Reshmarb commited on
Commit
1b4e41d
·
1 Parent(s): dfd847e
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -276,18 +276,18 @@ def customLLMBot(user_input, uploaded_image, chat_history):
276
  tts.save(audio_file)
277
  logger.info(f"Audio response saved as {audio_file}")
278
 
279
- # Return the chat history (all Q&A) and the audio file
280
- return [(entry[0], entry[1]) for entry in chat_history], audio_file
281
 
282
  except Exception as e:
283
  # Handle errors gracefully
284
  logger.error(f"Error in customLLMBot function: {e}")
285
- return [("User", f"An error occurred: {e}")], None
286
 
287
 
288
  # Gradio Interface
289
  def chatbot_ui():
290
- chat_history = [] # Initialize empty chat history for the session
291
 
292
  with gr.Blocks() as demo:
293
  gr.Markdown("# Healthcare Chatbot Doctor")
@@ -328,16 +328,17 @@ def chatbot_ui():
328
  outputs=[chatbot, audio_output, user_input],
329
  )
330
 
331
- # Action for clearing all fields and resetting chat history
332
- def clear_chat():
333
- nonlocal chat_history
334
- chat_history = [] # Reset chat history for new session
335
- return [], "", None, None
336
-
337
- clear_btn.click(clear_chat, inputs=[], outputs=[chatbot, user_input, uploaded_image, audio_output])
338
 
339
  return demo
340
 
341
 
342
  # Launch the interface
343
- chatbot_ui().launch(share=True,server_name="0.0.0.0", server_port=7860)
 
 
 
276
  tts.save(audio_file)
277
  logger.info(f"Audio response saved as {audio_file}")
278
 
279
+ # Return chat history as a list of tuples (sender, message)
280
+ return [(entry[1], entry[0]) for entry in chat_history], audio_file
281
 
282
  except Exception as e:
283
  # Handle errors gracefully
284
  logger.error(f"Error in customLLMBot function: {e}")
285
+ return [(user_input or "Image uploaded", f"An error occurred: {e}")], None
286
 
287
 
288
  # Gradio Interface
289
  def chatbot_ui():
290
+ chat_history = [] # Initialize empty chat history
291
 
292
  with gr.Blocks() as demo:
293
  gr.Markdown("# Healthcare Chatbot Doctor")
 
328
  outputs=[chatbot, audio_output, user_input],
329
  )
330
 
331
+ # Action for clearing all fields
332
+ clear_btn.click(
333
+ lambda: ([], "", None, None),
334
+ inputs=[],
335
+ outputs=[chatbot, user_input, uploaded_image, audio_output],
336
+ )
 
337
 
338
  return demo
339
 
340
 
341
  # Launch the interface
342
+ chatbot_ui().launch(server_name="0.0.0.0", server_port=7860)
343
+
344
+ #chatbot_ui().launch(server_name="localhost", server_port=7860)