Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from .handlers import respond, reset_chat | |
def user_message_handler(user_message, chat_history): | |
# Immediately show the user's message | |
chat_history = chat_history + [(user_message, None)] | |
return "", chat_history | |
def bot_response_handler(chat_history): | |
# Get the last user message | |
user_message = chat_history[-1][0] | |
# Get the bot's response | |
_, updated_history = respond(user_message, chat_history[:-1]) | |
# Replace the last (user, None) with (user, bot_response) | |
chat_history[-1] = updated_history[-1] | |
return chat_history | |
def build_interface(): | |
with gr.Blocks(theme="soft") as demo: | |
gr.Markdown("# π₯ BluePlanet Medical Assistant ") | |
gr.Markdown("By BluePlanet Solutions AI") | |
with gr.Row(): | |
with gr.Column(scale=4): | |
chatbot = gr.Chatbot(height=500) | |
msg = gr.Textbox( | |
placeholder="Tell me about your symptoms or health concerns...", | |
label="Your Message" | |
) | |
send_btn = gr.Button("Send", elem_id="send-btn") | |
with gr.Column(scale=1): | |
reset_btn = gr.Button("π Start New Consultation", variant="secondary") | |
gr.Markdown("**Memory Features:**\n- Tracks symptoms & timeline\n- Remembers medications & allergies\n- Maintains conversation context\n- Provides comprehensive summaries") | |
gr.Examples( | |
examples=[ | |
"I have a persistent cough and sore throat for 3 days", | |
"I've been having severe headaches and feel dizzy", | |
"My stomach hurts and I feel nauseous after eating" | |
], | |
inputs=msg | |
) | |
# Step 1: Show user message instantly | |
msg.submit(user_message_handler, [msg, chatbot], [msg, chatbot]).then( | |
bot_response_handler, chatbot, chatbot | |
) | |
send_btn.click(user_message_handler, [msg, chatbot], [msg, chatbot]).then( | |
bot_response_handler, chatbot, chatbot | |
) | |
reset_btn.click(reset_chat, [], [chatbot, msg]) | |
return demo |