sreepathi-ravikumar commited on
Commit
0fb0cc3
·
verified ·
1 Parent(s): ebb3c5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -33
app.py CHANGED
@@ -1,46 +1,28 @@
1
- from flask import Flask, request, jsonify
2
  from flask_cors import CORS
3
- from text2generation import generate_educational_content
4
- from video_processor import create_video
5
  import os
6
 
7
  app = Flask(__name__)
8
  CORS(app)
9
 
10
- @app.route('/health')
11
- def health_check():
12
- return jsonify({"status": "ready"}), 200
13
 
14
- @app.route('/generate', methods=['POST'])
15
- def generate_content():
16
- try:
17
- data = request.get_json()
18
- question = data.get('question', '').strip()
19
-
20
- if not question:
21
- return jsonify({"error": "Question is required"}), 400
22
-
23
- # Generate video script, audio script, and summary
24
- content = generate_educational_content(question)
25
- if "error" in content:
26
- return jsonify(content), 500
27
 
28
- # Generate video using content
29
- video_url = create_video(
30
- content['video_script'],
31
- content['audio_script'],
32
- content['summary']
33
- )
34
-
35
- return jsonify({
36
- "summary": content['summary'],
37
- "video_url": video_url,
38
- "status": "success"
39
- })
40
 
 
 
 
41
  except Exception as e:
42
  return jsonify({"error": str(e)}), 500
43
 
44
- if __name__ == '__main__':
45
- # Run on port 7860 (or use os.getenv('PORT', 7860) for cloud deployment)
46
  app.run(host='0.0.0.0', port=7860)
 
1
+ from flask import Flask, request, jsonify, send_file
2
  from flask_cors import CORS
3
+ from audio_generator import generate_audio
 
4
  import os
5
 
6
  app = Flask(__name__)
7
  CORS(app)
8
 
9
+ @app.route('/health', methods=['GET'])
10
+ def health():
11
+ return jsonify({"status": "ok"}), 200
12
 
13
+ @app.route('/generate-audio', methods=['POST'])
14
+ def generate_audio_route():
15
+ data = request.get_json()
16
+ text = data.get("text", "").strip()
 
 
 
 
 
 
 
 
 
17
 
18
+ if not text:
19
+ return jsonify({"error": "Text is required"}), 400
 
 
 
 
 
 
 
 
 
 
20
 
21
+ try:
22
+ filename = generate_audio(text)
23
+ return send_file(filename, as_attachment=True)
24
  except Exception as e:
25
  return jsonify({"error": str(e)}), 500
26
 
27
+ if __name__ == "__main__":
 
28
  app.run(host='0.0.0.0', port=7860)