Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,25 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
from
|
3 |
import os
|
4 |
|
5 |
-
app = Flask(
|
6 |
-
|
7 |
-
# Modeli başta yükle (sadece 1 kez)
|
8 |
-
question_generator = pipeline("text2text-generation", model="memorease/flan5_memorease")
|
9 |
|
10 |
@app.route("/ask", methods=["POST"])
|
11 |
def ask_question():
|
12 |
try:
|
|
|
13 |
input_text = request.json.get("text")
|
14 |
if not input_text:
|
15 |
return jsonify({"error": "Missing 'text'"}), 400
|
16 |
-
|
17 |
-
|
18 |
-
return jsonify({"question": result[0]['generated_text']})
|
19 |
except Exception as e:
|
20 |
-
print("SERVER ERROR:", str(e))
|
21 |
return jsonify({"error": str(e)}), 500
|
22 |
-
|
23 |
@app.route("/", methods=["GET"])
|
24 |
def index():
|
25 |
return "Flan5 Memorease Docker Space is running!", 200
|
26 |
|
27 |
-
if
|
28 |
port = int(os.environ.get("PORT", 7860))
|
29 |
-
app.run(host="0.0.0.0",
|
|
|
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 index():
|
21 |
return "Flan5 Memorease Docker Space is running!", 200
|
22 |
|
23 |
+
if _name_ == "_main_":
|
24 |
port = int(os.environ.get("PORT", 7860))
|
25 |
+
app.run(host="0.0.0.0", port=port)
|