|
import gradio as gr |
|
import time |
|
from src.pipeline import generate_report |
|
|
|
|
|
|
|
|
|
from src.tools_loader import get_tools |
|
_ = get_tools() |
|
|
|
|
|
|
|
|
|
def process_upload(image_path: str): |
|
""" |
|
Streamed generator: yields loading states then final report. |
|
Gradio shows spinner automatically during execution. |
|
""" |
|
if image_path is None: |
|
yield "**Please upload a chest X-ray image to begin analysis.**" |
|
return |
|
|
|
start = time.time() |
|
|
|
|
|
report = generate_report(image_path) |
|
|
|
elapsed = time.time() - start |
|
|
|
|
|
yield f"""### Radiology Report |
|
|
|
{report} |
|
|
|
--- |
|
*Generated in {elapsed:.1f} seconds*""" |
|
|
|
|
|
|
|
|
|
with gr.Blocks( |
|
theme=gr.themes.Soft(), |
|
title="Multi-Agent Radiology Assistant", |
|
css=""" |
|
.image-container { max-width: 600px; margin: 0 auto; } |
|
.report-container { margin-top: 40px; padding-top: 20px; } |
|
.generate-btn { margin: 30px auto; display: block; } |
|
.progress-bar { z-index: 1000 !important; position: relative; } |
|
.gradio-container .wrap { z-index: auto; } |
|
""" |
|
) as demo: |
|
|
|
|
|
gr.Markdown( |
|
"# Multi-Agent Radiology Assistant\n" |
|
"Upload a chest X-ray image to receive an AI-powered radiology report" |
|
) |
|
|
|
|
|
with gr.Column(): |
|
input_image = gr.Image( |
|
type="filepath", |
|
label="Upload Chest X-ray Image", |
|
height=400, |
|
elem_classes=["image-container"] |
|
) |
|
|
|
|
|
generate_btn = gr.Button( |
|
"Generate Report", |
|
variant="primary", |
|
size="lg", |
|
elem_classes=["generate-btn"] |
|
) |
|
|
|
|
|
with gr.Column(elem_classes=["report-container"]): |
|
output_report = gr.Markdown( |
|
value="**Ready to analyze**\n\nUpload an X-ray image above and click 'Generate Report' to begin.", |
|
label="Analysis Results" |
|
) |
|
|
|
|
|
generate_btn.click( |
|
fn=process_upload, |
|
inputs=input_image, |
|
outputs=output_report, |
|
show_progress="full", |
|
concurrency_limit=1 |
|
) |
|
|
|
|
|
gr.Markdown( |
|
"Download and use any frontal chest X-ray PNG/JPG file from the internet and click **Generate Report**.\n" |
|
"### NOTE: This is just a demo. It is not intended to diagnose or suggest treatment of any disease or condition, and should not be used for medical advice." |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |