Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,26 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from gradio_client import Client
|
3 |
import os
|
4 |
-
from transformers import pipeline
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
8 |
-
question_generator = pipeline("text2text-generation", model="memorease/memorease-flan-t5")
|
9 |
-
|
10 |
@app.route("/ask", methods=["POST"])
|
11 |
def ask_question():
|
12 |
try:
|
|
|
13 |
input_text = request.json.get("text")
|
14 |
-
print("INPUT:", input_text)
|
15 |
-
|
16 |
if not input_text:
|
17 |
return jsonify({"error": "Missing 'text'"}), 400
|
18 |
-
|
19 |
-
|
20 |
-
print("RESULT:", result)
|
21 |
-
return jsonify({"question": result[0]["generated_text"]})
|
22 |
except Exception as e:
|
23 |
-
print("SERVER ERROR:", str(e))
|
24 |
return jsonify({"error": str(e)}), 500
|
25 |
|
26 |
@app.route("/", methods=["GET"])
|
27 |
-
def
|
28 |
-
return "
|
|
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
port = int(os.environ.get("PORT", 7860))
|
32 |
-
app.run(host="0.0.0.0", port=port)
|
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
from gradio_client import Client
|
3 |
import os
|
|
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
|
|
|
|
7 |
@app.route("/ask", methods=["POST"])
|
8 |
def ask_question():
|
9 |
try:
|
10 |
+
client = Client("memorease/memorease-flan-t5")
|
11 |
input_text = request.json.get("text")
|
|
|
|
|
12 |
if not input_text:
|
13 |
return jsonify({"error": "Missing 'text'"}), 400
|
14 |
+
result = client.predict(input_text, api_name="/predict")
|
15 |
+
return jsonify({"question": result})
|
|
|
|
|
16 |
except Exception as e:
|
|
|
17 |
return jsonify({"error": str(e)}), 500
|
18 |
|
19 |
@app.route("/", methods=["GET"])
|
20 |
+
def root_check():
|
21 |
+
return jsonify({"status": "running"})
|
22 |
+
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
port = int(os.environ.get("PORT", 7860))
|
26 |
+
app.run(host="0.0.0.0", port=port)
|