Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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 |
-
|
| 103 |
-
fn=
|
| 104 |
-
inputs=
|
| 105 |
outputs=[gr.Image(label="Processed Image"), gr.Textbox(label="People Counting Results")],
|
| 106 |
-
title="YOLO
|
| 107 |
-
description="Upload an image
|
| 108 |
)
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
# Launch app
|
| 111 |
if __name__ == "__main__":
|
| 112 |
-
|
|
|
|
| 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()
|