Commit
·
24a53f5
1
Parent(s):
8b05966
Changed UI
Browse files
app.py
CHANGED
@@ -2,105 +2,39 @@ import gradio as gr
|
|
2 |
import time
|
3 |
from src.pipeline import generate_report
|
4 |
|
5 |
-
#
|
6 |
-
# 1. Pre-load models
|
7 |
-
# ------------------------------------------------------------------
|
8 |
from src.tools_loader import get_tools
|
9 |
_ = get_tools()
|
10 |
|
11 |
-
# ------------------------------------------------------------------
|
12 |
-
# 2. Helper: streaming generator with progress
|
13 |
-
# ------------------------------------------------------------------
|
14 |
def process_upload(image_path: str):
|
15 |
-
"""
|
16 |
-
Streamed generator: yields loading states then final report.
|
17 |
-
Gradio shows spinner automatically during execution.
|
18 |
-
"""
|
19 |
if image_path is None:
|
20 |
-
yield "
|
21 |
return
|
22 |
|
23 |
start = time.time()
|
|
|
24 |
|
25 |
-
# Show loading state immediately
|
26 |
-
yield "**Analyzing X-ray image...**\n\nThis will take a few seconds..."
|
27 |
-
|
28 |
-
# Generate the actual report
|
29 |
report = generate_report(image_path)
|
30 |
-
|
31 |
elapsed = time.time() - start
|
32 |
|
33 |
-
|
34 |
-
yield f"""### Radiology Report
|
35 |
-
|
36 |
-
{report}
|
37 |
-
|
38 |
-
---
|
39 |
-
*Report generated in {elapsed:.1f} seconds*"""
|
40 |
|
41 |
-
|
42 |
-
#
|
43 |
-
# ------------------------------------------------------------------
|
44 |
-
with gr.Blocks(
|
45 |
-
theme=gr.themes.Soft(),
|
46 |
-
title="Multi-Agent Radiology Assistant",
|
47 |
-
css="""
|
48 |
-
.image-container { max-width: 600px; margin: 0 auto; }
|
49 |
-
.report-container { margin-top: 40px; padding-top: 20px; }
|
50 |
-
.generate-btn { margin: 30px auto; display: block; }
|
51 |
-
.progress-bar { z-index: 1000 !important; position: relative; }
|
52 |
-
.gradio-container .wrap { z-index: auto; }
|
53 |
-
"""
|
54 |
-
) as demo:
|
55 |
-
|
56 |
-
# Header
|
57 |
-
gr.Markdown(
|
58 |
-
"# Multi-Agent Radiology Assistant\n"
|
59 |
-
"Upload a chest X-ray image to receive an AI-generated radiology report"
|
60 |
-
)
|
61 |
-
|
62 |
-
# Image upload section (centered, top)
|
63 |
-
with gr.Column():
|
64 |
-
input_image = gr.Image(
|
65 |
-
type="filepath",
|
66 |
-
label="Upload Chest X-ray Image",
|
67 |
-
height=400,
|
68 |
-
elem_classes=["image-container"]
|
69 |
-
)
|
70 |
-
|
71 |
-
# Generate button (centered with more spacing)
|
72 |
-
generate_btn = gr.Button(
|
73 |
-
"Generate Report",
|
74 |
-
variant="primary",
|
75 |
-
size="lg",
|
76 |
-
elem_classes=["generate-btn"]
|
77 |
-
)
|
78 |
-
|
79 |
-
# Add some spacing to prevent overlap
|
80 |
-
gr.HTML("<div style='height: 22px;'></div>")
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
value="**Ready to analyze**\n\nUpload an X-ray image above and click 'Generate Report' to begin.",
|
86 |
-
label="Analysis Results"
|
87 |
-
)
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
outputs=output_report,
|
94 |
-
show_progress="full", # Shows Gradio's built-in progress bar
|
95 |
-
concurrency_limit=1 # Prevent multiple simultaneous requests
|
96 |
-
)
|
97 |
-
|
98 |
-
# Footer with example hint
|
99 |
-
gr.Markdown(
|
100 |
-
"### Need an example?\n"
|
101 |
"Download and use any frontal chest X-ray PNG/JPG file from the internet and click **Generate Report**.\n"
|
102 |
"### 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."
|
103 |
)
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
-
demo.launch()
|
|
|
|
|
|
2 |
import time
|
3 |
from src.pipeline import generate_report
|
4 |
|
5 |
+
# Pre-load models
|
|
|
|
|
6 |
from src.tools_loader import get_tools
|
7 |
_ = get_tools()
|
8 |
|
|
|
|
|
|
|
9 |
def process_upload(image_path: str):
|
|
|
|
|
|
|
|
|
10 |
if image_path is None:
|
11 |
+
yield "Please upload a chest X-ray image."
|
12 |
return
|
13 |
|
14 |
start = time.time()
|
15 |
+
yield "Analyzing image..."
|
16 |
|
|
|
|
|
|
|
|
|
17 |
report = generate_report(image_path)
|
|
|
18 |
elapsed = time.time() - start
|
19 |
|
20 |
+
yield f"### Radiology Report\n{report}\n\n*Generated in {elapsed:.1f}s*"
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="Radiology Assistant") as demo:
|
23 |
+
gr.Markdown("#Multi-Agent Radiology Assistant")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
image_input = gr.Image(type="filepath", label="Upload Chest X-ray")
|
26 |
+
generate_btn = gr.Button("Generate Report", variant="primary")
|
27 |
+
report_output = gr.Markdown("Upload an image and click Generate Report.")
|
|
|
|
|
|
|
28 |
|
29 |
+
generate_btn.click(process_upload, image_input, report_output)
|
30 |
+
|
31 |
+
|
32 |
+
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
"Download and use any frontal chest X-ray PNG/JPG file from the internet and click **Generate Report**.\n"
|
34 |
"### 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."
|
35 |
)
|
36 |
|
37 |
if __name__ == "__main__":
|
38 |
+
demo.launch()
|
39 |
+
|
40 |
+
|