File size: 2,474 Bytes
bf9d629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba11599
bf9d629
 
 
5177dcf
bf9d629
 
 
 
5177dcf
bf9d629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58e3a0c
bf9d629
 
 
5177dcf
bf9d629
5177dcf
44c7dba
ea848f3
bf9d629
 
5177dcf
bf9d629
 
be2e8f1
ea848f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio as gr
import os
from glob import glob
from diffusers.utils import load_image
import spaces
from panna import SVD


model = SVD()
example_files = []
root_url = "https://huggingface.co/spaces/multimodalart/stable-video-diffusion/resolve/main/images"
examples = ["disaster_meme.png", "distracted_meme.png", "hide_meme.png", "success_meme.png", "willy_meme.png", "wink_meme.png"]
for example in examples:
    load_image(f"{root_url}/{example}").save(example)
tmp_output_dir = "outputs"
os.makedirs(tmp_output_dir, exist_ok=True)
title = ("# [Stable Video Diffusion](ttps://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt)\n"
         "The demo is part of [panna](https://github.com/asahi417/panna) project.")


@spaces.GPU(duration=120)
def infer(init_image, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed):
    base_count = len(glob(os.path.join(tmp_output_dir, "*.mp4")))
    video_path = os.path.join(tmp_output_dir, f"{base_count:06d}.mp4")
    frames = model.image2video(
        [init_image],
        num_frames=num_frames,
        motion_bucket_id=motion_bucket_id,
        noise_aug_strength=noise_aug_strength,
        decode_chunk_size=decode_chunk_size,
        fps=fps,
        seed=seed
    )
    model.export(frames[0], video_path, fps)
    return video_path


with gr.Blocks() as demo:
    gr.Markdown(title)
    with gr.Row():
        with gr.Column():
            image = gr.Image(label="Upload your image", type="pil")
            run_button = gr.Button("Generate")
        video = gr.Video()
    with gr.Accordion("Advanced options", open=False):
        seed = gr.Slider(label="Seed", minimum=0, maximum=1_000_000, step=1, value=0)
        num_frames = gr.Slider(label="Number of frames", minimum=1, maximum=100, step=1, value=25)
        motion_bucket_id = gr.Slider(label="Motion bucket id", minimum=1, maximum=255, step=1, value=127)
        noise_aug_strength = gr.Slider(label="Noise strength", minimum=0, maximum=1, step=0.01, value=0.02)
        fps = gr.Slider(label="Frames per second", minimum=5, maximum=30, step=1, value=7)
        decode_chunk_size = gr.Slider(label="Decode chunk size", minimum=1, maximum=25, step=1, value=7)
    run_button.click(
        fn=infer,
        inputs=[image, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed],
        outputs=[video]
    )
    gr.Examples(examples=examples, inputs=image)
demo.launch(server_name="0.0.0.0")