Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,13 +10,15 @@ import shutil
|
|
| 10 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
| 11 |
|
| 12 |
def detect_video(video):
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
|
|
|
| 20 |
|
| 21 |
# List to hold results
|
| 22 |
detection_results = []
|
|
|
|
| 10 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
| 11 |
|
| 12 |
def detect_video(video):
|
| 13 |
+
# Check if the video is in bytes (Gradio typically passes it as bytes)
|
| 14 |
+
if isinstance(video, bytes):
|
| 15 |
+
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
|
| 16 |
+
tmpfile.write(video) # Write the bytes to the temp file
|
| 17 |
+
video_path = tmpfile.name # Get the temp file path
|
| 18 |
+
else:
|
| 19 |
+
video_path = video # In case it's already a file path
|
| 20 |
|
| 21 |
+
cap = cv2.VideoCapture(video_path) # Open the temporary video file
|
| 22 |
|
| 23 |
# List to hold results
|
| 24 |
detection_results = []
|