File size: 3,627 Bytes
f91e0d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/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)