Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
10 |
-
query
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
response
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
"""
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
interface
|
33 |
-
|
34 |
-
|
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()
|