ayush2917 commited on
Commit
584a614
·
verified ·
1 Parent(s): 69820a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -28
app.py CHANGED
@@ -272,14 +272,21 @@ def home():
272
  @app.route('/chat', methods=['GET', 'POST'])
273
  def chat():
274
  """Handle chat interactions with Little Krishna"""
275
- if request.method == 'POST':
276
- user_input = request.form['message']
277
- reply = get_krishna_response(user_input)
278
- if firebase_enabled:
279
- save_chat_message(user_input, reply)
280
- return jsonify({'reply': reply})
281
- chat_history = get_chat_history() if firebase_enabled else []
282
- return render_template('chat.html', chat_history=chat_history)
 
 
 
 
 
 
 
283
 
284
  @app.route('/message')
285
  def message():
@@ -418,25 +425,6 @@ def comic():
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"""
@@ -520,7 +508,6 @@ def story_audio():
520
  json=payload
521
  )
522
  if response and response.status_code == 200:
523
- # Save the audio file temporarily
524
  audio_path = "static/audio/story_audio.mp3"
525
  with open(audio_path, "wb") as f:
526
  f.write(response.content)
 
272
  @app.route('/chat', methods=['GET', 'POST'])
273
  def chat():
274
  """Handle chat interactions with Little Krishna"""
275
+ try:
276
+ if request.method == 'POST':
277
+ user_input = request.form['message']
278
+ reply = get_krishna_response(user_input)
279
+ if firebase_enabled:
280
+ try:
281
+ save_chat_message(user_input, reply)
282
+ except Exception as e:
283
+ logger.error(f"Failed to save chat message to Firebase: {str(e)}")
284
+ return jsonify({'reply': reply})
285
+ chat_history = get_chat_history() if firebase_enabled else []
286
+ return render_template('chat.html', chat_history=chat_history)
287
+ except Exception as e:
288
+ logger.error(f"Error in /chat route: {str(e)}")
289
+ return jsonify({'error': 'Internal Server Error: Please try again later.'}), 500
290
 
291
  @app.route('/message')
292
  def message():
 
425
  comic_images = generate_comic_strip()
426
  return jsonify({'comic_images': comic_images})
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
  @app.route('/story', methods=['POST'])
429
  def story():
430
  """Generate a text-based Krishna story based on a user-provided theme"""
 
508
  json=payload
509
  )
510
  if response and response.status_code == 200:
 
511
  audio_path = "static/audio/story_audio.mp3"
512
  with open(audio_path, "wb") as f:
513
  f.write(response.content)