Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
cbd363e
1
Parent(s):
6bc4f7f
Add information and fix video format (#22)
Browse files- Add information and fix video format (7e266454113338159a0424722f876bd76384e002)
Co-authored-by: Fabrice TIERCELIN <Fabrice-TIERCELIN@users.noreply.huggingface.co>
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
import os
|
4 |
import random
|
|
|
|
|
5 |
import spaces
|
6 |
from glob import glob
|
7 |
from pathlib import Path
|
@@ -36,6 +38,7 @@ def animate(
|
|
36 |
version: str = "auto",
|
37 |
output_folder: str = "outputs",
|
38 |
):
|
|
|
39 |
if image.mode == "RGBA":
|
40 |
image = image.convert("RGB")
|
41 |
|
@@ -57,8 +60,20 @@ def animate(
|
|
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 |
|
61 |
-
return video_path, gr.update(value=video_path, visible=True), gr.update(label="Generated frames in *." + frame_format + " format", format = frame_format, value = frames, visible=True), seed
|
62 |
|
63 |
@spaces.GPU(duration=120)
|
64 |
def animate_on_gpu(
|
@@ -136,10 +151,11 @@ with gr.Blocks() as demo:
|
|
136 |
with gr.Column():
|
137 |
video = gr.Video(label="Generated video", autoplay=True)
|
138 |
download_button = gr.DownloadButton(label="💾 Download video", visible=False)
|
|
|
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=[
|
@@ -148,7 +164,7 @@ with gr.Blocks() as demo:
|
|
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,
|
154 |
cache_examples=False,
|
|
|
2 |
import torch
|
3 |
import os
|
4 |
import random
|
5 |
+
import time
|
6 |
+
import math
|
7 |
import spaces
|
8 |
from glob import glob
|
9 |
from pathlib import Path
|
|
|
38 |
version: str = "auto",
|
39 |
output_folder: str = "outputs",
|
40 |
):
|
41 |
+
start = time.time()
|
42 |
if image.mode == "RGBA":
|
43 |
image = image.convert("RGB")
|
44 |
|
|
|
60 |
video_path = os.path.join(output_folder, f"{base_count:06d}." + video_format)
|
61 |
|
62 |
export_to_video(frames, video_path, fps=fps_id)
|
63 |
+
end = time.time()
|
64 |
+
secondes = int(end - start)
|
65 |
+
minutes = math.floor(secondes / 60)
|
66 |
+
secondes = secondes - (minutes * 60)
|
67 |
+
hours = math.floor(minutes / 60)
|
68 |
+
minutes = minutes - (hours * 60)
|
69 |
+
information = ("Start the process again if you want a different result. " if randomize_seed else "") + \
|
70 |
+
"Wait 2 min before a new run to avoid quota penalty or use another computer. " + \
|
71 |
+
"The video has been generated in " + \
|
72 |
+
((str(hours) + " h, ") if hours != 0 else "") + \
|
73 |
+
((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
|
74 |
+
str(secondes) + " sec."
|
75 |
|
76 |
+
return gr.update(value=video_path, format=video_format), gr.update(value=video_path, visible=True), gr.update(label="Generated frames in *." + frame_format + " format", format = frame_format, value = frames, visible=True), seed, gr.update(value = information, visible = True)
|
77 |
|
78 |
@spaces.GPU(duration=120)
|
79 |
def animate_on_gpu(
|
|
|
151 |
with gr.Column():
|
152 |
video = gr.Video(label="Generated video", autoplay=True)
|
153 |
download_button = gr.DownloadButton(label="💾 Download video", visible=False)
|
154 |
+
information_msg = gr.HTML(visible = False)
|
155 |
gallery = gr.Gallery(label="Generated frames", visible=False)
|
156 |
|
157 |
image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
|
158 |
+
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, information_msg], api_name="video")
|
159 |
|
160 |
gr.Examples(
|
161 |
examples=[
|
|
|
164 |
["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"]
|
165 |
],
|
166 |
inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, video_format, frame_format, version],
|
167 |
+
outputs=[video, download_button, gallery, seed, information_msg],
|
168 |
fn=animate,
|
169 |
run_on_click=True,
|
170 |
cache_examples=False,
|