Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,18 @@
|
|
| 1 |
-
from flask import Flask, request,
|
| 2 |
-
from
|
| 3 |
-
from text2generation import generate_long_answer
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
-
CORS(app)
|
| 7 |
|
| 8 |
-
@app.route('/
|
| 9 |
-
def
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 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 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, send_file
|
| 2 |
+
from audio_generator import generate_audio_from_text
|
|
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
|
|
|
| 5 |
|
| 6 |
+
@app.route('/audio', methods=['POST'])
|
| 7 |
+
def audio():
|
| 8 |
+
data = request.get_json()
|
| 9 |
+
text = data.get("text", "")
|
| 10 |
|
| 11 |
+
if not text:
|
| 12 |
+
return {"error": "Text is required"}, 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
output_path = generate_audio_from_text(text)
|
| 15 |
+
if output_path:
|
| 16 |
+
return send_file(output_path, mimetype="audio/mpeg")
|
| 17 |
+
else:
|
| 18 |
+
return {"error": "Failed to generate audio"}, 500
|