edeler commited on
Commit
1245792
Β·
verified Β·
1 Parent(s): 771674d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -36
app.py CHANGED
@@ -200,8 +200,7 @@ class GradioApp:
200
  def process_image(
201
  self,
202
  image: Optional[np.ndarray],
203
- confidence: float,
204
- nms_threshold: float
205
  ) -> Tuple[Optional[Image.Image], str]:
206
  """
207
  Process image and return annotated result.
@@ -209,7 +208,6 @@ class GradioApp:
209
  Args:
210
  image: Input image
211
  confidence: Confidence threshold
212
- nms_threshold: NMS threshold
213
 
214
  Returns:
215
  Tuple of (annotated_image, summary_text)
@@ -218,11 +216,11 @@ class GradioApp:
218
  return None, "Please upload an image."
219
 
220
  try:
221
- # Perform detection
222
  detections, image_bgr = self.pipeline.detect(
223
  image,
224
  confidence_threshold=confidence,
225
- nms_threshold=nms_threshold
226
  )
227
 
228
  # Annotate image
@@ -256,13 +254,29 @@ class GradioApp:
256
  with gr.Row():
257
  # Left column - Input and controls
258
  with gr.Column(scale=1):
259
- gr.Markdown("### πŸ“€ Upload Image")
 
260
  input_img = gr.Image(
261
  label="Input Image",
262
  type="numpy",
263
  interactive=True
264
  )
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  # Detection parameters
267
  gr.Markdown("### βš™οΈ Detection Parameters")
268
  confidence_slider = gr.Slider(
@@ -274,15 +288,6 @@ class GradioApp:
274
  info="Minimum confidence for a detection"
275
  )
276
 
277
- nms_slider = gr.Slider(
278
- minimum=0.0,
279
- maximum=1.0,
280
- value=0.0,
281
- step=0.05,
282
- label="NMS Threshold",
283
- info="IoU threshold for non-maximum suppression"
284
- )
285
-
286
  # Action buttons
287
  with gr.Row():
288
  clear_btn = gr.Button("πŸ—‘οΈ Clear", variant="secondary")
@@ -300,24 +305,6 @@ class GradioApp:
300
  label="Detection Summary"
301
  )
302
 
303
- # Examples section
304
- gr.Markdown("### πŸ“‹ Example Images")
305
- example_root = os.path.dirname(__file__)
306
- example_images = [
307
- [os.path.join(example_root, file), 0.1, 0.0]
308
- for file in os.listdir(example_root)
309
- if file.lower().endswith(('.jpg', '.jpeg', '.png'))
310
- ]
311
-
312
- if example_images:
313
- gr.Examples(
314
- examples=example_images,
315
- inputs=[input_img, confidence_slider, nms_slider],
316
- outputs=[output_img, detection_summary],
317
- fn=self.process_image,
318
- cache_examples=False
319
- )
320
-
321
  # Footer
322
  gr.Markdown(
323
  """
@@ -328,17 +315,17 @@ class GradioApp:
328
 
329
  # Event handlers
330
  def reset_interface():
331
- return None, None, "Results will appear here...", 0.1, 0.0
332
 
333
  clear_btn.click(
334
  fn=reset_interface,
335
  inputs=None,
336
- outputs=[input_img, output_img, detection_summary, confidence_slider, nms_slider]
337
  )
338
 
339
  detect_btn.click(
340
  fn=self.process_image,
341
- inputs=[input_img, confidence_slider, nms_slider],
342
  outputs=[output_img, detection_summary]
343
  )
344
 
 
200
  def process_image(
201
  self,
202
  image: Optional[np.ndarray],
203
+ confidence: float
 
204
  ) -> Tuple[Optional[Image.Image], str]:
205
  """
206
  Process image and return annotated result.
 
208
  Args:
209
  image: Input image
210
  confidence: Confidence threshold
 
211
 
212
  Returns:
213
  Tuple of (annotated_image, summary_text)
 
216
  return None, "Please upload an image."
217
 
218
  try:
219
+ # Perform detection (NMS threshold from config)
220
  detections, image_bgr = self.pipeline.detect(
221
  image,
222
  confidence_threshold=confidence,
223
+ nms_threshold=None # Use default from config
224
  )
225
 
226
  # Annotate image
 
254
  with gr.Row():
255
  # Left column - Input and controls
256
  with gr.Column(scale=1):
257
+ # Examples section BEFORE upload
258
+ gr.Markdown("### πŸ“‹ Example Images")
259
  input_img = gr.Image(
260
  label="Input Image",
261
  type="numpy",
262
  interactive=True
263
  )
264
 
265
+ example_root = os.path.dirname(__file__)
266
+ example_images = [
267
+ os.path.join(example_root, file)
268
+ for file in os.listdir(example_root)
269
+ if file.lower().endswith(('.jpg', '.jpeg', '.png'))
270
+ ]
271
+
272
+ if example_images:
273
+ gr.Examples(
274
+ examples=example_images,
275
+ inputs=[input_img],
276
+ )
277
+
278
+ gr.Markdown("### πŸ“€ Or Upload Your Own Image")
279
+
280
  # Detection parameters
281
  gr.Markdown("### βš™οΈ Detection Parameters")
282
  confidence_slider = gr.Slider(
 
288
  info="Minimum confidence for a detection"
289
  )
290
 
 
 
 
 
 
 
 
 
 
291
  # Action buttons
292
  with gr.Row():
293
  clear_btn = gr.Button("πŸ—‘οΈ Clear", variant="secondary")
 
305
  label="Detection Summary"
306
  )
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  # Footer
309
  gr.Markdown(
310
  """
 
315
 
316
  # Event handlers
317
  def reset_interface():
318
+ return None, None, "Results will appear here...", 0.1
319
 
320
  clear_btn.click(
321
  fn=reset_interface,
322
  inputs=None,
323
+ outputs=[input_img, output_img, detection_summary, confidence_slider]
324
  )
325
 
326
  detect_btn.click(
327
  fn=self.process_image,
328
+ inputs=[input_img, confidence_slider],
329
  outputs=[output_img, detection_summary]
330
  )
331