Fabrice-TIERCELIN commited on
Commit
edba305
β€’
1 Parent(s): 6cbfe79

Reset button

Browse files
Files changed (1) hide show
  1. app.py +51 -5
app.py CHANGED
@@ -79,7 +79,7 @@ def animate(
79
  ((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
80
  str(secondes) + " sec."
81
 
82
- 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)
83
 
84
  @spaces.GPU(duration=120)
85
  def animate_on_gpu(
@@ -134,6 +134,20 @@ def resize_image(image, output_size=(1024, 576)):
134
  cropped_image = resized_image.crop((left, top, right, bottom))
135
  return cropped_image
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  with gr.Blocks() as demo:
138
  gr.HTML("""
139
  <h1><center>Image-to-Video</center></h1>
@@ -153,13 +167,14 @@ with gr.Blocks() as demo:
153
  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)
154
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
155
  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)
156
- video_format = gr.Radio([["*.mp4", "mp4"], ["*.ogg", "ogg"], ["*.webm", "webm"]], label="Video format for result", info="File extention", value="mp4", interactive=True)
157
- frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif (unanimated)", "gif"], ["*.bmp", "bmp"]], label="Image format for frames", info="File extention", value="webp", interactive=True)
158
  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)
159
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
160
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
161
 
162
  generate_btn = gr.Button(value="πŸš€ Animate", variant="primary")
 
163
 
164
  with gr.Column():
165
  video = gr.Video(label="Generated video", autoplay=True)
@@ -168,7 +183,38 @@ with gr.Blocks() as demo:
168
  gallery = gr.Gallery(label="Generated frames", visible=False)
169
 
170
  image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
171
- 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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  gr.Examples(
174
  examples=[
@@ -177,7 +223,7 @@ with gr.Blocks() as demo:
177
  ["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"]
178
  ],
179
  inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, video_format, frame_format, version],
180
- outputs=[video, download_button, gallery, seed, information_msg],
181
  fn=animate,
182
  run_on_click=True,
183
  cache_examples=False,
 
79
  ((str(minutes) + " min, ") if hours != 0 or minutes != 0 else "") + \
80
  str(secondes) + " sec."
81
 
82
+ 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), gr.update(visible=True)
83
 
84
  @spaces.GPU(duration=120)
85
  def animate_on_gpu(
 
134
  cropped_image = resized_image.crop((left, top, right, bottom))
135
  return cropped_image
136
 
137
+ def reset():
138
+ return [
139
+ None,
140
+ random.randint(0, max_64_bit_int),
141
+ True,
142
+ 127,
143
+ 6,
144
+ 0.1,
145
+ 3,
146
+ "mp4",
147
+ "webp",
148
+ "auto"
149
+ ]
150
+
151
  with gr.Blocks() as demo:
152
  gr.HTML("""
153
  <h1><center>Image-to-Video</center></h1>
 
167
  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)
168
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
169
  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)
170
+ video_format = gr.Radio([["*.mp4", "mp4"]], label="Video format for result", info="File extention", value="mp4", interactive=True)
171
+ frame_format = gr.Radio([["*.webp", "webp"], ["*.png", "png"], ["*.jpeg", "jpeg"], ["*.gif (unanimated)", "gif"], ["*.bmp", "bmp"]], label="Image format for frames", info="File extention", value="webp", interactive=True)
172
  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)
173
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
174
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
175
 
176
  generate_btn = gr.Button(value="πŸš€ Animate", variant="primary")
177
+ reset_btn = gr.Button(value="🧹 Reinit page", variant="stop", elem_id="reset_button", visible = False)
178
 
179
  with gr.Column():
180
  video = gr.Video(label="Generated video", autoplay=True)
 
183
  gallery = gr.Gallery(label="Generated frames", visible=False)
184
 
185
  image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
186
+ generate_btn.click(fn=animate, inputs=[
187
+ image,
188
+ seed,
189
+ randomize_seed,
190
+ motion_bucket_id,
191
+ fps_id,
192
+ noise_aug_strength,
193
+ decoding_t,
194
+ video_format,
195
+ frame_format,
196
+ version
197
+ ], outputs=[
198
+ video,
199
+ download_button,
200
+ gallery,
201
+ seed,
202
+ information_msg,
203
+ reset_btn
204
+ ], api_name="video")
205
+
206
+ reset_btn.click(fn = reset, inputs = [], outputs = [
207
+ image,
208
+ seed,
209
+ randomize_seed,
210
+ motion_bucket_id,
211
+ fps_id,
212
+ noise_aug_strength,
213
+ decoding_t,
214
+ video_format,
215
+ frame_format,
216
+ version
217
+ ], queue = False, show_progress = False)
218
 
219
  gr.Examples(
220
  examples=[
 
223
  ["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "mp4", "png", "auto"]
224
  ],
225
  inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, video_format, frame_format, version],
226
+ outputs=[video, download_button, gallery, seed, information_msg, reset_btn],
227
  fn=animate,
228
  run_on_click=True,
229
  cache_examples=False,