shamim237 commited on
Commit
93b947c
·
verified ·
1 Parent(s): 0176602

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -2,30 +2,27 @@ import os
2
  import gradio as gr
3
  from rag import generate_answer
4
 
5
- def chat_with_bot(history: list) -> list:
6
  """
7
- Chat with the bot using the provided history of the conversation.
8
  """
9
- query = history[-1][0] # Get the latest user input
10
  try:
11
- response = generate_answer(query) # Generate the bot's response
12
  except Exception as e:
13
  print(f"Error in generate_answer: {str(e)}") # More specific error handling
14
- response = "Sorry, I couldn't process your request. Please try again."
15
 
16
- # Append the bot's response to the chat history
17
- history.append((query, response))
18
- return history
19
 
20
  def main():
21
  """
22
- Main function to create and launch the Gradio chat interface.
23
  """
24
  try:
25
  interface = gr.Interface(
26
  fn=chat_with_bot,
27
- inputs="chatbot", # Input type is a chat interface
28
- outputs="chatbot", # Output type is also a chat interface
29
  title="RAG-LLM based Medical Chatbot",
30
  description="Ask your medical questions and get answers from the chatbot."
31
  )
@@ -35,4 +32,4 @@ def main():
35
  print(f"An error occurred while launching the interface: {str(e)}") # More context on errors
36
 
37
  if __name__ == "__main__":
38
- main()
 
2
  import gradio as gr
3
  from rag import generate_answer
4
 
5
+ def chat_with_bot(query: str) -> tuple:
6
  """
7
+ Chat with the bot using the provided query.
8
  """
 
9
  try:
10
+ response = generate_answer(query) # Ensure this function is working correctly
11
  except Exception as e:
12
  print(f"Error in generate_answer: {str(e)}") # More specific error handling
13
+ return "Error generating answer", None # Return a default response on error
14
 
15
+ return response
 
 
16
 
17
  def main():
18
  """
19
+ Main function to create and launch the Gradio interface.
20
  """
21
  try:
22
  interface = gr.Interface(
23
  fn=chat_with_bot,
24
+ inputs="text",
25
+ outputs="text",
26
  title="RAG-LLM based Medical Chatbot",
27
  description="Ask your medical questions and get answers from the chatbot."
28
  )
 
32
  print(f"An error occurred while launching the interface: {str(e)}") # More context on errors
33
 
34
  if __name__ == "__main__":
35
+ main()