maxin-cn Fabrice-TIERCELIN commited on
Commit
aca8023
·
1 Parent(s): c0c8920

This PR allows the user to automatically randomize the seed (#5)

Browse files

- This PR allows the user to automatically randomize the seed (2291aa5afa93f97eb7c8938eeec3b110034cec00)


Co-authored-by: Fabrice TIERCELIN <Fabrice-TIERCELIN@users.noreply.huggingface.co>

Files changed (1) hide show
  1. demo.py +15 -11
demo.py CHANGED
@@ -146,8 +146,10 @@ def prepare_image(image, vae, transform_video, device, dtype=torch.float16):
146
 
147
 
148
  @spaces.GPU
149
- def gen_video(input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed):
150
 
 
 
151
  torch.manual_seed(seed)
152
 
153
  scheduler = DDIMScheduler.from_pretrained(args.pretrained_model_path,
@@ -262,6 +264,7 @@ with gr.Blocks() as demo:
262
  sample_step_slider = gr.Slider(label="Sampling steps", value=50, minimum=10, maximum=250, step=1)
263
 
264
  with gr.Row():
 
265
  seed_textbox = gr.Slider(label="Seed", value=100, minimum=1, maximum=int(1e8), step=1, interactive=True)
266
  # seed_textbox = gr.Textbox(label="Seed", value=100)
267
  # seed_button = gr.Button(value="\U0001F3B2", elem_classes="toolbutton")
@@ -284,22 +287,22 @@ with gr.Blocks() as demo:
284
  input_image_path.submit(fn=update_and_resize_image, inputs=[input_image_path, height, width], outputs=[input_image])
285
 
286
  EXAMPLES = [
287
- ["./example/red_panda_eating_bamboo/0.jpg", "red panda eating bamboo" , "low quality", 50, 320, 512, 7.5, True, 0.23, 975, 10, 100],
288
- ["./example/fireworks/0.jpg", "fireworks" , "low quality", 50, 320, 512, 7.5, True, 0.23, 975, 10, 100],
289
- ["./example/flowers_swaying/0.jpg", "flowers swaying" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, 100],
290
- ["./example/girl_walking_on_the_beach/0.jpg", "girl walking on the beach" , "low quality, background changing", 50, 320, 512, 7.5, True, 0.25, 995, 10, 49494220],
291
- ["./example/house_rotating/0.jpg", "house rotating" , "low quality", 50, 320, 512, 7.5, True, 0.23, 985, 10, 46640174],
292
- ["./example/people_runing/0.jpg", "people runing" , "low quality, background changing", 50, 320, 512, 7.5, True, 0.23, 975, 10, 100],
293
- ["./example/shark_swimming/0.jpg", "shark swimming" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, 32947978],
294
- ["./example/car_moving/0.jpg", "car moving" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, 75469653],
295
- ["./example/windmill_turning/0.jpg", "windmill turning" , "background changing", 50, 320, 512, 7.5, True, 0.21, 975, 10, 89378613],
296
  ]
297
 
298
 
299
  examples = gr.Examples(
300
  examples = EXAMPLES,
301
  fn = gen_video,
302
- inputs=[input_image, prompt_textbox, negative_prompt_textbox, sample_step_slider, height, width, txt_cfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, seed_textbox],
303
  outputs=[result_video],
304
  cache_examples=True,
305
  # cache_examples="lazy",
@@ -319,6 +322,7 @@ with gr.Blocks() as demo:
319
  dct_coefficients,
320
  noise_level,
321
  motion_bucket_id,
 
322
  seed_textbox,
323
  ],
324
  outputs=[result_video]
 
146
 
147
 
148
  @spaces.GPU
149
+ def gen_video(input_image, prompt, negative_prompt, diffusion_step, height, width, scfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, randomize_seed, seed):
150
 
151
+ if randomize_seed:
152
+ seed = random.randint(1, int(1e8))
153
  torch.manual_seed(seed)
154
 
155
  scheduler = DDIMScheduler.from_pretrained(args.pretrained_model_path,
 
264
  sample_step_slider = gr.Slider(label="Sampling steps", value=50, minimum=10, maximum=250, step=1)
265
 
266
  with gr.Row():
267
+ randomize_seed_checkbox = gr.Checkbox(label = "Randomize seed", value = True, info = "If checked, result is always different")
268
  seed_textbox = gr.Slider(label="Seed", value=100, minimum=1, maximum=int(1e8), step=1, interactive=True)
269
  # seed_textbox = gr.Textbox(label="Seed", value=100)
270
  # seed_button = gr.Button(value="\U0001F3B2", elem_classes="toolbutton")
 
287
  input_image_path.submit(fn=update_and_resize_image, inputs=[input_image_path, height, width], outputs=[input_image])
288
 
289
  EXAMPLES = [
290
+ ["./example/red_panda_eating_bamboo/0.jpg", "red panda eating bamboo" , "low quality", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 100],
291
+ ["./example/fireworks/0.jpg", "fireworks" , "low quality", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 100],
292
+ ["./example/flowers_swaying/0.jpg", "flowers swaying" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 100],
293
+ ["./example/girl_walking_on_the_beach/0.jpg", "girl walking on the beach" , "low quality, background changing", 50, 320, 512, 7.5, True, 0.25, 995, 10, False, 49494220],
294
+ ["./example/house_rotating/0.jpg", "house rotating" , "low quality", 50, 320, 512, 7.5, True, 0.23, 985, 10, False, 46640174],
295
+ ["./example/people_runing/0.jpg", "people runing" , "low quality, background changing", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 100],
296
+ ["./example/shark_swimming/0.jpg", "shark swimming" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 32947978],
297
+ ["./example/car_moving/0.jpg", "car moving" , "", 50, 320, 512, 7.5, True, 0.23, 975, 10, False, 75469653],
298
+ ["./example/windmill_turning/0.jpg", "windmill turning" , "background changing", 50, 320, 512, 7.5, True, 0.21, 975, 10, False, 89378613],
299
  ]
300
 
301
 
302
  examples = gr.Examples(
303
  examples = EXAMPLES,
304
  fn = gen_video,
305
+ inputs=[input_image, prompt_textbox, negative_prompt_textbox, sample_step_slider, height, width, txt_cfg_scale, use_dctinit, dct_coefficients, noise_level, motion_bucket_id, randomize_seed_checkbox, seed_textbox],
306
  outputs=[result_video],
307
  cache_examples=True,
308
  # cache_examples="lazy",
 
322
  dct_coefficients,
323
  noise_level,
324
  motion_bucket_id,
325
+ randomize_seed_checkbox,
326
  seed_textbox,
327
  ],
328
  outputs=[result_video]