abreza commited on
Commit
a77146c
·
1 Parent(s): 058680b
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -37,7 +37,7 @@ logging.basicConfig(level=logging.INFO)
37
  logger = logging.getLogger(__name__)
38
 
39
  # Constants
40
- MAX_FRAMES = 80
41
  OUTPUT_FPS = 24
42
  RENDER_WIDTH = 512
43
  RENDER_HEIGHT = 384
@@ -287,6 +287,17 @@ def run_wan_ttm_generation(prompt, tweak_index, tstrong_index, first_frame_path,
287
 
288
  progress(0, desc="Loading Wan TTM Pipeline...")
289
 
 
 
 
 
 
 
 
 
 
 
 
290
  progress(0.2, desc="Preparing inputs...")
291
  image = load_image(first_frame_path)
292
 
@@ -307,7 +318,7 @@ def run_wan_ttm_generation(prompt, tweak_index, tstrong_index, first_frame_path,
307
  image.height, image.width, max_area, mod_value)
308
  image = image.resize((width, height))
309
 
310
- progress(0.4, desc="Generating Video (this may take a few minutes)...")
311
  generator = torch.Generator(device="cuda").manual_seed(0)
312
 
313
  with torch.inference_mode():
@@ -317,7 +328,7 @@ def run_wan_ttm_generation(prompt, tweak_index, tstrong_index, first_frame_path,
317
  negative_prompt=negative_prompt,
318
  height=height,
319
  width=width,
320
- num_frames=81, # Wan default
321
  guidance_scale=3.5,
322
  num_inference_steps=50,
323
  generator=generator,
@@ -331,7 +342,7 @@ def run_wan_ttm_generation(prompt, tweak_index, tstrong_index, first_frame_path,
331
  first_frame_path), "wan_ttm_output.mp4")
332
  export_to_video(result.frames[0], output_path, fps=16)
333
 
334
- return output_path, "✅ TTM Video generated successfully with Wan 2.2!"
335
 
336
  # --- MODIFIED PROCESS VIDEO TO RETURN FILE PATHS ---
337
 
 
37
  logger = logging.getLogger(__name__)
38
 
39
  # Constants
40
+ MAX_FRAMES = 81
41
  OUTPUT_FPS = 24
42
  RENDER_WIDTH = 512
43
  RENDER_HEIGHT = 384
 
287
 
288
  progress(0, desc="Loading Wan TTM Pipeline...")
289
 
290
+ import decord
291
+ vr = decord.VideoReader(motion_video_path)
292
+ actual_frame_count = len(vr)
293
+
294
+ target_num_frames = ((actual_frame_count - 1) // 4) * 4 + 1
295
+
296
+ if target_num_frames < 5:
297
+ return None, f"❌ Video too short. Only {actual_frame_count} frames tracked."
298
+
299
+ logger.info(f"Setting Wan num_frames to {target_num_frames} based on tracking output.")
300
+
301
  progress(0.2, desc="Preparing inputs...")
302
  image = load_image(first_frame_path)
303
 
 
318
  image.height, image.width, max_area, mod_value)
319
  image = image.resize((width, height))
320
 
321
+ progress(0.4, desc=f"Generating {target_num_frames} frames (this may take a few minutes)...")
322
  generator = torch.Generator(device="cuda").manual_seed(0)
323
 
324
  with torch.inference_mode():
 
328
  negative_prompt=negative_prompt,
329
  height=height,
330
  width=width,
331
+ num_frames=target_num_frames,
332
  guidance_scale=3.5,
333
  num_inference_steps=50,
334
  generator=generator,
 
342
  first_frame_path), "wan_ttm_output.mp4")
343
  export_to_video(result.frames[0], output_path, fps=16)
344
 
345
+ return output_path, f"✅ TTM Video ({target_num_frames} frames) generated successfully!"
346
 
347
  # --- MODIFIED PROCESS VIDEO TO RETURN FILE PATHS ---
348