Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from collections import defaultdict
|
| 4 |
|
| 5 |
# Load the symptom-to-disease mapping
|
|
@@ -59,7 +60,7 @@ symptom_data = {
|
|
| 59 |
# Global variables to track user state
|
| 60 |
user_state = {}
|
| 61 |
|
| 62 |
-
def chatbot(user_input
|
| 63 |
if "state" not in user_state:
|
| 64 |
user_state["state"] = "greet"
|
| 65 |
|
|
@@ -108,18 +109,25 @@ def chatbot(user_input, history):
|
|
| 108 |
user_state.clear()
|
| 109 |
return f"Based on your symptoms, the most likely condition is: {probable_disease}. Please consult a doctor for confirmation."
|
| 110 |
|
| 111 |
-
# Gradio Chatbot UI
|
| 112 |
with gr.Blocks() as demo:
|
| 113 |
gr.Markdown("# Symptom Chatbot")
|
| 114 |
chatbot_ui = gr.Chatbot()
|
| 115 |
-
user_input = gr.Textbox(placeholder="Enter your response...")
|
| 116 |
submit = gr.Button("Send")
|
|
|
|
| 117 |
|
| 118 |
def respond(user_message, history):
|
| 119 |
-
|
| 120 |
-
history
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
submit.click(respond, [user_input, chatbot_ui], [chatbot_ui, user_input])
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import time
|
| 4 |
from collections import defaultdict
|
| 5 |
|
| 6 |
# Load the symptom-to-disease mapping
|
|
|
|
| 60 |
# Global variables to track user state
|
| 61 |
user_state = {}
|
| 62 |
|
| 63 |
+
def chatbot(user_input):
|
| 64 |
if "state" not in user_state:
|
| 65 |
user_state["state"] = "greet"
|
| 66 |
|
|
|
|
| 109 |
user_state.clear()
|
| 110 |
return f"Based on your symptoms, the most likely condition is: {probable_disease}. Please consult a doctor for confirmation."
|
| 111 |
|
| 112 |
+
# Gradio Chatbot UI with improved features
|
| 113 |
with gr.Blocks() as demo:
|
| 114 |
gr.Markdown("# Symptom Chatbot")
|
| 115 |
chatbot_ui = gr.Chatbot()
|
| 116 |
+
user_input = gr.Textbox(placeholder="Enter your response...", label="Your Message")
|
| 117 |
submit = gr.Button("Send")
|
| 118 |
+
clear_chat = gr.Button("Clear Chat")
|
| 119 |
|
| 120 |
def respond(user_message, history):
|
| 121 |
+
history.append((user_message, "Thinking...")) # Show thinking message
|
| 122 |
+
yield history, "" # Immediate update
|
| 123 |
+
|
| 124 |
+
time.sleep(1.5) # Simulate processing delay
|
| 125 |
+
bot_response = chatbot(user_message)
|
| 126 |
+
history[-1] = (user_message, bot_response) # Update with real response
|
| 127 |
+
yield history, ""
|
| 128 |
|
| 129 |
submit.click(respond, [user_input, chatbot_ui], [chatbot_ui, user_input])
|
| 130 |
+
user_input.submit(respond, [user_input, chatbot_ui], [chatbot_ui, user_input])
|
| 131 |
+
clear_chat.click(lambda: ([], ""), outputs=[chatbot_ui, user_input])
|
| 132 |
|
| 133 |
+
demo.launch()
|