vincentiusyoshuac commited on
Commit
281e93d
·
verified ·
1 Parent(s): 8b0f993

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
5
  class ObjectDetector:
6
  def __init__(self):
7
  # Load YOLOv5 model from Torch Hub
8
- self.model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
9
 
10
  def count_objects(self, image):
11
  """
@@ -37,12 +37,13 @@ def create_interface():
37
  """Create and configure the Gradio interface"""
38
  detector = ObjectDetector()
39
 
 
40
  interface = gr.Interface(
41
  fn=detector.count_objects,
42
- inputs=gr.inputs.Image(type="pil"),
43
  outputs=[
44
- gr.outputs.Image(type="pil", label="Detected Objects"),
45
- gr.outputs.JSON(label="Object Counts")
46
  ],
47
  title="Object Detection and Counting System",
48
  description="Upload an image to detect and count objects using YOLOv5.",
 
5
  class ObjectDetector:
6
  def __init__(self):
7
  # Load YOLOv5 model from Torch Hub
8
+ self.model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, trust_repo=True)
9
 
10
  def count_objects(self, image):
11
  """
 
37
  """Create and configure the Gradio interface"""
38
  detector = ObjectDetector()
39
 
40
+ # Updated interface creation using new Gradio API
41
  interface = gr.Interface(
42
  fn=detector.count_objects,
43
+ inputs=gr.Image(type="pil"), # Updated from gr.inputs.Image
44
  outputs=[
45
+ gr.Image(type="pil", label="Detected Objects"), # Updated from gr.outputs.Image
46
+ gr.JSON(label="Object Counts") # Updated from gr.outputs.JSON
47
  ],
48
  title="Object Detection and Counting System",
49
  description="Upload an image to detect and count objects using YOLOv5.",