Kiransubedi545 commited on
Commit
afa3d9d
·
verified ·
1 Parent(s): f165f91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -8,11 +8,11 @@ model_path = MODEL_PATHS["YOLOv8n"]
8
  model = YOLO(model_path)
9
 
10
  # ---------- Detection Functions ----------
11
- def detect_image_fn(image_path, confidence):
12
- if image_path is None:
13
  return None
14
- results = detect_from_images([image_path], model, confidence, return_path=True)
15
- return results[0] if results else None
16
 
17
  def detect_video_fn(video_file, confidence):
18
  if video_file is None:
@@ -27,7 +27,7 @@ def detect_video_fn(video_file, confidence):
27
  image_interface = gr.Interface(
28
  fn=detect_image_fn,
29
  inputs=[
30
- gr.Image(label="Upload Image"), # No type="filepath"
31
  gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
32
  ],
33
  outputs=gr.Image(label="Predicted Output"),
@@ -38,7 +38,7 @@ image_interface = gr.Interface(
38
  video_interface = gr.Interface(
39
  fn=detect_video_fn,
40
  inputs=[
41
- gr.Video(label="Upload Video"), # No type="file"
42
  gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
43
  ],
44
  outputs=gr.Video(label="Predicted Output"),
@@ -50,5 +50,5 @@ video_interface = gr.Interface(
50
  gr.TabbedInterface(
51
  [image_interface, video_interface],
52
  tab_names=["Image Detection", "Video Detection"]
53
- ).launch(share=True)
54
 
 
8
  model = YOLO(model_path)
9
 
10
  # ---------- Detection Functions ----------
11
+ def detect_image_fn(image, confidence):
12
+ if image is None:
13
  return None
14
+ output_paths = detect_from_images([image], model, confidence, return_path=True)
15
+ return output_paths[0] if output_paths else None
16
 
17
  def detect_video_fn(video_file, confidence):
18
  if video_file is None:
 
27
  image_interface = gr.Interface(
28
  fn=detect_image_fn,
29
  inputs=[
30
+ gr.Image(type="filepath", label="Upload Image"),
31
  gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
32
  ],
33
  outputs=gr.Image(label="Predicted Output"),
 
38
  video_interface = gr.Interface(
39
  fn=detect_video_fn,
40
  inputs=[
41
+ gr.Video(type="filepath", label="Upload Video"),
42
  gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
43
  ],
44
  outputs=gr.Video(label="Predicted Output"),
 
50
  gr.TabbedInterface(
51
  [image_interface, video_interface],
52
  tab_names=["Image Detection", "Video Detection"]
53
+ ).launch()
54