samyakshrestha commited on
Commit
9e156d3
·
1 Parent(s): 24a53f5

Simplified UI

Browse files
Files changed (1) hide show
  1. app.py +35 -18
app.py CHANGED
@@ -4,37 +4,54 @@ 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
-
 
4
 
5
  # Pre-load models
6
  from src.tools_loader import get_tools
7
+ _ = get_tools() # Load necessary tools/models at startup for faster inference
8
 
9
  def process_upload(image_path: str):
10
+ # Handle case where no image is uploaded
11
  if image_path is None:
12
  yield "Please upload a chest X-ray image."
13
  return
14
 
15
+ start = time.time() # Start timer for report generation
16
+ yield "Analyzing image..." # Inform user that analysis is in progress
17
 
18
+ report = generate_report(image_path) # Generate radiology report using pipeline
19
+ elapsed = time.time() - start # Calculate elapsed time
20
 
21
+ # Display the generated report along with time taken
22
  yield f"### Radiology Report\n{report}\n\n*Generated in {elapsed:.1f}s*"
23
 
24
+ # Create enhanced Gradio interface with custom layout
25
+ with gr.Blocks(title="Multi-Agent Radiology Assistant") as demo:
26
+ gr.Markdown("# Multi-Agent Radiology Assistant") # App title
27
+ gr.Markdown("Upload a chest X-ray image to receive an AI-generated radiology report") # App description
28
 
29
+ with gr.Row(): # Layout row for input
30
+ with gr.Column(scale=1): # Column for image upload and button
31
+ input_image = gr.Image(
32
+ type="filepath",
33
+ label="Upload Chest X-ray",
34
+ height=400 # Set image display height
35
+ )
36
+ process_btn = gr.Button("Generate Report", variant="primary") # Button to trigger report generation
37
 
38
+ with gr.Row(): # Layout row for output
39
+ output_report = gr.Markdown(
40
+ label="Radiology Report",
41
+ height=300 # Set output display height
42
+ )
43
+
44
+ # Connect the button to processing function
45
+ process_btn.click(
46
+ fn=process_upload, # Function to call on button click
47
+ inputs=[input_image], # Input to the function
48
+ outputs=[output_report] # Output from the function
49
+ )
50
+
51
+ gr.Markdown(
52
  "Download and use any frontal chest X-ray PNG/JPG file from the internet and click **Generate Report**.\n"
53
  "### 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."
54
+ ) # Disclaimer and instructions
55
 
56
  if __name__ == "__main__":
57
+ demo.launch() # Launch the Gradio app if run as main script