alex commited on
Commit
0e77c48
Β·
1 Parent(s): d90466c

more duration fixes

Browse files
Files changed (1) hide show
  1. app.py +40 -47
app.py CHANGED
@@ -202,43 +202,33 @@ def is_portrait(video_file):
202
 
203
  def calculate_time_required(max_duration_s, rc_bool):
204
 
205
- frames_count = 30 * max_duration_s
206
-
207
- chunks = frames_count // 77 + 1
208
-
209
-
210
- if rc_bool:
211
- pose2d_tracking_duration_s = 75
212
- iteration_per_step_s = 12
213
- else:
214
- pose2d_tracking_duration_s = 65
215
- iteration_per_step_s = 12
216
-
217
- time_required = pose2d_tracking_duration_s + iteration_per_step_s * 5 * chunks
218
- print(f'for frames_count:{frames_count} doing {chunks} chunks the time_required is {time_required}')
219
- return time_required
220
 
221
  def update_time_required(max_duration_s, rc_str):
222
 
223
  rc_bool = rc_mapping[rc_str]
224
 
225
- duration_s = calculate_time_required(max_duration_s, rc_bool)
226
  duration_m = duration_s / 60
227
 
228
  return gr.update(value=f"⌚ Zero GPU Required: ~{duration_s}.0s ({duration_m:.1f} mins)")
229
 
230
- def log_slider_change():
231
- print("slider value changed")
232
 
233
  def get_duration(input_video, max_duration_s, edited_frame, rc_bool, session_id, progress):
234
- if max_duration_s == 2:
235
- return 120
236
- elif max_duration_s == 4:
237
- return 180
238
- elif max_duration_s == 6:
239
- return 240
240
- elif max_duration_s == 8:
241
- return 300
242
 
243
  @spaces.GPU(duration=get_duration)
244
  def _animate(input_video, max_duration_s, edited_frame, rc_bool, session_id = None, progress=gr.Progress(track_tqdm=True),):
@@ -269,14 +259,6 @@ def _animate(input_video, max_duration_s, edited_frame, rc_bool, session_id = No
269
  if rc_bool:
270
  tag_string = "replace_flag"
271
 
272
- # sh("python ./wan/modules/animate/preprocess/preprocess_data.py "
273
- # "--ckpt_path ./Wan2.2-Animate-14B/process_checkpoint "
274
- # f"--video_path {input_video} "
275
- # f"--refer_path {edited_frame} "
276
- # f"--save_path {preprocess_dir} "
277
- # f"--resolution_area {w} {h} --{tag_string} "
278
- # )
279
-
280
  preprocess_model = load_preprocess_models()
281
 
282
  run_preprocess(preprocess_model, input_video, edited_frame, preprocess_dir, w, h, tag_string)
@@ -302,12 +284,6 @@ def _animate(input_video, max_duration_s, edited_frame, rc_bool, session_id = No
302
 
303
  return output_video_path
304
 
305
- def animate_example(input_video, max_duration_s, edited_frame, rc_str, session_id = None, progress=gr.Progress(track_tqdm=True),):
306
-
307
- print("Example used")
308
-
309
- return animate_scene(input_video, max_duration_s, edited_frame, rc_str, session_id, progress)
310
-
311
  def animate_scene(input_video, max_duration_s, edited_frame, rc_str, session_id = None, progress=gr.Progress(track_tqdm=True),):
312
 
313
  if not input_video:
@@ -449,6 +425,14 @@ css = """
449
  transform: translateX(100%);
450
  }
451
  """
 
 
 
 
 
 
 
 
452
  def start_session(request: gr.Request):
453
 
454
  return request.session_hash
@@ -495,7 +479,7 @@ with gr.Blocks(css=css, title="Wan 2.2 Animate --replace", theme=gr.themes.Ocean
495
  </div>
496
  """)
497
  input_video = gr.Video(label="Input Video", height=512)
498
- max_duration_slider = gr.Slider(2, 4, 2, step=2, label="Max Duration", visible=False)
499
 
500
  gr.Examples(
501
  examples=[
@@ -521,8 +505,10 @@ with gr.Blocks(css=css, title="Wan 2.2 Animate --replace", theme=gr.themes.Ocean
521
  </div>
522
  """)
523
  edited_frame = gr.Image(label="Ref Image", type="filepath", height=512)
 
 
524
  replace_character_string = gr.Radio(
525
- ["Video β†’ Ref Image", "Video ← Ref Image"], value="Video ← Ref Image", show_label=False
526
  )
527
 
528
 
@@ -558,7 +544,12 @@ with gr.Blocks(css=css, title="Wan 2.2 Animate --replace", theme=gr.themes.Ocean
558
  """)
559
  output_video = gr.Video(label="Edited Video", height=512)
560
 
561
- time_required = gr.Text(value="⌚ Zero GPU Required: ~195.0s (3.2 mins)", show_label=False, visible=False)
 
 
 
 
 
562
  action_button = gr.Button("Wan Animate πŸ¦†", variant='primary', elem_classes="button-gradient")
563
 
564
  with gr.Accordion("Preprocessed Data", open=False, visible=True):
@@ -574,7 +565,6 @@ with gr.Blocks(css=css, title="Wan 2.2 Animate --replace", theme=gr.themes.Ocean
574
  gr.Examples(
575
  examples=[
576
 
577
-
578
  [
579
  "./examples/okay.mp4",
580
  2,
@@ -613,14 +603,17 @@ with gr.Blocks(css=css, title="Wan 2.2 Animate --replace", theme=gr.themes.Ocean
613
  ],
614
  inputs=[input_video, max_duration_slider, edited_frame, replace_character_string],
615
  outputs=[output_video, pose_video, bg_video, mask_video, face_video],
616
- fn=animate_example,
617
  cache_examples=True,
618
  )
619
 
620
  action_button.click(fn=animate_scene, inputs=[input_video, max_duration_slider, edited_frame, replace_character_string, session_state], outputs=[output_video, pose_video, bg_video, mask_video, face_video])
621
- max_duration_slider.change(log_slider_change)
622
  replace_character_string.change(update_time_required, inputs=[max_duration_slider, replace_character_string], outputs=[time_required])
623
-
 
 
 
 
624
  if __name__ == "__main__":
625
  demo.queue()
626
  demo.unload(cleanup)
 
202
 
203
  def calculate_time_required(max_duration_s, rc_bool):
204
 
205
+ if max_duration_s == 2:
206
+ return 120
207
+ elif max_duration_s == 4:
208
+ return 180
209
+ elif max_duration_s == 6:
210
+ return 260
211
+ elif max_duration_s == 8:
212
+ return 330
213
+ elif max_duration_s == 10:
214
+ return 340
215
+
216
+ def get_display_time_required(max_duration_s, rc_bool):
217
+ # the 30 seconds extra is just for saftey in case of a unexpected slow down
218
+ return calculate_time_required(max_duration_s, rc_bool) - 30
 
219
 
220
  def update_time_required(max_duration_s, rc_str):
221
 
222
  rc_bool = rc_mapping[rc_str]
223
 
224
+ duration_s = get_display_time_required(max_duration_s, rc_bool)
225
  duration_m = duration_s / 60
226
 
227
  return gr.update(value=f"⌚ Zero GPU Required: ~{duration_s}.0s ({duration_m:.1f} mins)")
228
 
 
 
229
 
230
  def get_duration(input_video, max_duration_s, edited_frame, rc_bool, session_id, progress):
231
+ return calculate_time_required(max_duration_s, rc_bool)
 
 
 
 
 
 
 
232
 
233
  @spaces.GPU(duration=get_duration)
234
  def _animate(input_video, max_duration_s, edited_frame, rc_bool, session_id = None, progress=gr.Progress(track_tqdm=True),):
 
259
  if rc_bool:
260
  tag_string = "replace_flag"
261
 
 
 
 
 
 
 
 
 
262
  preprocess_model = load_preprocess_models()
263
 
264
  run_preprocess(preprocess_model, input_video, edited_frame, preprocess_dir, w, h, tag_string)
 
284
 
285
  return output_video_path
286
 
 
 
 
 
 
 
287
  def animate_scene(input_video, max_duration_s, edited_frame, rc_str, session_id = None, progress=gr.Progress(track_tqdm=True),):
288
 
289
  if not input_video:
 
425
  transform: translateX(100%);
426
  }
427
  """
428
+
429
+ def log_change(log_source, session_id, meta_data = None):
430
+
431
+ if not meta_data:
432
+ print(f'{session_id} changed {log_source}')
433
+ else:
434
+ print(f'{session_id} changed {log_source} with {meta_data}')
435
+
436
  def start_session(request: gr.Request):
437
 
438
  return request.session_hash
 
479
  </div>
480
  """)
481
  input_video = gr.Video(label="Input Video", height=512)
482
+ max_duration_slider = gr.Slider(2, 10, 2, step=2, label="Max Duration", visible=False)
483
 
484
  gr.Examples(
485
  examples=[
 
505
  </div>
506
  """)
507
  edited_frame = gr.Image(label="Ref Image", type="filepath", height=512)
508
+
509
+ default_replace_string = "Video ← Ref Image"
510
  replace_character_string = gr.Radio(
511
+ ["Video β†’ Ref Image", "Video ← Ref Image"], value=default_replace_string, show_label=False
512
  )
513
 
514
 
 
544
  """)
545
  output_video = gr.Video(label="Edited Video", height=512)
546
 
547
+ duration_s = get_display_time_required(2, default_replace_string)
548
+ duration_m = duration_s / 60
549
+
550
+ time_required = f"⌚ Zero GPU Required: ~{duration_s}.0s ({duration_m:.1f} mins)"
551
+
552
+ time_required = gr.Text(value=time_required, show_label=False, visible=False)
553
  action_button = gr.Button("Wan Animate πŸ¦†", variant='primary', elem_classes="button-gradient")
554
 
555
  with gr.Accordion("Preprocessed Data", open=False, visible=True):
 
565
  gr.Examples(
566
  examples=[
567
 
 
568
  [
569
  "./examples/okay.mp4",
570
  2,
 
603
  ],
604
  inputs=[input_video, max_duration_slider, edited_frame, replace_character_string],
605
  outputs=[output_video, pose_video, bg_video, mask_video, face_video],
606
+ fn=animate_scene,
607
  cache_examples=True,
608
  )
609
 
610
  action_button.click(fn=animate_scene, inputs=[input_video, max_duration_slider, edited_frame, replace_character_string, session_state], outputs=[output_video, pose_video, bg_video, mask_video, face_video])
 
611
  replace_character_string.change(update_time_required, inputs=[max_duration_slider, replace_character_string], outputs=[time_required])
612
+
613
+ max_duration_slider.change(log_change, inputs=[gr.State("slider"), session_state, max_duration_slider]).then(update_time_required, inputs=[max_duration_slider, replace_character_string], outputs=[time_required])
614
+ input_video.change(log_change, inputs=[gr.State("video"), session_state])
615
+ edited_frame.change(log_change, inputs=[gr.State("ref image"), session_state])
616
+
617
  if __name__ == "__main__":
618
  demo.queue()
619
  demo.unload(cleanup)