Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from chatbot_functions import DataProcessor, Chatbot
|
| 3 |
+
|
| 4 |
+
# Initialize data and chatbot
|
| 5 |
+
data_processor = DataProcessor() # loads cleaned_medquad.csv
|
| 6 |
+
chatbot = Chatbot(data_processor)
|
| 7 |
+
|
| 8 |
+
def chat_with_backend(message, history=None):
|
| 9 |
+
if not message.strip():
|
| 10 |
+
return "Please enter a question."
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
best_question, response, source = chatbot.get_response(message)
|
| 14 |
+
if best_question == "UNKNOWN":
|
| 15 |
+
return response
|
| 16 |
+
else:
|
| 17 |
+
return f"Matched question: {best_question}\nAnswer: {response}\nSource: {source}"
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Error: {str(e)}"
|
| 20 |
+
|
| 21 |
+
# Gradio interface
|
| 22 |
+
iface = gr.ChatInterface(
|
| 23 |
+
fn=chat_with_backend,
|
| 24 |
+
title="Care Companion Chatbot",
|
| 25 |
+
description="Ask health-related questions and get reliable answers from Care Companion."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=True, debug=True)
|