Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,28 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
-
from
|
| 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
|
| 12 |
-
return jsonify({"status": "
|
| 13 |
|
| 14 |
-
@app.route('/generate', methods=['POST'])
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 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 |
-
|
| 29 |
-
|
| 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__ ==
|
| 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)
|