Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,126 Bytes
031a3f5 7c9f8aa 031a3f5 a22013f 031a3f5 f2907c6 031a3f5 7c9f8aa 031a3f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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 |