Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from text2generation import generate_long_answer # Your own function
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
CORS(app)
|
| 8 |
-
|
| 9 |
@app.route('/health')
|
| 10 |
def health_check():
|
| 11 |
return jsonify({"status": "ready"}), 200
|
|
@@ -14,7 +14,6 @@ def health_check():
|
|
| 14 |
@app.route('/ask', methods=['POST'])
|
| 15 |
def ask_question():
|
| 16 |
try:
|
| 17 |
-
global global_answer
|
| 18 |
data = request.get_json()
|
| 19 |
question = data.get('question', '').strip()
|
| 20 |
|
|
@@ -22,7 +21,10 @@ def ask_question():
|
|
| 22 |
return jsonify({"error": "Question is required"}), 400
|
| 23 |
|
| 24 |
answer = generate_long_answer(question)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
return jsonify({"question": question, "answer": answer})
|
| 27 |
|
| 28 |
except Exception as e:
|
|
@@ -30,11 +32,20 @@ def ask_question():
|
|
| 30 |
|
| 31 |
@app.route('/get_video')
|
| 32 |
def get_video():
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
|
|
|
|
|
|
| 38 |
|
| 39 |
if __name__ == '__main__':
|
| 40 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
CORS(app)
|
| 8 |
+
|
| 9 |
@app.route('/health')
|
| 10 |
def health_check():
|
| 11 |
return jsonify({"status": "ready"}), 200
|
|
|
|
| 14 |
@app.route('/ask', methods=['POST'])
|
| 15 |
def ask_question():
|
| 16 |
try:
|
|
|
|
| 17 |
data = request.get_json()
|
| 18 |
question = data.get('question', '').strip()
|
| 19 |
|
|
|
|
| 21 |
return jsonify({"error": "Question is required"}), 400
|
| 22 |
|
| 23 |
answer = generate_long_answer(question)
|
| 24 |
+
|
| 25 |
+
# Save to file
|
| 26 |
+
with open("/tmp/answer.txt", "w", encoding='utf-8') as f:
|
| 27 |
+
f.write(answer)
|
| 28 |
return jsonify({"question": question, "answer": answer})
|
| 29 |
|
| 30 |
except Exception as e:
|
|
|
|
| 32 |
|
| 33 |
@app.route('/get_video')
|
| 34 |
def get_video():
|
| 35 |
+
try:
|
| 36 |
+
with open("/tmp/answer.txt", "r", encoding='utf-8') as f:
|
| 37 |
+
answer = f.read()
|
| 38 |
+
|
| 39 |
+
print("Using answer for video:", answer)
|
| 40 |
+
|
| 41 |
+
# You can now use answer to generate images/video here
|
| 42 |
+
# Example:
|
| 43 |
+
# generate_video(answer) or do any processing
|
| 44 |
+
|
| 45 |
+
return redirect("https://videos.pexels.com/video-files/2098989/2098989-uhd_2560_1440_30fps.mp4")
|
| 46 |
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
return jsonify({"error": "Answer not found. Please ask a question first."}), 404
|
| 49 |
|
| 50 |
if __name__ == '__main__':
|
| 51 |
app.run(host='0.0.0.0', port=7860)
|