Vicente Alvarez commited on
Commit
6eb235b
·
1 Parent(s): 2f7ed25

Add first_image2/first_image3 per-clip frame conditioning

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -347,6 +347,8 @@ def generate_video(
347
  remove_music: bool = False,
348
  prompt2: str = "",
349
  prompt3: str = "",
 
 
350
  progress=gr.Progress(track_tqdm=True),
351
  ):
352
  try:
@@ -441,6 +443,16 @@ def generate_video(
441
  if prompt2 and prompt2.strip():
442
  print(f"[Clip 2] Generating with prompt2: {prompt2[:50]}...")
443
  seed2 = current_seed + 1
 
 
 
 
 
 
 
 
 
 
444
  video_frames_iter2, audio2 = pipeline(
445
  prompt=prompt2.strip(),
446
  seed=seed2,
@@ -448,7 +460,7 @@ def generate_video(
448
  width=int(width),
449
  num_frames=num_frames,
450
  frame_rate=frame_rate,
451
- images=images,
452
  enhance_prompt=enhance_prompt,
453
  )
454
  frames2 = [frame for frame in video_frames_iter2]
@@ -466,6 +478,16 @@ def generate_video(
466
  if prompt3 and prompt3.strip():
467
  print(f"[Clip 3] Generating with prompt3: {prompt3[:50]}...")
468
  seed3 = current_seed + 2
 
 
 
 
 
 
 
 
 
 
469
  video_frames_iter3, audio3 = pipeline(
470
  prompt=prompt3.strip(),
471
  seed=seed3,
@@ -473,7 +495,7 @@ def generate_video(
473
  width=int(width),
474
  num_frames=num_frames,
475
  frame_rate=frame_rate,
476
- images=images,
477
  enhance_prompt=enhance_prompt,
478
  )
479
  frames3 = [frame for frame in video_frames_iter3]
@@ -545,6 +567,9 @@ with gr.Blocks(title="Element-16 Video", delete_cache=(3600, 7200)) as demo: #
545
  output_video2 = gr.Video(label="Generated Video 2", autoplay=True)
546
  output_video3 = gr.Video(label="Generated Video 3", autoplay=True)
547
 
 
 
 
548
  with gr.Row():
549
  prompt2 = gr.Textbox(label="Prompt 2 (optional)", value="", lines=2)
550
  prompt3 = gr.Textbox(label="Prompt 3 (optional)", value="", lines=2)
@@ -597,7 +622,7 @@ with gr.Blocks(title="Element-16 Video", delete_cache=(3600, 7200)) as demo: #
597
  inputs=[
598
  first_image, last_image, prompt, duration, enhance_prompt,
599
  seed, randomize_seed, height, width, negative_prompt, blur_amount, remove_music,
600
- prompt2, prompt3,
601
  ],
602
  outputs=[output_video, seed, output_video2, output_video3],
603
  )
 
347
  remove_music: bool = False,
348
  prompt2: str = "",
349
  prompt3: str = "",
350
+ first_image2=None,
351
+ first_image3=None,
352
  progress=gr.Progress(track_tqdm=True),
353
  ):
354
  try:
 
443
  if prompt2 and prompt2.strip():
444
  print(f"[Clip 2] Generating with prompt2: {prompt2[:50]}...")
445
  seed2 = current_seed + 1
446
+ if first_image2 is not None:
447
+ images2 = []
448
+ temp_first2_path = output_dir / f"temp_first2_{current_seed}.jpg"
449
+ if hasattr(first_image2, "save"):
450
+ first_image2.save(temp_first2_path)
451
+ else:
452
+ temp_first2_path = Path(first_image2)
453
+ images2.append(ImageConditioningInput(path=str(temp_first2_path), frame_idx=0, strength=1.0))
454
+ else:
455
+ images2 = images
456
  video_frames_iter2, audio2 = pipeline(
457
  prompt=prompt2.strip(),
458
  seed=seed2,
 
460
  width=int(width),
461
  num_frames=num_frames,
462
  frame_rate=frame_rate,
463
+ images=images2,
464
  enhance_prompt=enhance_prompt,
465
  )
466
  frames2 = [frame for frame in video_frames_iter2]
 
478
  if prompt3 and prompt3.strip():
479
  print(f"[Clip 3] Generating with prompt3: {prompt3[:50]}...")
480
  seed3 = current_seed + 2
481
+ if first_image3 is not None:
482
+ images3 = []
483
+ temp_first3_path = output_dir / f"temp_first3_{current_seed}.jpg"
484
+ if hasattr(first_image3, "save"):
485
+ first_image3.save(temp_first3_path)
486
+ else:
487
+ temp_first3_path = Path(first_image3)
488
+ images3.append(ImageConditioningInput(path=str(temp_first3_path), frame_idx=0, strength=1.0))
489
+ else:
490
+ images3 = images
491
  video_frames_iter3, audio3 = pipeline(
492
  prompt=prompt3.strip(),
493
  seed=seed3,
 
495
  width=int(width),
496
  num_frames=num_frames,
497
  frame_rate=frame_rate,
498
+ images=images3,
499
  enhance_prompt=enhance_prompt,
500
  )
501
  frames3 = [frame for frame in video_frames_iter3]
 
567
  output_video2 = gr.Video(label="Generated Video 2", autoplay=True)
568
  output_video3 = gr.Video(label="Generated Video 3", autoplay=True)
569
 
570
+ with gr.Row():
571
+ first_image2 = gr.Image(label="First Frame 2 (optional)", type="pil")
572
+ first_image3 = gr.Image(label="First Frame 3 (optional)", type="pil")
573
  with gr.Row():
574
  prompt2 = gr.Textbox(label="Prompt 2 (optional)", value="", lines=2)
575
  prompt3 = gr.Textbox(label="Prompt 3 (optional)", value="", lines=2)
 
622
  inputs=[
623
  first_image, last_image, prompt, duration, enhance_prompt,
624
  seed, randomize_seed, height, width, negative_prompt, blur_amount, remove_music,
625
+ prompt2, prompt3, first_image2, first_image3,
626
  ],
627
  outputs=[output_video, seed, output_video2, output_video3],
628
  )