RIFE-NCNN / app.py
comfyri's picture
Update app.py
c37eb3f verified
import gradio as gr
import os
import subprocess
import shutil
# ===== RIFE ๋ชจ๋ธ ๊ฐ€์ค‘์น˜ ์ž๋™ ๋‹ค์šด๋กœ๋“œ =====
if not os.path.exists("train_log"):
os.makedirs("train_log", exist_ok=True)
subprocess.run(["wget", "-O", "train_log/RIFE_HDv3.pkl", "https://huggingface.co/datasets/wnshi/RIFE/resolve/main/train_log/RIFE_HDv3.pkl"])
subprocess.run(["wget", "-O", "train_log/RIFE_HDv2.pkl", "https://huggingface.co/datasets/wnshi/RIFE/resolve/main/train_log/RIFE_HDv2.pkl"])
subprocess.run(["wget", "-O", "train_log/RIFE_HD.pkl", "https://huggingface.co/datasets/wnshi/RIFE/resolve/main/train_log/RIFE_HD.pkl"])
# ===== GitHub์—์„œ RIFE ์›๋ณธ ์ฝ”๋“œ ๊ฐ€์ ธ์˜ค๊ธฐ =====
REPO_URL = "https://github.com/kimjongin0325-cyber/ECCV2022-RIFE.git"
REPO_DIR = "ECCV2022-RIFE"
if not os.path.exists(REPO_DIR):
print("๐Ÿ”„ Cloning RIFE repository from GitHub...")
os.system(f"git clone {REPO_URL}")
# ===== RIFE ์‹คํ–‰ ํ•จ์ˆ˜ =====
def process_video(video_file, scale=2.0, codec="OpenH264"):
if video_file is None:
raise gr.Error("Please upload a video file.")
input_path = "input_video.mp4"
output_path = "output_interp.mp4"
# ์—…๋กœ๋“œ๋œ ๋น„๋””์˜ค๋ฅผ ์ €์žฅ
shutil.copy(video_file, input_path)
# ECCV2022-RIFE ์‹คํ–‰ ๋ช…๋ น์–ด
cmd = (
f"python {REPO_DIR}/inference_video.py "
f"--exp=1 --scale={scale} "
f"--video={input_path} --output={output_path}"
)
print("๐Ÿš€ Running command:", cmd)
result = subprocess.run(cmd, shell=True, text=True, capture_output=True)
if result.returncode != 0:
print("โŒ Error:", result.stderr)
raise gr.Error(f"RIFE execution failed:\n{result.stderr}")
if not os.path.exists(output_path):
raise gr.Error("Output video was not generated.")
return output_path
# ===== Gradio UI ๊ตฌ์„ฑ =====
with gr.Blocks() as demo:
gr.Markdown("## ๐ŸŒ€ RIFE Frame Interpolation (ECCV 2022 Version)")
gr.Markdown("Upload a video and generate interpolated frames using RIFE (Kimjongin0325 Repository).")
with gr.Row():
with gr.Column():
input_video = gr.Video(label="Upload a video")
scale = gr.Slider(1.0, 4.0, value=2.0, step=0.5, label="Scale Factor")
codec = gr.Radio(["OpenH264", "H265", "AV1"], value="OpenH264", label="Codec")
submit_btn = gr.Button("๐Ÿช„ Interpolate Frames")
with gr.Column():
output_video = gr.Video(label="Interpolated Result")
submit_btn.click(
fn=process_video,
inputs=[input_video, scale, codec],
outputs=output_video
)
demo.launch()