Commit
·
996bb04
1
Parent(s):
6eb737d
Changed UI
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ 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()
|
@@ -17,13 +17,13 @@ def process_upload(image_path: str):
|
|
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 "
|
27 |
|
28 |
# Generate the actual report
|
29 |
report = generate_report(image_path)
|
@@ -36,7 +36,7 @@ def process_upload(image_path: str):
|
|
36 |
{report}
|
37 |
|
38 |
---
|
39 |
-
*
|
40 |
|
41 |
# ------------------------------------------------------------------
|
42 |
# 3. Gradio UI - Vertical Layout
|
@@ -46,15 +46,17 @@ with gr.Blocks(
|
|
46 |
title="Multi-Agent Radiology Assistant",
|
47 |
css="""
|
48 |
.image-container { max-width: 600px; margin: 0 auto; }
|
49 |
-
.report-container { margin-top: 20px; }
|
50 |
-
.generate-btn { margin:
|
|
|
|
|
51 |
"""
|
52 |
) as demo:
|
53 |
|
54 |
# Header
|
55 |
gr.Markdown(
|
56 |
"# Multi-Agent Radiology Assistant\n"
|
57 |
-
"Upload a chest X-ray image to receive
|
58 |
)
|
59 |
|
60 |
# Image upload section (centered, top)
|
@@ -66,13 +68,16 @@ with gr.Blocks(
|
|
66 |
elem_classes=["image-container"]
|
67 |
)
|
68 |
|
69 |
-
# Generate button (centered)
|
70 |
generate_btn = gr.Button(
|
71 |
"Generate Report",
|
72 |
variant="primary",
|
73 |
size="lg",
|
74 |
elem_classes=["generate-btn"]
|
75 |
)
|
|
|
|
|
|
|
76 |
|
77 |
# Report output section (bottom)
|
78 |
with gr.Column(elem_classes=["report-container"]):
|
@@ -81,18 +86,19 @@ with gr.Blocks(
|
|
81 |
label="Analysis Results"
|
82 |
)
|
83 |
|
84 |
-
# Event handler
|
85 |
generate_btn.click(
|
86 |
fn=process_upload,
|
87 |
inputs=input_image,
|
88 |
outputs=output_report,
|
89 |
-
show_progress="full" # Shows Gradio's built-in progress bar
|
|
|
90 |
)
|
91 |
|
92 |
# Footer with example hint
|
93 |
gr.Markdown(
|
94 |
"### Need an example?\n"
|
95 |
-
"
|
96 |
)
|
97 |
|
98 |
if __name__ == "__main__":
|
|
|
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()
|
|
|
17 |
Gradio shows spinner automatically during execution.
|
18 |
"""
|
19 |
if image_path is None:
|
20 |
+
yield "**Please upload a chest X-ray image to begin analysis.**"
|
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)
|
|
|
36 |
{report}
|
37 |
|
38 |
---
|
39 |
+
*Report generated in {elapsed:.1f} seconds*"""
|
40 |
|
41 |
# ------------------------------------------------------------------
|
42 |
# 3. Gradio UI - Vertical Layout
|
|
|
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-powered radiology report"
|
60 |
)
|
61 |
|
62 |
# Image upload section (centered, top)
|
|
|
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: 20px;'></div>")
|
81 |
|
82 |
# Report output section (bottom)
|
83 |
with gr.Column(elem_classes=["report-container"]):
|
|
|
86 |
label="Analysis Results"
|
87 |
)
|
88 |
|
89 |
+
# Event handler with progress settings
|
90 |
generate_btn.click(
|
91 |
fn=process_upload,
|
92 |
inputs=input_image,
|
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 |
+
"Use any frontal chest X-ray PNG/JPG file and click **Generate Report**."
|
102 |
)
|
103 |
|
104 |
if __name__ == "__main__":
|