This PR allows to automatically change the seed
#1
by
Fabrice-TIERCELIN
- opened
app.py
CHANGED
|
@@ -3,9 +3,12 @@ import os
|
|
| 3 |
from glob import glob
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
import spaces
|
|
|
|
| 6 |
from panna.pipeline import PipelineSVDUpscale
|
| 7 |
|
| 8 |
|
|
|
|
|
|
|
| 9 |
model = PipelineSVDUpscale(upscaler="instruct_ir")
|
| 10 |
example_files = []
|
| 11 |
root_url = "https://huggingface.co/spaces/multimodalart/stable-video-diffusion/resolve/main/images"
|
|
@@ -19,7 +22,10 @@ title = ("# [Stable Video Diffusion](ttps://huggingface.co/stabilityai/stable-vi
|
|
| 19 |
|
| 20 |
|
| 21 |
@spaces.GPU(duration=120)
|
| 22 |
-
def infer(init_image, upscaler_prompt, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed):
|
|
|
|
|
|
|
|
|
|
| 23 |
base_count = len(glob(os.path.join(tmp_output_dir, "*.mp4")))
|
| 24 |
video_path = os.path.join(tmp_output_dir, f"{base_count:06d}.mp4")
|
| 25 |
model(
|
|
@@ -41,19 +47,20 @@ with gr.Blocks() as demo:
|
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column():
|
| 43 |
image = gr.Image(label="Upload your image", type="pil")
|
| 44 |
-
run_button = gr.Button("Generate")
|
| 45 |
-
video = gr.Video()
|
| 46 |
with gr.Accordion("Advanced options", open=False):
|
| 47 |
upscaler_prompt = gr.Text("Correct the motion blur in this image so it is more clear", label="Prompt for upscaler", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False)
|
| 48 |
-
seed = gr.Slider(label="Seed", minimum=0, maximum=1_000_000, step=1, value=0)
|
| 49 |
num_frames = gr.Slider(label="Number of frames", minimum=1, maximum=100, step=1, value=25)
|
| 50 |
motion_bucket_id = gr.Slider(label="Motion bucket id", minimum=1, maximum=255, step=1, value=127)
|
| 51 |
noise_aug_strength = gr.Slider(label="Noise strength", minimum=0, maximum=1, step=0.01, value=0.02)
|
| 52 |
fps = gr.Slider(label="Frames per second", minimum=5, maximum=30, step=1, value=7)
|
| 53 |
decode_chunk_size = gr.Slider(label="Decode chunk size", minimum=1, maximum=25, step=1, value=7)
|
|
|
|
|
|
|
| 54 |
run_button.click(
|
| 55 |
fn=infer,
|
| 56 |
-
inputs=[image, upscaler_prompt, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed],
|
| 57 |
outputs=[video]
|
| 58 |
)
|
| 59 |
gr.Examples(examples=examples, inputs=image)
|
|
|
|
| 3 |
from glob import glob
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
import spaces
|
| 6 |
+
import random
|
| 7 |
from panna.pipeline import PipelineSVDUpscale
|
| 8 |
|
| 9 |
|
| 10 |
+
max_64_bit_int = 1_000_000
|
| 11 |
+
|
| 12 |
model = PipelineSVDUpscale(upscaler="instruct_ir")
|
| 13 |
example_files = []
|
| 14 |
root_url = "https://huggingface.co/spaces/multimodalart/stable-video-diffusion/resolve/main/images"
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
@spaces.GPU(duration=120)
|
| 25 |
+
def infer(init_image, upscaler_prompt, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed, randomize_seed):
|
| 26 |
+
if randomize_seed:
|
| 27 |
+
seed = random.randint(0, max_64_bit_int)
|
| 28 |
+
|
| 29 |
base_count = len(glob(os.path.join(tmp_output_dir, "*.mp4")))
|
| 30 |
video_path = os.path.join(tmp_output_dir, f"{base_count:06d}.mp4")
|
| 31 |
model(
|
|
|
|
| 47 |
with gr.Row():
|
| 48 |
with gr.Column():
|
| 49 |
image = gr.Image(label="Upload your image", type="pil")
|
| 50 |
+
run_button = gr.Button(value="Generate", variant="primary")
|
| 51 |
+
video = gr.Video(autoplay=True)
|
| 52 |
with gr.Accordion("Advanced options", open=False):
|
| 53 |
upscaler_prompt = gr.Text("Correct the motion blur in this image so it is more clear", label="Prompt for upscaler", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False)
|
|
|
|
| 54 |
num_frames = gr.Slider(label="Number of frames", minimum=1, maximum=100, step=1, value=25)
|
| 55 |
motion_bucket_id = gr.Slider(label="Motion bucket id", minimum=1, maximum=255, step=1, value=127)
|
| 56 |
noise_aug_strength = gr.Slider(label="Noise strength", minimum=0, maximum=1, step=0.01, value=0.02)
|
| 57 |
fps = gr.Slider(label="Frames per second", minimum=5, maximum=30, step=1, value=7)
|
| 58 |
decode_chunk_size = gr.Slider(label="Decode chunk size", minimum=1, maximum=25, step=1, value=7)
|
| 59 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 60 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=1_000_000, step=1, value=0)
|
| 61 |
run_button.click(
|
| 62 |
fn=infer,
|
| 63 |
+
inputs=[image, upscaler_prompt, num_frames, motion_bucket_id, noise_aug_strength, decode_chunk_size, fps, seed, randomize_seed],
|
| 64 |
outputs=[video]
|
| 65 |
)
|
| 66 |
gr.Examples(examples=examples, inputs=image)
|