Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
6 |
"""
|
7 |
-
Chat with the bot using the provided
|
8 |
"""
|
9 |
-
query = history[-1][0] # Get the latest user input
|
10 |
try:
|
11 |
-
response = generate_answer(query) #
|
12 |
except Exception as e:
|
13 |
print(f"Error in generate_answer: {str(e)}") # More specific error handling
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
history.append((query, response))
|
18 |
-
return history
|
19 |
|
20 |
def main():
|
21 |
"""
|
22 |
-
Main function to create and launch the Gradio
|
23 |
"""
|
24 |
try:
|
25 |
interface = gr.Interface(
|
26 |
fn=chat_with_bot,
|
27 |
-
inputs="
|
28 |
-
outputs="
|
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()
|