hb-setosys commited on
Commit
9f44384
·
verified ·
1 Parent(s): 183b1ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -6,7 +6,7 @@ import os
6
  # Load YOLO model
7
  net = cv2.dnn.readNet('yolov3.weights', 'yolov3.cfg')
8
 
9
- # Set backend (CPU or GPU)
10
  net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
11
  net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
12
 
@@ -98,15 +98,27 @@ def analyze_image(image):
98
  processed_image, people_count = count_people_in_frame(image_cv)
99
  return processed_image, f"People in Image: {people_count}"
100
 
101
- # Gradio Interface
102
- interface = gr.Interface(
103
- fn=[analyze_image, analyze_video], # Supports both image & video
104
- inputs=[gr.Image(type="pil", label="Upload Image"), gr.Video(label="Upload Video")],
105
  outputs=[gr.Image(label="Processed Image"), gr.Textbox(label="People Counting Results")],
106
- title="YOLO-based People Counter",
107
- description="Upload an image or video to detect and count people using YOLOv3."
108
  )
109
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  # Launch app
111
  if __name__ == "__main__":
112
- interface.launch()
 
6
  # Load YOLO model
7
  net = cv2.dnn.readNet('yolov3.weights', 'yolov3.cfg')
8
 
9
+ # Set backend (CPU)
10
  net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
11
  net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
12
 
 
98
  processed_image, people_count = count_people_in_frame(image_cv)
99
  return processed_image, f"People in Image: {people_count}"
100
 
101
+ # Gradio Interface for Image Processing
102
+ image_interface = gr.Interface(
103
+ fn=analyze_image,
104
+ inputs=gr.Image(type="pil", label="Upload Image"),
105
  outputs=[gr.Image(label="Processed Image"), gr.Textbox(label="People Counting Results")],
106
+ title="YOLO People Counter (Image)",
107
+ description="Upload an image to detect and count people using YOLOv3."
108
  )
109
 
110
+ # Gradio Interface for Video Processing
111
+ video_interface = gr.Interface(
112
+ fn=analyze_video,
113
+ inputs=gr.Video(label="Upload Video"),
114
+ outputs=gr.Textbox(label="People Counting Results"),
115
+ title="YOLO People Counter (Video)",
116
+ description="Upload a video to detect and count people using YOLOv3."
117
+ )
118
+
119
+ # Combine both interfaces into tabs
120
+ app = gr.TabbedInterface([image_interface, video_interface], ["Image Mode", "Video Mode"])
121
+
122
  # Launch app
123
  if __name__ == "__main__":
124
+ app.launch()