Commit
·
6eb737d
1
Parent(s):
6763be4
Updated the Gradio UI
Browse files- .DS_Store +0 -0
- app.py +69 -26
- src/.DS_Store +0 -0
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
app.py
CHANGED
@@ -9,47 +9,90 @@ from src.tools_loader import get_tools
|
|
9 |
_ = get_tools()
|
10 |
|
11 |
# ------------------------------------------------------------------
|
12 |
-
# 2. Helper: streaming generator
|
13 |
# ------------------------------------------------------------------
|
14 |
def process_upload(image_path: str):
|
15 |
"""
|
16 |
-
Streamed generator: yields
|
17 |
-
|
18 |
-
Gradio automatically shows a spinner / progress bar
|
19 |
-
while the function is running.
|
20 |
"""
|
21 |
if image_path is None:
|
22 |
-
yield "Please upload a chest
|
23 |
return
|
24 |
|
25 |
start = time.time()
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
#
|
31 |
-
# report = generate_report(image_path, progress=progress)
|
32 |
-
|
33 |
report = generate_report(image_path)
|
34 |
-
|
35 |
elapsed = time.time() - start
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
# 3. Gradio UI
|
40 |
-
# ------------------------------------------------------------------
|
41 |
-
with gr.Blocks() as demo:
|
42 |
-
gr.Markdown("# Multi-Agent Radiology Assistant")
|
43 |
-
with gr.Row():
|
44 |
-
input_image = gr.Image(type="filepath", label="Upload Chest X-ray", height=400)
|
45 |
-
output_report = gr.Markdown()
|
46 |
|
47 |
-
|
|
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
generate_btn.click(
|
50 |
-
fn=process_upload,
|
51 |
inputs=input_image,
|
52 |
-
outputs=output_report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
|
|
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 " **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 might take a couple of seconds..."
|
27 |
+
|
28 |
+
# Generate the actual report
|
|
|
|
|
29 |
report = generate_report(image_path)
|
30 |
+
|
31 |
elapsed = time.time() - start
|
32 |
+
|
33 |
+
# Return final formatted report
|
34 |
+
yield f"""### Radiology Report
|
35 |
|
36 |
+
{report}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
---
|
39 |
+
*Generated in {elapsed:.1f} seconds*"""
|
40 |
|
41 |
+
# ------------------------------------------------------------------
|
42 |
+
# 3. Gradio UI - Vertical Layout
|
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: 20px; }
|
50 |
+
.generate-btn { margin: 20px auto; display: block; }
|
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 a professional radiology report"
|
58 |
+
)
|
59 |
+
|
60 |
+
# Image upload section (centered, top)
|
61 |
+
with gr.Column():
|
62 |
+
input_image = gr.Image(
|
63 |
+
type="filepath",
|
64 |
+
label="Upload Chest X-ray Image",
|
65 |
+
height=400,
|
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"]):
|
79 |
+
output_report = gr.Markdown(
|
80 |
+
value="**Ready to analyze**\n\nUpload an X-ray image above and click 'Generate Report' to begin.",
|
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 |
+
"Download and use any frontal chest X-ray PNG/JPG file and click **Generate Report**."
|
96 |
)
|
97 |
|
98 |
if __name__ == "__main__":
|
src/.DS_Store
CHANGED
Binary files a/src/.DS_Store and b/src/.DS_Store differ
|
|