Yaroslav
Update app.py
4b9964c verified
raw
history blame
1.33 kB
import gradio as gr
import numpy as np
import cv2
def interpolate_frames(video_file, num_interpolations):
cap = cv2.VideoCapture(video_file)
frames = []
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frames.append(frame)
cap.release()
# Convert frames to numpy array
frames = np.array(frames)
# Interpolate frames
interpolated_frames = []
for i in range(len(frames) - 1):
for j in range(num_interpolations + 1):
alpha = j / (num_interpolations + 1)
interpolated_frame = cv2.addWeighted(frames[i], 1 - alpha, frames[i + 1], alpha, 0)
interpolated_frames.append(interpolated_frame)
return interpolated_frames
# Create a Gradio interface
with gr.Blocks() as demo:
gr.Markdown("## Video Frame Interpolation")
video_input = gr.File(label="Input Video")
num_interpolations = gr.Slider(1, 10, step=1, label="Number of Interpolations")
video_output = gr.Video(label="Interpolated Video")
start_button = gr.Button("Start Interpolation")
# Define the event listener for the start button
start_button.click(interpolate_frames, inputs=[video_input, num_interpolations], outputs=video_output)
# Launch the interface
if __name__ == "__main__":
demo.launch(show_error=True)