File size: 3,024 Bytes
51ed9c7
f9d5d64
51ed9c7
 
 
f9d5d64
51ed9c7
 
 
 
 
 
 
 
f9d5d64
51ed9c7
 
f9d5d64
51ed9c7
 
 
 
 
c88a03a
51ed9c7
 
 
 
 
 
 
 
c88a03a
51ed9c7
 
 
f9d5d64
c88a03a
51ed9c7
 
 
 
 
 
 
 
f9d5d64
51ed9c7
 
 
 
f9d5d64
51ed9c7
 
 
 
fc05593
51ed9c7
 
 
 
 
f9d5d64
1fbbb20
51ed9c7
bc98225
51ed9c7
 
bc98225
 
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
import gradio as gr
import os
from loader import loader
from tutor import run_council_deliberation
from inference import generate_universal_heatmap

# NerdMedica Dark Tech CSS
CSS = """
body, .gradio-container { background-color: #0A0E1A !important; color: #D1D5DB !important; }
.gr-button-primary { background: linear-gradient(90deg, #E5534B, #A855F7) !important; border: none !important; border-radius: 8px !important; color: white !important; font-weight: bold !important; }
#header { border-bottom: 2px solid #E5534B; padding-bottom: 15px; margin-bottom: 25px; }
.message.user { background-color: #1F2937 !important; border-left: 4px solid #E5534B !important; }
.message.bot { background-color: #111827 !important; border-left: 4px solid #3B82F6 !important; }
"""

def medical_audit_pipeline(image, modality, question, history):
    loader.clear_vram()
    
    # 1. Visual Evidence (If image exists)
    heatmap = None
    if image is not None:
        clip_model, preprocess = loader.load_biomed_clip()
        heatmap = generate_universal_heatmap(image, question, clip_model, preprocess)
    
    # 2. Council Deliberation
    response = run_council_deliberation(image, modality, question)
    
    # Append to Chat History
    history.append({"role": "user", "content": question})
    history.append({"role": "assistant", "content": response})
    
    return history, heatmap, response

# Gradio 6.0: We build the blocks without passing theme/css here
with gr.Blocks() as demo:
    gr.HTML("<div id='header'><h1 style='color:white; font-family:Consolas;'>🧬 MediVance LLC | NerdMedica Council</h1></div>")
    
    with gr.Row():
        with gr.Column(scale=1):
            img_in = gr.Image(type="pil", label="Medical Scan (Optional)")
            modality_drop = gr.Dropdown(
                ["General Inquiry", "Chest X-Ray", "CT Scan", "MRI", "Pathology"], 
                value="General Inquiry", 
                label="Modality Focus"
            )
            heatmap_out = gr.Image(label="Visual Evidence Audit")
            
        with gr.Column(scale=2):
            chat = gr.Chatbot(label="Council Deliberation", type="messages", height=500)
            query = gr.Textbox(placeholder="Ask about 'Isolated Hypertension' or specific scan findings...", label="Doctor's Inquiry")
            btn = gr.Button("Consult the Council", variant="primary")

    with gr.Accordion("🩺 Official Clinical Audit Report", open=False):
        audit_box = gr.Textbox(label="Final Finding (Editable)", interactive=True, lines=4)
        status = gr.Radio(["Approved", "Corrected", "Flagged"], label="Clinical Signature")
        gr.Button("Archive to MediVance API", variant="secondary")

    # Wire up the button
    btn.click(
        fn=medical_audit_pipeline, 
        inputs=[img_in, modality_drop, query, chat], 
        outputs=[chat, heatmap_out, audit_box]
    )

# Gradio 6.0: Theme and CSS MUST be passed in the launch method
demo.launch(
    ssr_mode=False,
    theme=gr.themes.Base(),
    css=CSS
)