Spaces:
Paused
Paused
Commit
•
a79f40e
1
Parent(s):
c8b4b1d
Choose the frame format (#11)
Browse files- Choose the frame format (ffd4ed8bb7f89e3ce340694c0dc6cb9206079efc)
Co-authored-by: Fabrice TIERCELIN <Fabrice-TIERCELIN@users.noreply.huggingface.co>
app.py
CHANGED
@@ -6,10 +6,9 @@ from pathlib import Path
|
|
6 |
from typing import Optional
|
7 |
|
8 |
from diffusers import StableVideoDiffusionPipeline
|
9 |
-
from diffusers.utils import
|
10 |
from PIL import Image
|
11 |
|
12 |
-
import uuid
|
13 |
import random
|
14 |
import spaces
|
15 |
|
@@ -29,6 +28,7 @@ def sample(
|
|
29 |
fps_id: int = 6,
|
30 |
noise_aug_strength: float = 0.1,
|
31 |
decoding_t: int = 3,
|
|
|
32 |
version: str = "svd_xt",
|
33 |
device: str = "cuda",
|
34 |
output_folder: str = "outputs",
|
@@ -36,7 +36,7 @@ def sample(
|
|
36 |
if image.mode == "RGBA":
|
37 |
image = image.convert("RGB")
|
38 |
|
39 |
-
if
|
40 |
seed = random.randint(0, max_64_bit_int)
|
41 |
generator = torch.manual_seed(seed)
|
42 |
|
@@ -47,7 +47,7 @@ def sample(
|
|
47 |
frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=noise_aug_strength, num_frames=25).frames[0]
|
48 |
export_to_video(frames, video_path, fps=fps_id)
|
49 |
|
50 |
-
return video_path, frames, seed
|
51 |
|
52 |
def resize_image(image, output_size=(1024, 576)):
|
53 |
# Calculate aspect ratios
|
@@ -96,6 +96,7 @@ with gr.Blocks() as demo:
|
|
96 |
motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
|
97 |
noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
|
98 |
decoding_t = gr.Slider(label="Decoding", info="Number of frames decoded at a time; this eats more VRAM; reduce if necessary", value=3, minimum=1, maximum=5, step=1)
|
|
|
99 |
seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
|
100 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
101 |
|
@@ -106,7 +107,7 @@ with gr.Blocks() as demo:
|
|
106 |
gallery = gr.Gallery(label="Generated frames")
|
107 |
|
108 |
image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
|
109 |
-
generate_btn.click(fn=sample, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t], outputs=[video, gallery, seed], api_name="video")
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
demo.launch(share=True, show_api=False)
|
|
|
6 |
from typing import Optional
|
7 |
|
8 |
from diffusers import StableVideoDiffusionPipeline
|
9 |
+
from diffusers.utils import export_to_video
|
10 |
from PIL import Image
|
11 |
|
|
|
12 |
import random
|
13 |
import spaces
|
14 |
|
|
|
28 |
fps_id: int = 6,
|
29 |
noise_aug_strength: float = 0.1,
|
30 |
decoding_t: int = 3,
|
31 |
+
frame_format: str = "webp",
|
32 |
version: str = "svd_xt",
|
33 |
device: str = "cuda",
|
34 |
output_folder: str = "outputs",
|
|
|
36 |
if image.mode == "RGBA":
|
37 |
image = image.convert("RGB")
|
38 |
|
39 |
+
if randomize_seed:
|
40 |
seed = random.randint(0, max_64_bit_int)
|
41 |
generator = torch.manual_seed(seed)
|
42 |
|
|
|
47 |
frames = pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=noise_aug_strength, num_frames=25).frames[0]
|
48 |
export_to_video(frames, video_path, fps=fps_id)
|
49 |
|
50 |
+
return video_path, gr.update(label="Generated frames in *." + frame_format + " format", format = frame_format, value = frames), seed
|
51 |
|
52 |
def resize_image(image, output_size=(1024, 576)):
|
53 |
# Calculate aspect ratios
|
|
|
96 |
motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
|
97 |
noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
|
98 |
decoding_t = gr.Slider(label="Decoding", info="Number of frames decoded at a time; this eats more VRAM; reduce if necessary", value=3, minimum=1, maximum=5, step=1)
|
99 |
+
frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="webp", interactive=True)
|
100 |
seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
|
101 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
102 |
|
|
|
107 |
gallery = gr.Gallery(label="Generated frames")
|
108 |
|
109 |
image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
|
110 |
+
generate_btn.click(fn=sample, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format], outputs=[video, gallery, seed], api_name="video")
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
demo.launch(share=True, show_api=False)
|