samyakshrestha commited on
Commit
5c7cdbe
·
1 Parent(s): 2c45fd9

Changed UI

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +49 -40
  3. src/.DS_Store +0 -0
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -1,54 +1,63 @@
1
  import gradio as gr
2
  from src.pipeline import generate_report
3
 
4
- def process_upload(image):
5
- """Process uploaded X-ray image and return radiology report"""
6
- if image is None:
7
- return None, "Please upload a chest X-ray image."
8
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  try:
10
- report = generate_report(image)
11
- return image, report # Return both image and report
12
  except Exception as e:
13
- return image, f"Error processing image: {str(e)}"
14
 
15
- # Create enhanced Gradio interface with custom layout
 
 
16
  with gr.Blocks(title="Multi-Agent Radiology Assistant") as demo:
17
- gr.Markdown("# Multi-Agent Radiology Assistant")
18
- gr.Markdown("Upload a chest X-ray image to receive an AI-generated radiology report using cutting-edge, multi-agent analysis")
19
-
20
- with gr.Row():
21
- with gr.Column(scale=1):
22
- input_image = gr.Image(
23
- type="filepath",
24
- label="Upload Chest X-ray",
25
- height=400
26
- )
27
- process_btn = gr.Button("Generate Report", variant="primary")
28
-
29
- with gr.Column(scale=1):
30
- output_image = gr.Image(
31
- label="Analyzed Image",
32
- height=400,
33
- interactive=False
34
- )
35
-
36
- with gr.Row():
37
- output_report = gr.Markdown(
38
- label="📄 Radiology Report",
39
- height=300
40
  )
41
-
42
- # Connect the button to processing function
 
 
 
 
43
  process_btn.click(
44
  fn=process_upload,
45
- inputs=[input_image],
46
- outputs=[output_image, output_report]
47
  )
48
-
49
- # Add examples section
50
- gr.Markdown("### Example X-rays")
51
- gr.Markdown("*Upload your own chest X-ray image above to get started*")
52
 
 
 
 
53
  if __name__ == "__main__":
54
  demo.launch()
 
1
  import gradio as gr
2
  from src.pipeline import generate_report
3
 
4
+ # ------------------------------------------------------------------
5
+ # 1. Pre-load models on Space start-up
6
+ # ------------------------------------------------------------------
7
+ print("Pre-loading models for fast inference ")
8
+ try:
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. Inference wrapper
17
+ # ------------------------------------------------------------------
18
+ def process_upload(image_path: str):
19
+ """Run the multi-agent pipeline on an uploaded chest X-ray."""
20
+ if image_path is None:
21
+ return "Please upload a chest X-ray image."
22
+
23
  try:
24
+ report = generate_report(image_path)
25
+ return report
26
  except Exception as e:
27
+ return f"Error processing image: {e}"
28
 
29
+ # ------------------------------------------------------------------
30
+ # 3. Gradio UI
31
+ # ------------------------------------------------------------------
32
  with gr.Blocks(title="Multi-Agent Radiology Assistant") as demo:
33
+ gr.Markdown(
34
+ """
35
+ # Multi-Agent Radiology Assistant
36
+ Upload a chest X-ray and receive an AI-generated report produced by a multi-agent pipeline.
37
+ """
38
+ )
39
+
40
+ # --- Upload widget + button ------------------------------------------------
41
+ with gr.Column():
42
+ input_image = gr.Image(
43
+ type="filepath",
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()
src/.DS_Store CHANGED
Binary files a/src/.DS_Store and b/src/.DS_Store differ