BhumikaMak commited on
Commit
d4cd198
·
1 Parent(s): 70f0887

Fix: revert-3

Browse files
Files changed (1) hide show
  1. app.py +36 -16
app.py CHANGED
@@ -83,35 +83,55 @@ def process_image(choice, yolo_versions=["yolov5"]):
83
 
84
  with gr.Blocks() as interface:
85
  gr.Markdown("# XAI: Visualize Object Detection of Your Models")
86
- gr.Markdown("Select a sample image to visualize object detection.")
 
 
87
  default_sample = "Sample 1"
88
- with gr.Row():
 
 
89
  sample_selection = gr.Radio(
90
  choices=list(sample_images.keys()),
91
  label="Select a Sample Image",
92
  type="value",
93
  value=default_sample, # Set default selection
94
  )
95
- sample_display = gr.Image(
96
- value=load_sample_image(default_sample),
97
- label="Selected Sample Image",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  )
99
- sample_selection.change(
100
- fn=load_sample_image,
101
- inputs=sample_selection,
102
- outputs=sample_display,
103
- )
104
 
105
- selected_models = gr.CheckboxGroup(
106
- choices=["yolov5", "yolov8s"],
107
- value=["yolov5"],
108
- label="Select Model(s)",
109
- )
110
  result_gallery = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500)
111
 
 
112
  gr.Button("Run").click(
113
  fn=process_image,
114
- inputs=[sample_selection, selected_models],
115
  outputs=result_gallery,
116
  )
117
 
 
83
 
84
  with gr.Blocks() as interface:
85
  gr.Markdown("# XAI: Visualize Object Detection of Your Models")
86
+ gr.Markdown("Select a sample image or upload your own image to visualize object detection.")
87
+
88
+ # Default sample image selection
89
  default_sample = "Sample 1"
90
+
91
+ with gr.Column(): # Column layout for the image selection section
92
+ # Radio button with default value set
93
  sample_selection = gr.Radio(
94
  choices=list(sample_images.keys()),
95
  label="Select a Sample Image",
96
  type="value",
97
  value=default_sample, # Set default selection
98
  )
99
+ # Display the selected or uploaded image
100
+ image_display = gr.Image(
101
+ value=load_sample_image(default_sample), # Load default sample image
102
+ label="Selected/Uploaded Image",
103
+ )
104
+
105
+ # File upload for custom images (placed below the sample selection)
106
+ uploaded_image = gr.Image(type="numpy", label="Upload an Image")
107
+
108
+ # Update display when sample selection changes
109
+ sample_selection.change(
110
+ fn=load_sample_image,
111
+ inputs=sample_selection,
112
+ outputs=image_display,
113
+ )
114
+
115
+ uploaded_image.change(
116
+ fn=lambda img: img,
117
+ inputs=uploaded_image,
118
+ outputs=image_display,
119
+ )
120
+
121
+ # Place the "Select Model(s)" below the image selection block
122
+ with gr.Column(): # Column layout for model selection
123
+ selected_models = gr.CheckboxGroup(
124
+ choices=["yolov5", "yolov8s"],
125
+ value=["yolov5"],
126
+ label="Select Model(s)",
127
  )
 
 
 
 
 
128
 
 
 
 
 
 
129
  result_gallery = gr.Gallery(label="Results", elem_id="gallery", rows=2, height=500)
130
 
131
+ # Use the uploaded image if available, otherwise the selected sample
132
  gr.Button("Run").click(
133
  fn=process_image,
134
+ inputs=[image_display, selected_models],
135
  outputs=result_gallery,
136
  )
137