Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,20 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
from
|
3 |
import os
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
-
|
8 |
-
client = None # global cache
|
9 |
|
10 |
@app.route("/ask", methods=["POST"])
|
11 |
def ask_question():
|
12 |
-
global client
|
13 |
try:
|
14 |
-
if client is None:
|
15 |
-
client = Client("memorease/flan5_memorease", hf_token=HF_TOKEN) # lazy init
|
16 |
-
|
17 |
input_text = request.json.get("text")
|
18 |
-
|
19 |
-
return jsonify({"error": "Missing 'text'"}), 400
|
20 |
-
|
21 |
-
result = client.predict(input_text, api_name="/predict")
|
22 |
return jsonify({"question": result})
|
23 |
-
|
24 |
except Exception as e:
|
25 |
return jsonify({"error": str(e)}), 500
|
26 |
|
27 |
-
|
28 |
@app.route("/", methods=["GET"])
|
29 |
def root_check():
|
30 |
return jsonify({"status": "running"})
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
import os
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
+
pipe = pipeline("text2text-generation", model="memorease/flan5_memorease", token=os.environ.get("HF_TOKEN"))
|
|
|
8 |
|
9 |
@app.route("/ask", methods=["POST"])
|
10 |
def ask_question():
|
|
|
11 |
try:
|
|
|
|
|
|
|
12 |
input_text = request.json.get("text")
|
13 |
+
result = pipe(f"Generate a question about: {input_text}")[0]["generated_text"]
|
|
|
|
|
|
|
14 |
return jsonify({"question": result})
|
|
|
15 |
except Exception as e:
|
16 |
return jsonify({"error": str(e)}), 500
|
17 |
|
|
|
18 |
@app.route("/", methods=["GET"])
|
19 |
def root_check():
|
20 |
return jsonify({"status": "running"})
|