Yaroslav
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
-
# This is a Gradio application for interpolating frames in a video.
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import cv2
|
5 |
|
6 |
-
# Function to interpolate frames in a video
|
7 |
def interpolate_frames(video_file, num_interpolations):
|
8 |
-
cap = cv2.VideoCapture(video_file)
|
9 |
frames = []
|
10 |
while cap.isOpened():
|
11 |
ret, frame = cap.read()
|
@@ -25,22 +23,14 @@ def interpolate_frames(video_file, num_interpolations):
|
|
25 |
interpolated_frame = cv2.addWeighted(frames[i], 1 - alpha, frames[i + 1], alpha, 0)
|
26 |
interpolated_frames.append(interpolated_frame)
|
27 |
|
28 |
-
|
29 |
-
output_video = "interpolated_video.mp4"
|
30 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
31 |
-
out = cv2.VideoWriter(output_video, fourcc, 30.0, (frames.shape[2], frames.shape[1]))
|
32 |
-
for frame in interpolated_frames:
|
33 |
-
out.write(frame)
|
34 |
-
out.release()
|
35 |
-
|
36 |
-
return output_video
|
37 |
|
38 |
# Create a Gradio interface
|
39 |
with gr.Blocks() as demo:
|
40 |
gr.Markdown("## Video Frame Interpolation")
|
41 |
-
video_input = gr.Video(label="Input Video", sources=["upload"
|
42 |
num_interpolations = gr.Slider(1, 10, step=1, label="Number of Interpolations")
|
43 |
-
video_output = gr.Video(label="Interpolated Video"
|
44 |
start_button = gr.Button("Start Interpolation")
|
45 |
|
46 |
# Define the event listener for the start button
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import cv2
|
4 |
|
|
|
5 |
def interpolate_frames(video_file, num_interpolations):
|
6 |
+
cap = cv2.VideoCapture(video_file.name)
|
7 |
frames = []
|
8 |
while cap.isOpened():
|
9 |
ret, frame = cap.read()
|
|
|
23 |
interpolated_frame = cv2.addWeighted(frames[i], 1 - alpha, frames[i + 1], alpha, 0)
|
24 |
interpolated_frames.append(interpolated_frame)
|
25 |
|
26 |
+
return interpolated_frames
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Create a Gradio interface
|
29 |
with gr.Blocks() as demo:
|
30 |
gr.Markdown("## Video Frame Interpolation")
|
31 |
+
video_input = gr.Video(label="Input Video", sources=["upload"])
|
32 |
num_interpolations = gr.Slider(1, 10, step=1, label="Number of Interpolations")
|
33 |
+
video_output = gr.Video(label="Interpolated Video")
|
34 |
start_button = gr.Button("Start Interpolation")
|
35 |
|
36 |
# Define the event listener for the start button
|