Update app.py
Browse files
app.py
CHANGED
@@ -418,6 +418,25 @@ def comic():
|
|
418 |
comic_images = generate_comic_strip()
|
419 |
return jsonify({'comic_images': comic_images})
|
420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
@app.route('/story', methods=['POST'])
|
422 |
def story():
|
423 |
"""Generate a text-based Krishna story based on a user-provided theme"""
|
|
|
418 |
comic_images = generate_comic_strip()
|
419 |
return jsonify({'comic_images': comic_images})
|
420 |
|
421 |
+
@app.route('/chat', methods=['GET', 'POST'])
|
422 |
+
def chat():
|
423 |
+
"""Handle chat interactions with Little Krishna"""
|
424 |
+
try:
|
425 |
+
if request.method == 'POST':
|
426 |
+
user_input = request.form['message']
|
427 |
+
reply = get_krishna_response(user_input)
|
428 |
+
if firebase_enabled:
|
429 |
+
try:
|
430 |
+
save_chat_message(user_input, reply)
|
431 |
+
except Exception as e:
|
432 |
+
logger.error(f"Failed to save chat message to Firebase: {str(e)}")
|
433 |
+
return jsonify({'reply': reply})
|
434 |
+
chat_history = get_chat_history() if firebase_enabled else []
|
435 |
+
return render_template('chat.html', chat_history=chat_history)
|
436 |
+
except Exception as e:
|
437 |
+
logger.error(f"Error in /chat route: {str(e)}")
|
438 |
+
return jsonify({'error': 'Internal Server Error: Please try again later.'}), 500
|
439 |
+
|
440 |
@app.route('/story', methods=['POST'])
|
441 |
def story():
|
442 |
"""Generate a text-based Krishna story based on a user-provided theme"""
|