Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import os
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Seek to the desired starting point
|
| 16 |
-
if current_time < clip_start:
|
| 17 |
-
video.set(cv2.CAP_PROP_POS_MSEC, clip_start * 1000)
|
| 18 |
-
success, frame = video.read()
|
| 19 |
-
continue
|
| 20 |
-
|
| 21 |
-
# Check duration after reaching the clip_start timestamp
|
| 22 |
-
elif current_time - clip_start <= clip_duration:
|
| 23 |
-
frames.append(frame)
|
| 24 |
-
|
| 25 |
-
success, frame = video.read()
|
| 26 |
-
count += 1
|
| 27 |
-
|
| 28 |
-
else:
|
| 29 |
-
break
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
def display_frames(frames):
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
# Create Gradio interface
|
| 41 |
video_input = gr.inputs.Video(type="file")
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
def install_opencv():
|
| 6 |
+
try:
|
| 7 |
+
import cv2
|
| 8 |
+
print("OpenCV is already installed.")
|
| 9 |
+
except ImportError:
|
| 10 |
+
print("Installing OpenCV...")
|
| 11 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "opencv-python"])
|
| 12 |
+
print("OpenCV installation completed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def extract_clip(video_path, clip_start, clip_duration):
|
| 15 |
+
# ... (rest of your extract_clip function)
|
| 16 |
|
| 17 |
def display_frames(frames):
|
| 18 |
+
# ... (rest of your display_frames function)
|
| 19 |
+
|
| 20 |
+
# Install OpenCV if not already installed
|
| 21 |
+
install_opencv()
|
| 22 |
|
| 23 |
# Create Gradio interface
|
| 24 |
video_input = gr.inputs.Video(type="file")
|