shamim237 commited on
Commit
22ab087
·
verified ·
1 Parent(s): 99e00bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -37
app.py CHANGED
@@ -1,38 +1,35 @@
1
- import os
2
- import gradio as gr
3
- from rag import generate_answer # Import the generate_answer function from rag.py
4
-
5
- def chat_with_bot(query: str) -> tuple:
6
- """
7
- Chat with the bot using the provided query.
8
-
9
- Args:
10
- query: User's question
11
-
12
- Returns:
13
- tuple: Generated answer and extracted contents
14
- """
15
- response = generate_answer(query) # Call the existing generate_answer function
16
-
17
- return response
18
-
19
- def main():
20
- """
21
- Main function to create and launch the Gradio interface.
22
- """
23
- try:
24
- # Create Gradio interface
25
- interface = gr.Interface(
26
- fn=chat_with_bot, # Use the chat function
27
- inputs="text", # Input type
28
- outputs="text", # Output type
29
- title="RAG-LLM based Medical Chatbot", # Title of the app
30
- description="Ask your medical questions and get answers from the chatbot." # Description
31
- )
32
- interface.launch(share=True) # Launch the Gradio app
33
-
34
- except Exception as e:
35
- print(f"An error occurred: {str(e)}")
36
-
37
- if __name__ == "__main__":
38
  main()
 
1
+ import os
2
+ import gradio as gr
3
+ from rag import generate_answer # Import the generate_answer function from rag.py
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
+ )
29
+ interface.launch(share=True)
30
+
31
+ except Exception as e:
32
+ print(f"An error occurred while launching the interface: {str(e)}") # More context on errors
33
+
34
+ if __name__ == "__main__":
 
 
 
35
  main()