Spaces:
Runtime error
Runtime error
| import subprocess | |
| import sys | |
| import gradio as gr | |
| def install_opencv(): | |
| try: | |
| import cv2 | |
| print("OpenCV is already installed.") | |
| except ImportError: | |
| print("Installing OpenCV...") | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "opencv-python"]) | |
| print("OpenCV installation completed.") | |
| def extract_clip(video_path, clip_start, clip_duration): | |
| # ... (rest of your extract_clip function) | |
| def display_frames(frames): | |
| num_cols = 4 # Number of columns in the image grid | |
| num_rows = (len(frames) + num_cols - 1) // num_cols | |
| grid_image = cv2.hconcat([cv2.hconcat(frames[i:i+num_cols]) for i in range(0, len(frames), num_cols)]) | |
| return grid_image | |
| # Install OpenCV if not already installed | |
| install_opencv() | |
| # Create Gradio interface | |
| video_input = gr.inputs.Video(type="file") | |
| start_input = gr.inputs.Number(default=5, label="Start Time (seconds)") | |
| duration_input = gr.inputs.Number(default=3, label="Duration (seconds)") | |
| image_output = gr.outputs.Image(type="pil") | |
| gr.Interface(fn=lambda video, start, duration: display_frames(extract_clip(video, start, duration)), | |
| inputs=[video_input, start_input, duration_input], | |
| outputs=image_output, | |
| title="Extract Video Clip").launch() |