Spaces:
Build error
Build error
Download app.py from Muhammad-Faizan-Ahmed/Video-Streaming: direct link, hf CLI and curl.
- Browser
- Download file 719 Bytes
-
https://huggingface.co/spaces/Muhammad-Faizan-Ahmed/Video-Streaming/resolve/main/app.py
- Command line
-
hf download hf://spaces/Muhammad-Faizan-Ahmed/Video-Streaming/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Muhammad-Faizan-Ahmed/Video-Streaming/resolve/main/app.py
719 Bytes
| # 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() |