C4G-HKUST commited on
Commit
12835e4
·
1 Parent(s): b87c83f

feat: time out check

Browse files
Files changed (2) hide show
  1. app.py +12 -15
  2. wan/utils/infer_utils.py +6 -10
app.py CHANGED
@@ -485,9 +485,8 @@ def run_graio_demo(args):
485
 
486
  # Fast模式:如果trim_to_6s为True,强制限制为6秒对应的帧数
487
  if trim_to_6s:
488
- # 计算6秒对应的帧数(4n+1格式)
489
- max_frames_6s = int(math.ceil(6.0 * fps))
490
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
491
  current_frame_num = min(calculated_frame_num, max_frames_6s)
492
  logging.warning(f"Fast mode: Audio duration exceeds 6 seconds. Trimming to 6 seconds ({max_frames_6s} frames). Original: {calculated_frame_num} frames")
493
  else:
@@ -618,8 +617,8 @@ def run_graio_demo(args):
618
  # 参考: https://huggingface.co/spaces/KlingTeam/LivePortrait/blob/main/app.py
619
  # @spaces.GPU 装饰器会自动处理 GPU 初始化,不需要手动初始化
620
 
621
- # 快速生成模式:100秒,固定10步去噪
622
- @spaces.GPU(duration=100)
623
  def gpu_wrapped_generate_video_fast(*args, **kwargs):
624
  # 固定使用10步去噪,通过关键字参数传递
625
  kwargs['fixed_steps'] = 8
@@ -663,9 +662,8 @@ def run_graio_demo(args):
663
  fps = getattr(cfg, 'fps', 24)
664
  try:
665
  calculated_frame_num = calculate_frame_num_from_audio(audio_paths, fps, mode=audio_mode_selector)
666
- # 计算6秒对应的帧数
667
- max_frames_6s = int(math.ceil(6.0 * fps))
668
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
669
 
670
  if calculated_frame_num > max_frames_6s:
671
  # 超过6秒,设置trim_to_6s标记
@@ -837,7 +835,7 @@ def run_graio_demo(args):
837
 
838
  with gr.Row():
839
  run_i2v_button_fast = gr.Button(
840
- "Generate Video (Fast - 100s, 8 steps)",
841
  variant="secondary",
842
  scale=1
843
  )
@@ -848,10 +846,10 @@ def run_graio_demo(args):
848
  )
849
  gr.Markdown("""
850
  **Generation Modes:**
851
- - **Fast Mode (up to 100s GPU budget)**: Fixed 8 denoising steps for quick generation.
852
  - **Quality Mode (up to 720s GPU budget)**: Custom denoising steps (adjustable via "Diffusion steps" slider, default: 25 steps).
853
 
854
- *Note: The GPU duration (100s/720s) represents the maximum budget allocated, not the actual generation time. Multi-person videos generally require longer duration and more Usage Quota for better quality.*
855
  """)
856
 
857
  with gr.Column(scale=2):
@@ -913,9 +911,8 @@ def run_graio_demo(args):
913
  fps = getattr(cfg, 'fps', 24)
914
  try:
915
  calculated_frame_num = calculate_frame_num_from_audio(audio_paths, fps, mode=audio_mode_selector)
916
- # 计算6秒对应的帧数
917
- max_frames_6s = int(math.ceil(6.0 * fps))
918
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
919
 
920
  if calculated_frame_num > max_frames_6s:
921
  # 超过6秒,立即显示警告
@@ -936,7 +933,7 @@ def run_graio_demo(args):
936
  result = gpu_wrapped_generate_video_quality(*args)
937
  return result
938
 
939
- # 快速生成按钮:100秒,固定10步
940
  run_i2v_button_fast.click(
941
  fn=handle_fast_generation,
942
  inputs=[img2vid_image, img2vid_prompt, n_prompt, img2vid_audio_1, img2vid_audio_2, img2vid_audio_3, sd_steps, seed, guide_scale, person_num_selector, audio_mode_selector],
 
485
 
486
  # Fast模式:如果trim_to_6s为True,强制限制为6秒对应的帧数
487
  if trim_to_6s:
488
+ # 6秒固定为145帧(4n+1格式)
489
+ max_frames_6s = 145
 
490
  current_frame_num = min(calculated_frame_num, max_frames_6s)
491
  logging.warning(f"Fast mode: Audio duration exceeds 6 seconds. Trimming to 6 seconds ({max_frames_6s} frames). Original: {calculated_frame_num} frames")
492
  else:
 
617
  # 参考: https://huggingface.co/spaces/KlingTeam/LivePortrait/blob/main/app.py
618
  # @spaces.GPU 装饰器会自动处理 GPU 初始化,不需要手动初始化
619
 
620
+ # 快速生成模式:200秒,固定10步去噪
621
+ @spaces.GPU(duration=200)
622
  def gpu_wrapped_generate_video_fast(*args, **kwargs):
623
  # 固定使用10步去噪,通过关键字参数传递
624
  kwargs['fixed_steps'] = 8
 
662
  fps = getattr(cfg, 'fps', 24)
663
  try:
664
  calculated_frame_num = calculate_frame_num_from_audio(audio_paths, fps, mode=audio_mode_selector)
665
+ # 6秒固定为145帧
666
+ max_frames_6s = 145
 
667
 
668
  if calculated_frame_num > max_frames_6s:
669
  # 超过6秒,设置trim_to_6s标记
 
835
 
836
  with gr.Row():
837
  run_i2v_button_fast = gr.Button(
838
+ "Generate Video (Fast - 200s, 8 steps)",
839
  variant="secondary",
840
  scale=1
841
  )
 
846
  )
847
  gr.Markdown("""
848
  **Generation Modes:**
849
+ - **Fast Mode (up to 200s GPU budget)**: Fixed 8 denoising steps for quick generation.
850
  - **Quality Mode (up to 720s GPU budget)**: Custom denoising steps (adjustable via "Diffusion steps" slider, default: 25 steps).
851
 
852
+ *Note: The GPU duration (200s/720s) represents the maximum budget allocated, not the actual generation time. Multi-person videos generally require longer duration and more Usage Quota for better quality.*
853
  """)
854
 
855
  with gr.Column(scale=2):
 
911
  fps = getattr(cfg, 'fps', 24)
912
  try:
913
  calculated_frame_num = calculate_frame_num_from_audio(audio_paths, fps, mode=audio_mode_selector)
914
+ # 6秒固定为145帧
915
+ max_frames_6s = 145
 
916
 
917
  if calculated_frame_num > max_frames_6s:
918
  # 超过6秒,立即显示警告
 
933
  result = gpu_wrapped_generate_video_quality(*args)
934
  return result
935
 
936
+ # 快速生成按钮:200秒,固定10步
937
  run_i2v_button_fast.click(
938
  fn=handle_fast_generation,
939
  inputs=[img2vid_image, img2vid_prompt, n_prompt, img2vid_audio_1, img2vid_audio_2, img2vid_audio_3, sd_steps, seed, guide_scale, person_num_selector, audio_mode_selector],
wan/utils/infer_utils.py CHANGED
@@ -205,10 +205,8 @@ def process_audio_features(
205
 
206
  # Fast mode: trim to 6 seconds if trim_to_6s is True
207
  if trim_to_6s:
208
- import math
209
- # Calculate 6 seconds in frames
210
- max_frames_6s = int(math.ceil(6.0 * fps))
211
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
212
  if total_length > max_frames_6s:
213
  print(f"Fast mode: Trimming audio from {total_length} frames to {max_frames_6s} frames (6 seconds)")
214
  # Truncate each audio proportionally
@@ -299,9 +297,8 @@ def process_audio_features(
299
  # Fast mode: if trim_to_6s, limit to 6 seconds
300
  target_frames = F
301
  if trim_to_6s:
302
- import math
303
- max_frames_6s = int(math.ceil(6.0 * fps))
304
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
305
  target_frames = min(F, max_frames_6s)
306
  if F > max_frames_6s:
307
  print(f"Fast mode: Trimming audio {i} from {F} frames to {max_frames_6s} frames (6 seconds)")
@@ -349,9 +346,8 @@ def process_audio_features(
349
  # Fast mode: if trim_to_6s, limit to 6 seconds
350
  target_frames = F
351
  if trim_to_6s:
352
- import math
353
- max_frames_6s = int(math.ceil(6.0 * fps))
354
- max_frames_6s = ((max_frames_6s - 1) // 4) * 4 + 1
355
  target_frames = min(F, max_frames_6s)
356
  if F > max_frames_6s:
357
  print(f"Fast mode: Trimming single audio from {F} frames to {max_frames_6s} frames (6 seconds)")
 
205
 
206
  # Fast mode: trim to 6 seconds if trim_to_6s is True
207
  if trim_to_6s:
208
+ # 6秒固定为145帧
209
+ max_frames_6s = 145
 
 
210
  if total_length > max_frames_6s:
211
  print(f"Fast mode: Trimming audio from {total_length} frames to {max_frames_6s} frames (6 seconds)")
212
  # Truncate each audio proportionally
 
297
  # Fast mode: if trim_to_6s, limit to 6 seconds
298
  target_frames = F
299
  if trim_to_6s:
300
+ # 6秒固定为145帧
301
+ max_frames_6s = 145
 
302
  target_frames = min(F, max_frames_6s)
303
  if F > max_frames_6s:
304
  print(f"Fast mode: Trimming audio {i} from {F} frames to {max_frames_6s} frames (6 seconds)")
 
346
  # Fast mode: if trim_to_6s, limit to 6 seconds
347
  target_frames = F
348
  if trim_to_6s:
349
+ # 6秒固定为145帧
350
+ max_frames_6s = 145
 
351
  target_frames = min(F, max_frames_6s)
352
  if F > max_frames_6s:
353
  print(f"Fast mode: Trimming single audio from {F} frames to {max_frames_6s} frames (6 seconds)")