Vicente Alvarez commited on
Commit
bb07cbe
·
1 Parent(s): 7971834

Add first_image2/first_image3 per-clip frame conditioning

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