Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,27 +5,26 @@ import os
|
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
8 |
-
client = None # global
|
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) #
|
16 |
-
|
17 |
input_text = request.json.get("text")
|
18 |
if not input_text:
|
19 |
return jsonify({"error": "Missing 'text'"}), 400
|
20 |
-
|
21 |
result = client.predict(input_text, api_name="/predict")
|
22 |
return jsonify({"question": result})
|
|
|
23 |
except Exception as e:
|
24 |
return jsonify({"error": str(e)}), 500
|
25 |
|
26 |
|
27 |
-
|
28 |
-
|
29 |
@app.route("/", methods=["GET"])
|
30 |
def root_check():
|
31 |
return jsonify({"status": "running"})
|
@@ -33,4 +32,4 @@ def root_check():
|
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
port = int(os.environ.get("PORT", 7860))
|
36 |
-
app.run(host="0.0.0.0", port=port)
|
|
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
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 |
if not input_text:
|
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"})
|
|
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
port = int(os.environ.get("PORT", 7860))
|
35 |
+
app.run(host="0.0.0.0", port=port)
|