Spaces:
Runtime error
Runtime error
| import cv2 | |
| import gradio as gr | |
| import tempfile | |
| from ultralytics import YOLO | |
| model = YOLO("yolov8n-pose.pt") | |
| def process_video(video_path): | |
| cap = cv2.VideoCapture(video_path) | |
| w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
| h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
| fps = cap.get(cv2.CAP_PROP_FPS) | |
| out_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") | |
| out = cv2.VideoWriter( | |
| out_file.name, | |
| cv2.VideoWriter_fourcc(*"mp4v"), | |
| fps, | |
| (w, h) | |
| ) | |
| while cap.isOpened(): | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| results = model(frame, verbose=False) | |
| for r in results: | |
| frame = r.plot() | |
| out.write(frame) | |
| cap.release() | |
| out.release() | |
| return out_file.name | |
| gr.Interface( | |
| fn=process_video, | |
| inputs=gr.Video(label="Upload Video"), | |
| outputs=gr.Video(label="Pose Detection Output"), | |
| title="🎥 YOLOv8 Video Pose Detection" | |
| ).launch() | |