Commit
·
6763be4
1
Parent(s):
5c7cdbe
Updated the UI
Browse files- app.py +34 -41
- src/.DS_Store +0 -0
app.py
CHANGED
@@ -1,63 +1,56 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from src.pipeline import generate_report
|
3 |
|
4 |
# ------------------------------------------------------------------
|
5 |
-
# 1. Pre-load models
|
6 |
# ------------------------------------------------------------------
|
7 |
-
|
8 |
-
|
9 |
-
from src.tools_loader import get_tools # downloads BiomedCLIP + SPECTER-2
|
10 |
-
_ = get_tools()
|
11 |
-
print("Models pre-loaded successfully!")
|
12 |
-
except Exception as e:
|
13 |
-
print(f"Model pre-loading failed: {e}")
|
14 |
|
15 |
# ------------------------------------------------------------------
|
16 |
-
# 2.
|
17 |
# ------------------------------------------------------------------
|
18 |
def process_upload(image_path: str):
|
19 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
20 |
if image_path is None:
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# ------------------------------------------------------------------
|
30 |
# 3. Gradio UI
|
31 |
# ------------------------------------------------------------------
|
32 |
-
with gr.Blocks(
|
33 |
-
gr.Markdown(
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
"""
|
38 |
-
)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
label="Upload Chest X-ray",
|
45 |
-
height=400
|
46 |
-
)
|
47 |
-
process_btn = gr.Button("Generate Report", variant="primary")
|
48 |
-
|
49 |
-
# --- Report output ---------------------------------------------------------
|
50 |
-
output_report = gr.Markdown(label="Radiology Report", show_label=True)
|
51 |
-
|
52 |
-
# --- Wire everything together ---------------------------------------------
|
53 |
-
process_btn.click(
|
54 |
-
fn=process_upload,
|
55 |
inputs=input_image,
|
56 |
outputs=output_report
|
57 |
)
|
58 |
|
59 |
-
gr.Markdown("### Need an example? \nUse any frontal CXR PNG file and click **Generate Report**.")
|
60 |
-
|
61 |
-
# ------------------------------------------------------------------
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import time
|
3 |
from src.pipeline import generate_report
|
4 |
|
5 |
# ------------------------------------------------------------------
|
6 |
+
# 1. Pre-load models (unchanged)
|
7 |
# ------------------------------------------------------------------
|
8 |
+
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 placeholder first,
|
17 |
+
then final report with inference time.
|
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-X-ray image."
|
23 |
+
return
|
24 |
|
25 |
+
start = time.time()
|
26 |
+
# Initial placeholder so the textarea updates immediately
|
27 |
+
yield " **Generating report...**\n\nThis may take a few seconds..."
|
28 |
+
|
29 |
+
# Optional manual progress bar
|
30 |
+
# with gr.Progress(track_tqdm=True) as progress:
|
31 |
+
# report = generate_report(image_path, progress=progress)
|
32 |
+
|
33 |
+
report = generate_report(image_path)
|
34 |
+
|
35 |
+
elapsed = time.time() - start
|
36 |
+
yield f"### Radiology Report\n{report}\n\n---\n*Generated in `{elapsed:0.1f}` s*"
|
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 |
+
generate_btn = gr.Button("Generate Report")
|
48 |
+
|
49 |
+
generate_btn.click(
|
50 |
+
fn=process_upload, # generator function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
inputs=input_image,
|
52 |
outputs=output_report
|
53 |
)
|
54 |
|
|
|
|
|
|
|
55 |
if __name__ == "__main__":
|
56 |
demo.launch()
|
src/.DS_Store
CHANGED
Binary files a/src/.DS_Store and b/src/.DS_Store differ
|
|