Spaces:
Build error
Build error
File size: 719 Bytes
b2ce27a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# Import necessary libraries
import cv2
import gradio as gr
def video_stream(video):
"""
Process video uploaded by the user (works with webcam in Gradio live interface).
"""
cap = cv2.VideoCapture(video)
if not cap.isOpened():
raise RuntimeError("Error: Could not access the video.")
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# Resize the frame for faster processing
frame = cv2.resize(frame, (640, 480))
cap.release()
# Create Gradio app
gr.Interface(
fn=video_stream,
inputs=gr.Video(label="Upload Video or Stream"),
outputs=gr.Video(label="Live Object Detection"),
live=True
).launch() |