Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,31 @@
|
|
| 1 |
-
from flask import Flask, request,
|
| 2 |
-
from
|
|
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
|
|
|
| 5 |
|
| 6 |
-
@app.route('/
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
text = data.get("text", "")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return send_file(output_path, mimetype="audio/mpeg")
|
| 17 |
-
else:
|
| 18 |
-
return {"error": "Failed to generate audio"}, 500
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
+
from text2generation import generate_long_answer
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
+
CORS(app)
|
| 7 |
|
| 8 |
+
@app.route('/health')
|
| 9 |
+
def health_check():
|
| 10 |
+
return jsonify({"status": "ready"}), 200
|
|
|
|
| 11 |
|
| 12 |
+
@app.route('/ask', methods=['POST'])
|
| 13 |
+
def ask_question():
|
| 14 |
+
try:
|
| 15 |
+
data = request.get_json()
|
| 16 |
+
question = data.get('question', '').strip()
|
| 17 |
+
|
| 18 |
+
if not question:
|
| 19 |
+
return jsonify({"error": "Question is required"}), 400
|
| 20 |
+
|
| 21 |
+
answer = generate_long_answer(question)
|
| 22 |
+
return jsonify({
|
| 23 |
+
"question": question,
|
| 24 |
+
"answer": answer
|
| 25 |
+
})
|
| 26 |
+
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return jsonify({"error": str(e)}), 500
|
| 29 |
|
| 30 |
+
if __name__ == '__main__':
|
| 31 |
+
app.run(host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|
|