File size: 1,097 Bytes
ec2de63
 
20bee2f
 
ec2de63
 
 
 
 
 
 
 
20bee2f
ec2de63
 
bbce39c
 
ec2de63
 
 
 
bbce39c
 
 
 
 
 
 
 
 
 
 
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
30
31
32
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):
    # ... (rest of your display_frames function)

# 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()