Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,13 @@ import gradio as gr
|
|
2 |
from ultralytics import YOLO
|
3 |
import cv2
|
4 |
from deep_sort_realtime.deepsort_tracker import DeepSort
|
5 |
-
import tempfile
|
6 |
|
7 |
# Initialize YOLO model
|
8 |
model = YOLO("yolov8l.pt") # Load YOLOv8 model
|
9 |
tracker = DeepSort(max_age=30, n_init=3, nn_budget=100)
|
10 |
|
11 |
-
def count_people_in_video(
|
12 |
-
cap = cv2.VideoCapture(
|
13 |
total_ids = set() # Track unique IDs
|
14 |
|
15 |
while cap.isOpened():
|
@@ -42,11 +41,9 @@ def count_people_in_video(video_file):
|
|
42 |
|
43 |
# Gradio Interface
|
44 |
def process_video(video_file):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
total_people = count_people_in_video(temp_file.name)
|
49 |
-
return f"Total unique people in the video: {total_people}"
|
50 |
|
51 |
interface = gr.Interface(
|
52 |
fn=process_video,
|
@@ -57,4 +54,4 @@ interface = gr.Interface(
|
|
57 |
)
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
-
interface.launch()
|
|
|
2 |
from ultralytics import YOLO
|
3 |
import cv2
|
4 |
from deep_sort_realtime.deepsort_tracker import DeepSort
|
|
|
5 |
|
6 |
# Initialize YOLO model
|
7 |
model = YOLO("yolov8l.pt") # Load YOLOv8 model
|
8 |
tracker = DeepSort(max_age=30, n_init=3, nn_budget=100)
|
9 |
|
10 |
+
def count_people_in_video(video_path):
|
11 |
+
cap = cv2.VideoCapture(video_path) # Load video
|
12 |
total_ids = set() # Track unique IDs
|
13 |
|
14 |
while cap.isOpened():
|
|
|
41 |
|
42 |
# Gradio Interface
|
43 |
def process_video(video_file):
|
44 |
+
# The `video_file` is a path to the temporary file
|
45 |
+
total_people = count_people_in_video(video_file)
|
46 |
+
return f"Total unique people in the video: {total_people}"
|
|
|
|
|
47 |
|
48 |
interface = gr.Interface(
|
49 |
fn=process_video,
|
|
|
54 |
)
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
+
interface.launch(share=True)
|