Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script for Provider Summary UI functionality. | |
| """ | |
| import gradio as gr | |
| import html as html_module | |
| from src.core.provider_summary_generator import ProviderSummary, ProviderSummaryGenerator | |
| from datetime import datetime | |
| def create_test_summary(): | |
| """Create a test provider summary.""" | |
| return ProviderSummary( | |
| patient_name="Test Patient", | |
| patient_phone="555-123-4567", | |
| situation_description="Patient expressing suicidal ideation", | |
| indicators=["suicidal_thoughts", "hopelessness"], | |
| classification="RED", | |
| confidence=0.95, | |
| reasoning="Patient explicitly mentioned wanting to end their life", | |
| triage_context=[], | |
| conversation_context="user: I want to end my life\nassistant: I hear you...", | |
| generated_at=datetime.now().isoformat() | |
| ) | |
| def test_interface(): | |
| """Create test interface for Provider Summary.""" | |
| with gr.Blocks(title="Provider Summary Test") as demo: | |
| gr.Markdown("# Provider Summary Test") | |
| # State to store summary | |
| summary_state = gr.State(value="") | |
| with gr.Row(): | |
| with gr.Column(scale=2): | |
| gr.Markdown("## Chat Simulation") | |
| test_btn = gr.Button("๐ด Simulate RED Flag", variant="primary") | |
| clear_btn = gr.Button("๐๏ธ Clear") | |
| result_text = gr.Textbox(label="Debug", lines=3) | |
| with gr.Column(scale=1, visible=False) as provider_panel: | |
| gr.Markdown("### ๐ Provider Summary") | |
| gr.Markdown("*For Spiritual Care Team*") | |
| # Using simple Textbox - most reliable | |
| summary_box = gr.Textbox( | |
| label="", | |
| value="Waiting...", | |
| lines=25, | |
| max_lines=30, | |
| interactive=False | |
| ) | |
| download_btn = gr.DownloadButton("๐ฅ Download", size="sm") | |
| # Event handlers | |
| def simulate_red_flag(): | |
| """Simulate RED flag detection.""" | |
| summary = create_test_summary() | |
| generator = ProviderSummaryGenerator() | |
| formatted_text = generator.format_for_display(summary) | |
| print(f"Generated summary length: {len(formatted_text)}") | |
| print(f"First 100 chars: {formatted_text[:100]}") | |
| debug_msg = f"Length: {len(formatted_text)}" | |
| return ( | |
| gr.update(visible=True), # show panel | |
| formatted_text, # update textbox | |
| debug_msg, # debug info | |
| formatted_text # store in state | |
| ) | |
| def clear_summary(): | |
| """Clear summary.""" | |
| return ( | |
| gr.update(visible=False), # hide panel | |
| "Cleared", # clear textbox | |
| "Cleared", # debug | |
| "" # clear state | |
| ) | |
| test_btn.click( | |
| simulate_red_flag, | |
| inputs=[], | |
| outputs=[provider_panel, summary_box, result_text, summary_state] | |
| ) | |
| clear_btn.click( | |
| clear_summary, | |
| inputs=[], | |
| outputs=[provider_panel, summary_box, result_text, summary_state] | |
| ) | |
| return demo | |
| if __name__ == "__main__": | |
| demo = test_interface() | |
| demo.launch(server_name="0.0.0.0", server_port=7862, share=False) |