sreepathi-ravikumar commited on
Commit
ea19a60
·
verified ·
1 Parent(s): 44d57e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -1,31 +1,18 @@
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)
 
 
 
 
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