Spaces:
Runtime error
Runtime error
#!/usr/bin/env python | |
import os | |
import pathlib | |
import tempfile | |
import gradio as gr | |
import torch | |
from huggingface_hub import snapshot_download | |
from modelscope.outputs import OutputKeys | |
from modelscope.pipelines import pipeline | |
DESCRIPTION = "# ModelScope-Vid2Vid-XL" | |
if torch.cuda.is_available(): | |
model_cache_dir = os.getenv("MODEL_CACHE_DIR", "./models") | |
model_dir = pathlib.Path(model_cache_dir) / "MS-Vid2Vid-XL" | |
snapshot_download(repo_id="damo-vilab/MS-Vid2Vid-XL", repo_type="model", local_dir=model_dir) | |
pipe = pipeline(task="video-to-video", model=model_dir.as_posix(), model_revision="v1.1.0", device="cuda:0") | |
else: | |
pipe = None | |
def video_to_video(video_path: str, text: str) -> str: | |
p_input = {"video_path": video_path, "text": text} | |
output_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) | |
pipe(p_input, output_video=output_file.name)[OutputKeys.OUTPUT_VIDEO] | |
return output_file.name | |
with gr.Blocks(css="style.css") as demo: | |
gr.Markdown(DESCRIPTION) | |
input_video = gr.Video(label="Input video", type="filepath") | |
text_description = gr.Textbox(label="Text description") | |
run_button = gr.Button() | |
output_video = gr.Video(label="Output video") | |
run_button.click( | |
fn=video_to_video, | |
inputs=[input_video, text_description], | |
outputs=output_video, | |
api_name="run", | |
) | |
demo.queue(max_size=20).launch() | |