Spaces:
Running
on
Zero
Running
on
Zero
Video format
#21
by
Fabrice-TIERCELIN
- opened
app.py
CHANGED
@@ -31,6 +31,7 @@ def animate(
|
|
31 |
fps_id: int = 6,
|
32 |
noise_aug_strength: float = 0.1,
|
33 |
decoding_t: int = 3,
|
|
|
34 |
frame_format: str = "webp",
|
35 |
version: str = "auto",
|
36 |
output_folder: str = "outputs",
|
@@ -44,18 +45,16 @@ def animate(
|
|
44 |
frames = animate_on_gpu(
|
45 |
image,
|
46 |
seed,
|
47 |
-
randomize_seed,
|
48 |
motion_bucket_id,
|
49 |
fps_id,
|
50 |
noise_aug_strength,
|
51 |
decoding_t,
|
52 |
-
frame_format,
|
53 |
version
|
54 |
)
|
55 |
|
56 |
os.makedirs(output_folder, exist_ok=True)
|
57 |
-
base_count = len(glob(os.path.join(output_folder, "*.
|
58 |
-
video_path = os.path.join(output_folder, f"{base_count:06d}.
|
59 |
|
60 |
export_to_video(frames, video_path, fps=fps_id)
|
61 |
|
@@ -65,12 +64,10 @@ def animate(
|
|
65 |
def animate_on_gpu(
|
66 |
image: Image,
|
67 |
seed: Optional[int] = 42,
|
68 |
-
randomize_seed: bool = True,
|
69 |
motion_bucket_id: int = 127,
|
70 |
fps_id: int = 6,
|
71 |
noise_aug_strength: float = 0.1,
|
72 |
decoding_t: int = 3,
|
73 |
-
frame_format: str = "webp",
|
74 |
version: str = "auto"
|
75 |
):
|
76 |
generator = torch.manual_seed(seed)
|
@@ -128,7 +125,8 @@ with gr.Blocks() as demo:
|
|
128 |
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)
|
129 |
noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
|
130 |
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)
|
131 |
-
|
|
|
132 |
version = gr.Radio([["Auto", "auto"], ["ππ»ββοΈ SVD (trained on 14 f/s)", "svd"], ["ππ»ββοΈπ¨ SVD-XT (trained on 25 f/s)", "svdxt"]], label="Model", info="Trained model", value="auto", interactive=True)
|
133 |
seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
|
134 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
@@ -141,15 +139,15 @@ with gr.Blocks() as demo:
|
|
141 |
gallery = gr.Gallery(label="Generated frames", visible=False)
|
142 |
|
143 |
image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
|
144 |
-
generate_btn.click(fn=animate, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version], outputs=[video, download_button, gallery, seed], api_name="video")
|
145 |
|
146 |
gr.Examples(
|
147 |
examples=[
|
148 |
-
["Examples/Fire.webp", 42, True, 127, 25, 0.1, 3, "png", "auto"],
|
149 |
-
["Examples/Water.png", 42, True, 127, 25, 0.1, 3, "png", "auto"],
|
150 |
-
["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "png", "auto"]
|
151 |
],
|
152 |
-
inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version],
|
153 |
outputs=[video, download_button, gallery, seed],
|
154 |
fn=animate,
|
155 |
run_on_click=True,
|
|
|
31 |
fps_id: int = 6,
|
32 |
noise_aug_strength: float = 0.1,
|
33 |
decoding_t: int = 3,
|
34 |
+
video_format: str = "mp4",
|
35 |
frame_format: str = "webp",
|
36 |
version: str = "auto",
|
37 |
output_folder: str = "outputs",
|
|
|
45 |
frames = animate_on_gpu(
|
46 |
image,
|
47 |
seed,
|
|
|
48 |
motion_bucket_id,
|
49 |
fps_id,
|
50 |
noise_aug_strength,
|
51 |
decoding_t,
|
|
|
52 |
version
|
53 |
)
|
54 |
|
55 |
os.makedirs(output_folder, exist_ok=True)
|
56 |
+
base_count = len(glob(os.path.join(output_folder, "*." + video_format)))
|
57 |
+
video_path = os.path.join(output_folder, f"{base_count:06d}." + video_format)
|
58 |
|
59 |
export_to_video(frames, video_path, fps=fps_id)
|
60 |
|
|
|
64 |
def animate_on_gpu(
|
65 |
image: Image,
|
66 |
seed: Optional[int] = 42,
|
|
|
67 |
motion_bucket_id: int = 127,
|
68 |
fps_id: int = 6,
|
69 |
noise_aug_strength: float = 0.1,
|
70 |
decoding_t: int = 3,
|
|
|
71 |
version: str = "auto"
|
72 |
):
|
73 |
generator = torch.manual_seed(seed)
|
|
|
125 |
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)
|
126 |
noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
|
127 |
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)
|
128 |
+
video_format = gr.Radio([["*.mp4", "mp4"], ["*.avi", "avi"]], label="Video format for result", info="File extention", value="mp4", interactive=True)
|
129 |
+
frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for frames", info="File extention", value="webp", interactive=True)
|
130 |
version = gr.Radio([["Auto", "auto"], ["ππ»ββοΈ SVD (trained on 14 f/s)", "svd"], ["ππ»ββοΈπ¨ SVD-XT (trained on 25 f/s)", "svdxt"]], label="Model", info="Trained model", value="auto", interactive=True)
|
131 |
seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
|
132 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
|
|
139 |
gallery = gr.Gallery(label="Generated frames", visible=False)
|
140 |
|
141 |
image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
|
142 |
+
generate_btn.click(fn=animate, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, video_format, frame_format, version], outputs=[video, download_button, gallery, seed], api_name="video")
|
143 |
|
144 |
gr.Examples(
|
145 |
examples=[
|
146 |
+
["Examples/Fire.webp", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"],
|
147 |
+
["Examples/Water.png", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"],
|
148 |
+
["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"]
|
149 |
],
|
150 |
+
inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, video_format, frame_format, version],
|
151 |
outputs=[video, download_button, gallery, seed],
|
152 |
fn=animate,
|
153 |
run_on_click=True,
|