import gradio as gr import requests # 1. This function handles the chat logic def chat_and_collect(message, history): # The response the doctor avatar gives bot_message = f"I've noted that you said: '{message}'. To help further, could you tell me more about your symptoms?" # NEW FIX: Gradio now expects history to be updated like this history.append((message, bot_message)) # Returns empty string for the input box and the updated history for the chatbot return "", history # 2. Build the visual interface with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# 🏥 Patient Data Intake Assistant") with gr.Row(): # Displays your doctor image avatar_display = gr.Image("avatar.webp", label="Your Assistant", width=300) # The chatbot component chatbot = gr.Chatbot() # The text input for the patient msg = gr.Textbox(label="Your Response", placeholder="Type here...") # Clear button to reset clear = gr.Button("Restart Conversation") # This connects the text box to our function msg.submit(chat_and_collect, [msg, chatbot], [msg, chatbot]) # This resets the chat history clear.click(lambda: None, None, chatbot, queue=False) # 3. Launch the app demo.launch(server_name="0.0.0.0", server_port=7860)