Spaces:
Build error
Build error
| # 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() |