Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load YOLOv5 model
|
7 |
+
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
|
8 |
+
|
9 |
+
def object_detection(video):
|
10 |
+
cap = cv2.VideoCapture(video.name)
|
11 |
+
|
12 |
+
while True:
|
13 |
+
ret, frame = cap.read()
|
14 |
+
|
15 |
+
if not ret:
|
16 |
+
break
|
17 |
+
|
18 |
+
# Object detection
|
19 |
+
results = model(frame)
|
20 |
+
|
21 |
+
# Render results
|
22 |
+
results.render()
|
23 |
+
|
24 |
+
yield results.imgs[0]
|
25 |
+
|
26 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
27 |
+
break
|
28 |
+
|
29 |
+
cap.release()
|
30 |
+
|
31 |
+
iface = gr.Interface(fn=object_detection, inputs=gr.Video(), outputs=gr.Image(label="Object Detection"))
|
32 |
+
iface.launch()
|