Fabrice-TIERCELIN commited on
Commit
e9848b2
·
verified ·
1 Parent(s): 0cfab65

Remove SE

Browse files
Files changed (1) hide show
  1. app.py +40 -445
app.py CHANGED
@@ -120,8 +120,8 @@ outputs_folder = './outputs/'
120
  os.makedirs(outputs_folder, exist_ok=True)
121
 
122
  input_image_debug_value = [None]
123
- input_video_debug_value = [None]
124
  end_image_debug_value = [None]
 
125
  prompt_debug_value = [None]
126
  total_second_length_debug_value = [None]
127
 
@@ -316,7 +316,7 @@ def set_mp4_comments_imageio_ffmpeg(input_file, comments):
316
  return False
317
 
318
  @torch.no_grad()
319
- def worker(input_image, end_image, image_position, prompts, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number):
320
  def encode_prompt(prompt, n_prompt):
321
  llama_vec, clip_l_pooler = encode_prompt_conds(prompt, text_encoder, text_encoder_2, tokenizer, tokenizer_2)
322
 
@@ -585,275 +585,6 @@ def worker(input_image, end_image, image_position, prompts, n_prompt, seed, tota
585
  stream.output_queue.push(('end', None))
586
  return
587
 
588
- @torch.no_grad()
589
- def worker_start_end(input_image, end_image, image_position, prompts, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number):
590
- def encode_prompt(prompt, n_prompt):
591
- llama_vec, clip_l_pooler = encode_prompt_conds(prompt, text_encoder, text_encoder_2, tokenizer, tokenizer_2)
592
-
593
- if cfg == 1:
594
- llama_vec_n, clip_l_pooler_n = torch.zeros_like(llama_vec), torch.zeros_like(clip_l_pooler)
595
- else:
596
- llama_vec_n, clip_l_pooler_n = encode_prompt_conds(n_prompt, text_encoder, text_encoder_2, tokenizer, tokenizer_2)
597
-
598
- llama_vec, llama_attention_mask = crop_or_pad_yield_mask(llama_vec, length=512)
599
- llama_vec_n, llama_attention_mask_n = crop_or_pad_yield_mask(llama_vec_n, length=512)
600
-
601
- llama_vec = llama_vec.to(transformer.dtype)
602
- llama_vec_n = llama_vec_n.to(transformer.dtype)
603
- clip_l_pooler = clip_l_pooler.to(transformer.dtype)
604
- clip_l_pooler_n = clip_l_pooler_n.to(transformer.dtype)
605
- return [llama_vec, clip_l_pooler, llama_vec_n, clip_l_pooler_n, llama_attention_mask, llama_attention_mask_n]
606
-
607
- total_latent_sections = (total_second_length * fps_number) / (latent_window_size * 4)
608
- total_latent_sections = int(max(round(total_latent_sections), 1))
609
-
610
- job_id = generate_timestamp()
611
-
612
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'Starting ...'))))
613
-
614
- try:
615
- # Clean GPU
616
- if not high_vram:
617
- unload_complete_models(
618
- text_encoder, text_encoder_2, image_encoder, vae, transformer
619
- )
620
-
621
- # Text encoding
622
-
623
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'Text encoding ...'))))
624
-
625
- if not high_vram:
626
- fake_diffusers_current_device(text_encoder, gpu) # since we only encode one text - that is one model move and one encode, offload is same time consumption since it is also one load and one encode.
627
- load_model_as_complete(text_encoder_2, target_device=gpu)
628
-
629
-
630
- prompt_parameters = []
631
-
632
- for prompt_part in prompts[:total_latent_sections]:
633
- prompt_parameters.append(encode_prompt(prompt_part, n_prompt))
634
-
635
- # Clean GPU
636
- if not high_vram:
637
- unload_complete_models(
638
- text_encoder, text_encoder_2
639
- )
640
-
641
- # Processing input image (start frame)
642
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'Processing start frame ...'))))
643
-
644
- H, W, C = input_image.shape
645
- height, width = find_nearest_bucket(H, W, resolution=640)
646
- input_image_np = resize_and_center_crop(input_image, target_width=width, target_height=height)
647
-
648
- Image.fromarray(input_image_np).save(os.path.join(outputs_folder, f'{job_id}_start.png'))
649
-
650
- input_image_pt = torch.from_numpy(input_image_np).float() / 127.5 - 1
651
- input_image_pt = input_image_pt.permute(2, 0, 1)[None, :, None]
652
-
653
- # Processing end image (if provided)
654
- has_end_image = end_image is not None
655
- if has_end_image:
656
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'Processing end frame ...'))))
657
-
658
- H_end, W_end, C_end = end_image.shape
659
- end_image_np = resize_and_center_crop(end_image, target_width=width, target_height=height)
660
-
661
- Image.fromarray(end_image_np).save(os.path.join(outputs_folder, f'{job_id}_end.png'))
662
-
663
- end_image_pt = torch.from_numpy(end_image_np).float() / 127.5 - 1
664
- end_image_pt = end_image_pt.permute(2, 0, 1)[None, :, None]
665
-
666
- # VAE encoding
667
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'VAE encoding ...'))))
668
-
669
- if not high_vram:
670
- load_model_as_complete(vae, target_device=gpu)
671
-
672
- start_latent = vae_encode(input_image_pt, vae)
673
-
674
- if has_end_image:
675
- end_latent = vae_encode(end_image_pt, vae)
676
-
677
- # CLIP Vision
678
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'CLIP Vision encoding ...'))))
679
-
680
- if not high_vram:
681
- load_model_as_complete(image_encoder, target_device=gpu)
682
-
683
- image_encoder_output = hf_clip_vision_encode(input_image_np, feature_extractor, image_encoder)
684
- image_encoder_last_hidden_state = image_encoder_output.last_hidden_state
685
-
686
- if has_end_image:
687
- end_image_encoder_output = hf_clip_vision_encode(end_image_np, feature_extractor, image_encoder)
688
- end_image_encoder_last_hidden_state = end_image_encoder_output.last_hidden_state
689
- # Combine both image embeddings or use a weighted approach
690
- image_encoder_last_hidden_state = (image_encoder_last_hidden_state + end_image_encoder_last_hidden_state) / 2
691
-
692
- # Clean GPU
693
- if not high_vram:
694
- unload_complete_models(
695
- image_encoder
696
- )
697
-
698
- # Dtype
699
- image_encoder_last_hidden_state = image_encoder_last_hidden_state.to(transformer.dtype)
700
-
701
- # Sampling
702
- stream.output_queue.push(('progress', (None, '', make_progress_bar_html(0, 'Start sampling ...'))))
703
-
704
- rnd = torch.Generator("cpu").manual_seed(seed)
705
- num_frames = latent_window_size * 4 - 3
706
-
707
- history_latents = torch.zeros(size=(1, 16, 1 + 2 + 16, height // 8, width // 8), dtype=torch.float32, device=cpu)
708
- start_latent = start_latent.to(history_latents)
709
- if has_end_image:
710
- end_latent = end_latent.to(history_latents)
711
-
712
- history_pixels = None
713
- total_generated_latent_frames = 0
714
-
715
- if total_latent_sections > 4:
716
- # In theory the latent_paddings should follow the above sequence, but it seems that duplicating some
717
- # items looks better than expanding it when total_latent_sections > 4
718
- # One can try to remove below trick and just
719
- # use `latent_paddings = list(reversed(range(total_latent_sections)))` to compare
720
- latent_paddings = [3] + [2] * (total_latent_sections - 3) + [1, 0]
721
- else:
722
- # Convert an iterator to a list
723
- latent_paddings = list(range(total_latent_sections - 1, -1, -1))
724
-
725
- if enable_preview:
726
- def callback(d):
727
- preview = d['denoised']
728
- preview = vae_decode_fake(preview)
729
-
730
- preview = (preview * 255.0).detach().cpu().numpy().clip(0, 255).astype(np.uint8)
731
- preview = einops.rearrange(preview, 'b c t h w -> (b h) (t w) c')
732
-
733
- if stream.input_queue.top() == 'end':
734
- stream.output_queue.push(('end', None))
735
- raise KeyboardInterrupt('User ends the task.')
736
-
737
- current_step = d['i'] + 1
738
- percentage = int(100.0 * current_step / steps)
739
- hint = f'Sampling {current_step}/{steps}'
740
- desc = f'Total generated frames: {int(max(0, total_generated_latent_frames * 4 - 3))}, Video length: {max(0, (total_generated_latent_frames * 4 - 3) / fps_number) :.2f} seconds (FPS-30), Resolution: {height}px * {width}px. The video is being extended now ...'
741
- stream.output_queue.push(('progress', (preview, desc, make_progress_bar_html(percentage, hint))))
742
- return
743
- else:
744
- def callback(d):
745
- return
746
-
747
- for latent_padding in latent_paddings:
748
- is_last_section = latent_padding == 0
749
- is_first_section = latent_padding == latent_paddings[0]
750
- latent_padding_size = latent_padding * latent_window_size
751
-
752
- if stream.input_queue.top() == 'end':
753
- stream.output_queue.push(('end', None))
754
- return
755
-
756
- print(f'latent_padding_size = {latent_padding_size}, is_last_section = {is_last_section}, is_first_section = {is_first_section}')
757
-
758
- if len(prompt_parameters) > 0:
759
- [llama_vec, clip_l_pooler, llama_vec_n, clip_l_pooler_n, llama_attention_mask, llama_attention_mask_n] = prompt_parameters.pop(len(prompt_parameters) - 1)
760
-
761
- indices = torch.arange(1 + latent_padding_size + latent_window_size + 1 + 2 + 16).unsqueeze(0)
762
- clean_latent_indices_pre, blank_indices, latent_indices, clean_latent_indices_post, clean_latent_2x_indices, clean_latent_4x_indices = indices.split([1, latent_padding_size, latent_window_size, 1, 2, 16], dim=1)
763
- clean_latent_indices = torch.cat([clean_latent_indices_pre, clean_latent_indices_post], dim=1)
764
-
765
- clean_latents_post, clean_latents_2x, clean_latents_4x = history_latents[:, :, :1 + 2 + 16, :, :].split([1, 2, 16], dim=2)
766
-
767
- # Use end image latent for the first section if provided
768
- if has_end_image and is_first_section:
769
- clean_latents_post = end_latent
770
-
771
- clean_latents = torch.cat([start_latent, clean_latents_post], dim=2)
772
-
773
- if not high_vram:
774
- unload_complete_models()
775
- move_model_to_device_with_memory_preservation(transformer, target_device=gpu, preserved_memory_gb=gpu_memory_preservation)
776
-
777
- if use_teacache:
778
- transformer.initialize_teacache(enable_teacache=True, num_steps=steps)
779
- else:
780
- transformer.initialize_teacache(enable_teacache=False)
781
-
782
- generated_latents = sample_hunyuan(
783
- transformer=transformer,
784
- sampler='unipc',
785
- width=width,
786
- height=height,
787
- frames=num_frames,
788
- real_guidance_scale=cfg,
789
- distilled_guidance_scale=gs,
790
- guidance_rescale=rs,
791
- # shift=3.0,
792
- num_inference_steps=steps,
793
- generator=rnd,
794
- prompt_embeds=llama_vec,
795
- prompt_embeds_mask=llama_attention_mask,
796
- prompt_poolers=clip_l_pooler,
797
- negative_prompt_embeds=llama_vec_n,
798
- negative_prompt_embeds_mask=llama_attention_mask_n,
799
- negative_prompt_poolers=clip_l_pooler_n,
800
- device=gpu,
801
- dtype=torch.bfloat16,
802
- image_embeddings=image_encoder_last_hidden_state,
803
- latent_indices=latent_indices,
804
- clean_latents=clean_latents,
805
- clean_latent_indices=clean_latent_indices,
806
- clean_latents_2x=clean_latents_2x,
807
- clean_latent_2x_indices=clean_latent_2x_indices,
808
- clean_latents_4x=clean_latents_4x,
809
- clean_latent_4x_indices=clean_latent_4x_indices,
810
- callback=callback,
811
- )
812
-
813
- if is_last_section:
814
- generated_latents = torch.cat([start_latent.to(generated_latents), generated_latents], dim=2)
815
-
816
- total_generated_latent_frames += int(generated_latents.shape[2])
817
- history_latents = torch.cat([generated_latents.to(history_latents), history_latents], dim=2)
818
-
819
- if not high_vram:
820
- offload_model_from_device_for_memory_preservation(transformer, target_device=gpu, preserved_memory_gb=8)
821
- load_model_as_complete(vae, target_device=gpu)
822
-
823
- if history_pixels is None:
824
- history_pixels = vae_decode(history_latents[:, :, :total_generated_latent_frames, :, :], vae).cpu()
825
- else:
826
- section_latent_frames = (latent_window_size * 2 + 1) if is_last_section else (latent_window_size * 2)
827
- overlapped_frames = latent_window_size * 4 - 3
828
-
829
- current_pixels = vae_decode(history_latents[:, :, :min(total_generated_latent_frames, section_latent_frames)], vae).cpu()
830
- history_pixels = soft_append_bcthw(current_pixels, history_pixels, overlapped_frames)
831
-
832
- if not high_vram:
833
- unload_complete_models(vae)
834
-
835
- if enable_preview or is_last_section:
836
- output_filename = os.path.join(outputs_folder, f'{job_id}_{total_generated_latent_frames}.mp4')
837
-
838
- save_bcthw_as_mp4(history_pixels, output_filename, fps=fps_number, crf=mp4_crf)
839
-
840
- print(f'Decoded. Pixel shape {history_pixels.shape}')
841
-
842
- stream.output_queue.push(('file', output_filename))
843
-
844
- if is_last_section:
845
- break
846
- except:
847
- traceback.print_exc()
848
-
849
- if not high_vram:
850
- unload_complete_models(
851
- text_encoder, text_encoder_2, image_encoder, vae, transformer
852
- )
853
-
854
- stream.output_queue.push(('end', None))
855
- return
856
-
857
  # 20250506 pftq: Modified worker to accept video input and clean frame count
858
  @torch.no_grad()
859
  def worker_video(input_video, prompts, n_prompt, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
@@ -1144,7 +875,7 @@ def process_on_gpu(input_image, end_image, image_position, prompts, generation_m
1144
  global stream
1145
  stream = AsyncStream()
1146
 
1147
- async_run(worker_start_end if generation_mode == "start_end" else worker, input_image, end_image, image_position, prompts, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number)
1148
 
1149
  output_filename = None
1150
 
@@ -1186,12 +917,12 @@ def process(input_image,
1186
  resolution=640,
1187
  total_second_length=5,
1188
  latent_window_size=9,
1189
- steps=30,
1190
  cfg=1.0,
1191
  gs=10.0,
1192
  rs=0.0,
1193
  gpu_memory_preservation=6,
1194
- enable_preview=False,
1195
  use_teacache=False,
1196
  mp4_crf=16,
1197
  fps_number=30
@@ -1199,13 +930,12 @@ def process(input_image,
1199
  if auto_allocation:
1200
  allocation_time = min(total_second_length * 60 * (1.5 if use_teacache else 3.0) * (1 + ((steps - 25) / 25))**2, 600)
1201
 
1202
- if input_image_debug_value[0] is not None or end_image_debug_value[0] is not None or prompt_debug_value[0] is not None or total_second_length_debug_value[0] is not None:
1203
  input_image = input_image_debug_value[0]
1204
- end_image = end_image_debug_value[0]
1205
  prompt = prompt_debug_value[0]
1206
  total_second_length = total_second_length_debug_value[0]
1207
  allocation_time = min(total_second_length_debug_value[0] * 60 * 100, 600)
1208
- input_image_debug_value[0] = end_image_debug_value[0] = input_video_debug_value[0] = prompt_debug_value[0] = total_second_length_debug_value[0] = None
1209
 
1210
  if torch.cuda.device_count() == 0:
1211
  gr.Warning('Set this space to GPU config to make it work.')
@@ -1226,7 +956,7 @@ def process(input_image,
1226
  yield gr.update(label="Previewed Frames"), None, '', '', gr.update(interactive=False), gr.update(interactive=True), gr.skip()
1227
 
1228
  yield from process_on_gpu(input_image,
1229
- end_image,
1230
  image_position,
1231
  prompts,
1232
  generation_mode,
@@ -1297,7 +1027,7 @@ def process_video(input_video, prompt, n_prompt, randomize_seed, seed, auto_allo
1297
  prompt = prompt_debug_value[0]
1298
  total_second_length = total_second_length_debug_value[0]
1299
  allocation_time = min(total_second_length_debug_value[0] * 60 * 100, 600)
1300
- input_image_debug_value[0] = end_image_debug_value[0] = input_video_debug_value[0] = prompt_debug_value[0] = total_second_length_debug_value[0] = None
1301
 
1302
  if torch.cuda.device_count() == 0:
1303
  gr.Warning('Set this space to GPU config to make it work.')
@@ -1397,11 +1127,11 @@ with block:
1397
  local_storage = gr.BrowserState(default_local_storage)
1398
  with gr.Row():
1399
  with gr.Column():
1400
- generation_mode = gr.Radio([["Text-to-Video", "text"], ["Image-to-Video", "image"], ["Start & end frames", "start_end"], ["Video Extension", "video"]], elem_id="generation-mode", label="Generation mode", value = "image")
1401
  text_to_video_hint = gr.HTML("Text-to-Video badly works with a flash effect at the start. I discourage to use the Text-to-Video feature. You should rather generate an image with Flux and use Image-to-Video. You will save time.")
1402
  input_image = gr.Image(sources='upload', type="numpy", label="Image", height=320)
1403
- end_image = gr.Image(sources='upload', type="numpy", label="End Frame (Optional)", height=320)
1404
  image_position = gr.Slider(label="Image position", minimum=0, maximum=100, value=0, step=1, info='0=Video start; 100=Video end (lower quality)')
 
1405
  input_video = gr.Video(sources='upload', label="Input Video", height=320)
1406
  timeless_prompt = gr.Textbox(label="Timeless prompt", info='Used on the whole duration of the generation', value='', placeholder="The creature starts to move, fast motion, fixed camera, focus motion, consistent arm, consistent position, mute colors, insanely detailed")
1407
  prompt_number = gr.Slider(label="Timed prompt number", minimum=0, maximum=1000, value=0, step=1, info='Prompts will automatically appear')
@@ -1426,7 +1156,7 @@ with block:
1426
  enable_preview = gr.Checkbox(label='Enable preview', value=True, info='Display a preview around each second generated but it costs 2 sec. for each second generated.')
1427
  use_teacache = gr.Checkbox(label='Use TeaCache', value=False, info='Faster speed and no break in brightness, but often makes hands and fingers slightly worse.')
1428
 
1429
- n_prompt = gr.Textbox(label="Negative Prompt", value="Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", info='Requires using normal CFG (undistilled) instead of Distilled (set Distilled=1 and CFG > 1).')
1430
 
1431
  fps_number = gr.Slider(label="Frame per seconds", info="The model is trained for 30 fps so other fps may generate weird results", minimum=10, maximum=60, value=30, step=1)
1432
 
@@ -1476,7 +1206,6 @@ with block:
1476
 
1477
  with gr.Accordion("Debug", open=False):
1478
  input_image_debug = gr.Image(type="numpy", label="Image Debug", height=320)
1479
- end_image_debug = gr.Image(type="numpy", label="End Image Debug", height=320)
1480
  input_video_debug = gr.Video(sources='upload', label="Input Video Debug", height=320)
1481
  prompt_debug = gr.Textbox(label="Prompt Debug", value='')
1482
  total_second_length_debug = gr.Slider(label="Additional Video Length to Generate (seconds) Debug", minimum=1, maximum=120, value=1, step=0.1)
@@ -1488,6 +1217,7 @@ with block:
1488
  progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
1489
  progress_bar = gr.HTML('', elem_classes='no-generating-animation')
1490
 
 
1491
  ips = [input_image, end_image, image_position, final_prompt, generation_mode, n_prompt, randomize_seed, seed, auto_allocation, allocation_time, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number]
1492
  ips_video = [input_video, final_prompt, n_prompt, randomize_seed, seed, auto_allocation, allocation_time, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch]
1493
 
@@ -1501,7 +1231,7 @@ with block:
1501
  0, # image_position
1502
  "Overcrowed street in Japan, photorealistic, realistic, intricate details, 8k, insanely detailed",
1503
  "text", # generation_mode
1504
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1505
  True, # randomize_seed
1506
  42, # seed
1507
  True, # auto_allocation
@@ -1537,7 +1267,7 @@ with block:
1537
  0, # image_position
1538
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks, the man stops talking and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens",
1539
  "image", # generation_mode
1540
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1541
  True, # randomize_seed
1542
  42, # seed
1543
  True, # auto_allocation
@@ -1561,7 +1291,7 @@ with block:
1561
  0, # image_position
1562
  "A dolphin emerges from the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1563
  "image", # generation_mode
1564
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1565
  True, # randomize_seed
1566
  42, # seed
1567
  True, # auto_allocation
@@ -1585,7 +1315,7 @@ with block:
1585
  1, # image_position
1586
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1587
  "image", # generation_mode
1588
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1589
  True, # randomize_seed
1590
  42, # seed
1591
  True, # auto_allocation
@@ -1609,7 +1339,7 @@ with block:
1609
  50, # image_position
1610
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1611
  "image", # generation_mode
1612
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1613
  True, # randomize_seed
1614
  42, # seed
1615
  True, # auto_allocation
@@ -1633,43 +1363,7 @@ with block:
1633
  100, # image_position
1634
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1635
  "image", # generation_mode
1636
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1637
- True, # randomize_seed
1638
- 42, # seed
1639
- True, # auto_allocation
1640
- 180, # allocation_time
1641
- 672, # resolution
1642
- 1, # total_second_length
1643
- 9, # latent_window_size
1644
- 30, # steps
1645
- 1.0, # cfg
1646
- 10.0, # gs
1647
- 0.0, # rs
1648
- 6, # gpu_memory_preservation
1649
- False, # enable_preview
1650
- False, # use_teacache
1651
- 16, # mp4_crf
1652
- 30 # fps_number
1653
- ],
1654
- ],
1655
- run_on_click = True,
1656
- fn = process,
1657
- inputs = ips,
1658
- outputs = [result_video, preview_image, progress_desc, progress_bar, start_button, end_button, warning],
1659
- cache_examples = torch.cuda.device_count() > 0,
1660
- )
1661
-
1662
- with gr.Row(elem_id="start_end_examples", visible=False):
1663
- gr.Examples(
1664
- label = "Examples from start and end frames",
1665
- examples = [
1666
- [
1667
- "./img_examples/Example2.webp", # input_image
1668
- None, # end_image
1669
- 0, # image_position
1670
- "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks, the man stops talking and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens",
1671
- "start_end", # generation_mode
1672
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1673
  True, # randomize_seed
1674
  42, # seed
1675
  True, # auto_allocation
@@ -1702,7 +1396,7 @@ with block:
1702
  [
1703
  "./img_examples/Example1.mp4", # input_video
1704
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1705
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1706
  True, # randomize_seed
1707
  42, # seed
1708
  True, # auto_allocation
@@ -1726,7 +1420,7 @@ with block:
1726
  [
1727
  "./img_examples/Example1.mp4", # input_video
1728
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1729
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1730
  True, # randomize_seed
1731
  42, # seed
1732
  True, # auto_allocation
@@ -1764,7 +1458,7 @@ with block:
1764
  0, # image_position
1765
  "Overcrowed street in Japan, photorealistic, realistic, intricate details, 8k, insanely detailed",
1766
  "text", # generation_mode
1767
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1768
  True, # randomize_seed
1769
  42, # seed
1770
  True, # auto_allocation
@@ -1799,7 +1493,7 @@ with block:
1799
  0, # image_position
1800
  "A dolphin emerges from the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1801
  "image", # generation_mode
1802
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1803
  True, # randomize_seed
1804
  42, # seed
1805
  True, # auto_allocation
@@ -1823,7 +1517,7 @@ with block:
1823
  0, # image_position
1824
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks, the man stops talking and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens",
1825
  "image", # generation_mode
1826
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1827
  True, # randomize_seed
1828
  42, # seed
1829
  True, # auto_allocation
@@ -1847,7 +1541,7 @@ with block:
1847
  0, # image_position
1848
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks, the woman stops talking and the woman listens A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens",
1849
  "image", # generation_mode
1850
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1851
  True, # randomize_seed
1852
  42, # seed
1853
  True, # auto_allocation
@@ -1871,7 +1565,7 @@ with block:
1871
  0, # image_position
1872
  "A boy is walking to the right, full view, full-length view, cartoon",
1873
  "image", # generation_mode
1874
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1875
  True, # randomize_seed
1876
  42, # seed
1877
  True, # auto_allocation
@@ -1895,7 +1589,7 @@ with block:
1895
  100, # image_position
1896
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1897
  "image", # generation_mode
1898
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1899
  True, # randomize_seed
1900
  42, # seed
1901
  True, # auto_allocation
@@ -1921,48 +1615,13 @@ with block:
1921
  cache_examples = False,
1922
  )
1923
 
1924
- gr.Examples(
1925
- label = "🖼️ Examples from start and end frames",
1926
- examples = [
1927
- [
1928
- "./img_examples/Example1.png", # input_image
1929
- None, # end_image
1930
- 0, # image_position
1931
- "A dolphin emerges from the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1932
- "start_end", # generation_mode
1933
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1934
- True, # randomize_seed
1935
- 42, # seed
1936
- True, # auto_allocation
1937
- 180, # allocation_time
1938
- 672, # resolution
1939
- 1, # total_second_length
1940
- 9, # latent_window_size
1941
- 30, # steps
1942
- 1.0, # cfg
1943
- 10.0, # gs
1944
- 0.0, # rs
1945
- 6, # gpu_memory_preservation
1946
- False, # enable_preview
1947
- True, # use_teacache
1948
- 16, # mp4_crf
1949
- 30 # fps_number
1950
- ],
1951
- ],
1952
- run_on_click = True,
1953
- fn = process,
1954
- inputs = ips,
1955
- outputs = [result_video, preview_image, progress_desc, progress_bar, start_button, end_button, warning],
1956
- cache_examples = False,
1957
- )
1958
-
1959
  gr.Examples(
1960
  label = "🎥 Examples from video",
1961
  examples = [
1962
  [
1963
  "./img_examples/Example1.mp4", # input_video
1964
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1965
- "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, poorly framed, blurred, blurry, over-smooth", # n_prompt
1966
  True, # randomize_seed
1967
  42, # seed
1968
  True, # auto_allocation
@@ -2013,106 +1672,42 @@ with block:
2013
 
2014
  def handle_generation_mode_change(generation_mode_data):
2015
  if generation_mode_data == "text":
2016
- return [
2017
- gr.update(visible = True), # text_to_video_hint
2018
- gr.update(visible = False), # image_position
2019
- gr.update(visible = False), # input_image
2020
- gr.update(visible = False), # end_image
2021
- gr.update(visible = False), # input_video
2022
- gr.update(visible = True), # start_button
2023
- gr.update(visible = False), # start_button_video
2024
- gr.update(visible = False), # no_resize
2025
- gr.update(visible = False), # batch
2026
- gr.update(visible = False), # num_clean_frames
2027
- gr.update(visible = False), # vae_batch
2028
- gr.update(visible = False), # prompt_hint
2029
- gr.update(visible = True) # fps_number
2030
- ]
2031
  elif generation_mode_data == "image":
2032
- return [
2033
- gr.update(visible = False), # text_to_video_hint
2034
- gr.update(visible = True), # image_position
2035
- gr.update(visible = True), # input_image
2036
- gr.update(visible = False), # end_image
2037
- gr.update(visible = False), # input_video
2038
- gr.update(visible = True), # start_button
2039
- gr.update(visible = False), # start_button_video
2040
- gr.update(visible = False), # no_resize
2041
- gr.update(visible = False), # batch
2042
- gr.update(visible = False), # num_clean_frames
2043
- gr.update(visible = False), # vae_batch
2044
- gr.update(visible = False), # prompt_hint
2045
- gr.update(visible = True) # fps_number
2046
- ]
2047
- elif generation_mode_data == "start_end":
2048
- return [
2049
- gr.update(visible = False), # text_to_video_hint
2050
- gr.update(visible = False), # image_position
2051
- gr.update(visible = True), # input_image
2052
- gr.update(visible = True), # end_image
2053
- gr.update(visible = False), # input_video
2054
- gr.update(visible = True), # start_button
2055
- gr.update(visible = False), # start_button_video
2056
- gr.update(visible = False), # no_resize
2057
- gr.update(visible = False), # batch
2058
- gr.update(visible = False), # num_clean_frames
2059
- gr.update(visible = False), # vae_batch
2060
- gr.update(visible = False), # prompt_hint
2061
- gr.update(visible = True) # fps_number
2062
- ]
2063
  elif generation_mode_data == "video":
2064
- return [
2065
- gr.update(visible = False), # text_to_video_hint
2066
- gr.update(visible = False), # image_position
2067
- gr.update(visible = False), # input_image
2068
- gr.update(visible = False), # end_image
2069
- gr.update(visible = True), # input_video
2070
- gr.update(visible = False), # start_button
2071
- gr.update(visible = True), # start_button_video
2072
- gr.update(visible = True), # no_resize
2073
- gr.update(visible = True), # batch
2074
- gr.update(visible = True), # num_clean_frames
2075
- gr.update(visible = True), # vae_batch
2076
- gr.update(visible = True), # prompt_hint
2077
- gr.update(visible = False) # fps_number
2078
- ]
2079
-
2080
- def handle_field_debug_change(input_image_debug_data, input_video_debug_data, end_image_debug_data, prompt_debug_data, total_second_length_debug_data):
2081
  print("handle_field_debug_change")
2082
  input_image_debug_value[0] = input_image_debug_data
2083
  input_video_debug_value[0] = input_video_debug_data
2084
- end_image_debug_value[0] = end_image_debug_data
2085
  prompt_debug_value[0] = prompt_debug_data
2086
  total_second_length_debug_value[0] = total_second_length_debug_data
2087
  return []
2088
 
2089
  input_image_debug.upload(
2090
  fn=handle_field_debug_change,
2091
- inputs=[input_image_debug, input_video_debug, end_image_debug, prompt_debug, total_second_length_debug],
2092
  outputs=[]
2093
  )
2094
 
2095
  input_video_debug.upload(
2096
  fn=handle_field_debug_change,
2097
- inputs=[input_image_debug, input_video_debug, end_image_debug, prompt_debug, total_second_length_debug],
2098
- outputs=[]
2099
- )
2100
-
2101
- end_image_debug.upload(
2102
- fn=handle_field_debug_change,
2103
- inputs=[input_image_debug, input_video_debug, end_image_debug, prompt_debug, total_second_length_debug],
2104
  outputs=[]
2105
  )
2106
 
2107
  prompt_debug.change(
2108
  fn=handle_field_debug_change,
2109
- inputs=[input_image_debug, input_video_debug, end_image_debug, prompt_debug, total_second_length_debug],
2110
  outputs=[]
2111
  )
2112
 
2113
  total_second_length_debug.change(
2114
  fn=handle_field_debug_change,
2115
- inputs=[input_image_debug, input_video_debug, end_image_debug, prompt_debug, total_second_length_debug],
2116
  outputs=[]
2117
  )
2118
 
@@ -2136,7 +1731,7 @@ with block:
2136
  generation_mode.change(
2137
  fn=handle_generation_mode_change,
2138
  inputs=[generation_mode],
2139
- outputs=[text_to_video_hint, image_position, input_image, end_image, input_video, start_button, start_button_video, no_resize, batch, num_clean_frames, vae_batch, prompt_hint, fps_number]
2140
  )
2141
 
2142
  # Update display when the page loads
@@ -2144,7 +1739,7 @@ with block:
2144
  fn=handle_generation_mode_change, inputs = [
2145
  generation_mode
2146
  ], outputs = [
2147
- text_to_video_hint, image_position, input_image, end_image, input_video, start_button, start_button_video, no_resize, batch, num_clean_frames, vae_batch, prompt_hint, fps_number
2148
  ]
2149
  )
2150
 
 
120
  os.makedirs(outputs_folder, exist_ok=True)
121
 
122
  input_image_debug_value = [None]
 
123
  end_image_debug_value = [None]
124
+ input_video_debug_value = [None]
125
  prompt_debug_value = [None]
126
  total_second_length_debug_value = [None]
127
 
 
316
  return False
317
 
318
  @torch.no_grad()
319
+ def worker(input_image, end_image, image_position, prompts, n_prompt, seed, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number):
320
  def encode_prompt(prompt, n_prompt):
321
  llama_vec, clip_l_pooler = encode_prompt_conds(prompt, text_encoder, text_encoder_2, tokenizer, tokenizer_2)
322
 
 
585
  stream.output_queue.push(('end', None))
586
  return
587
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  # 20250506 pftq: Modified worker to accept video input and clean frame count
589
  @torch.no_grad()
590
  def worker_video(input_video, prompts, n_prompt, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
 
875
  global stream
876
  stream = AsyncStream()
877
 
878
+ async_run(worker, input_image, end_image, image_position, prompts, n_prompt, seed, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number)
879
 
880
  output_filename = None
881
 
 
917
  resolution=640,
918
  total_second_length=5,
919
  latent_window_size=9,
920
+ steps=25,
921
  cfg=1.0,
922
  gs=10.0,
923
  rs=0.0,
924
  gpu_memory_preservation=6,
925
+ enable_preview=True,
926
  use_teacache=False,
927
  mp4_crf=16,
928
  fps_number=30
 
930
  if auto_allocation:
931
  allocation_time = min(total_second_length * 60 * (1.5 if use_teacache else 3.0) * (1 + ((steps - 25) / 25))**2, 600)
932
 
933
+ if input_image_debug_value[0] is not None or prompt_debug_value[0] is not None or total_second_length_debug_value[0] is not None:
934
  input_image = input_image_debug_value[0]
 
935
  prompt = prompt_debug_value[0]
936
  total_second_length = total_second_length_debug_value[0]
937
  allocation_time = min(total_second_length_debug_value[0] * 60 * 100, 600)
938
+ input_image_debug_value[0] = prompt_debug_value[0] = total_second_length_debug_value[0] = None
939
 
940
  if torch.cuda.device_count() == 0:
941
  gr.Warning('Set this space to GPU config to make it work.')
 
956
  yield gr.update(label="Previewed Frames"), None, '', '', gr.update(interactive=False), gr.update(interactive=True), gr.skip()
957
 
958
  yield from process_on_gpu(input_image,
959
+ end_image,
960
  image_position,
961
  prompts,
962
  generation_mode,
 
1027
  prompt = prompt_debug_value[0]
1028
  total_second_length = total_second_length_debug_value[0]
1029
  allocation_time = min(total_second_length_debug_value[0] * 60 * 100, 600)
1030
+ input_video_debug_value[0] = prompt_debug_value[0] = total_second_length_debug_value[0] = None
1031
 
1032
  if torch.cuda.device_count() == 0:
1033
  gr.Warning('Set this space to GPU config to make it work.')
 
1127
  local_storage = gr.BrowserState(default_local_storage)
1128
  with gr.Row():
1129
  with gr.Column():
1130
+ generation_mode = gr.Radio([["Text-to-Video", "text"], ["Image-to-Video", "image"], ["Video Extension", "video"]], elem_id="generation-mode", label="Generation mode", value = "image")
1131
  text_to_video_hint = gr.HTML("Text-to-Video badly works with a flash effect at the start. I discourage to use the Text-to-Video feature. You should rather generate an image with Flux and use Image-to-Video. You will save time.")
1132
  input_image = gr.Image(sources='upload', type="numpy", label="Image", height=320)
 
1133
  image_position = gr.Slider(label="Image position", minimum=0, maximum=100, value=0, step=1, info='0=Video start; 100=Video end (lower quality)')
1134
+ end_image = gr.Image(sources='upload', type="numpy", label="End Frame (Optional)", height=320)
1135
  input_video = gr.Video(sources='upload', label="Input Video", height=320)
1136
  timeless_prompt = gr.Textbox(label="Timeless prompt", info='Used on the whole duration of the generation', value='', placeholder="The creature starts to move, fast motion, fixed camera, focus motion, consistent arm, consistent position, mute colors, insanely detailed")
1137
  prompt_number = gr.Slider(label="Timed prompt number", minimum=0, maximum=1000, value=0, step=1, info='Prompts will automatically appear')
 
1156
  enable_preview = gr.Checkbox(label='Enable preview', value=True, info='Display a preview around each second generated but it costs 2 sec. for each second generated.')
1157
  use_teacache = gr.Checkbox(label='Use TeaCache', value=False, info='Faster speed and no break in brightness, but often makes hands and fingers slightly worse.')
1158
 
1159
+ n_prompt = gr.Textbox(label="Negative Prompt", value="Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", info='Requires using normal CFG (undistilled) instead of Distilled (set Distilled=1 and CFG > 1).')
1160
 
1161
  fps_number = gr.Slider(label="Frame per seconds", info="The model is trained for 30 fps so other fps may generate weird results", minimum=10, maximum=60, value=30, step=1)
1162
 
 
1206
 
1207
  with gr.Accordion("Debug", open=False):
1208
  input_image_debug = gr.Image(type="numpy", label="Image Debug", height=320)
 
1209
  input_video_debug = gr.Video(sources='upload', label="Input Video Debug", height=320)
1210
  prompt_debug = gr.Textbox(label="Prompt Debug", value='')
1211
  total_second_length_debug = gr.Slider(label="Additional Video Length to Generate (seconds) Debug", minimum=1, maximum=120, value=1, step=0.1)
 
1217
  progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
1218
  progress_bar = gr.HTML('', elem_classes='no-generating-animation')
1219
 
1220
+ # 20250506 pftq: Updated inputs to include num_clean_frames
1221
  ips = [input_image, end_image, image_position, final_prompt, generation_mode, n_prompt, randomize_seed, seed, auto_allocation, allocation_time, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, mp4_crf, fps_number]
1222
  ips_video = [input_video, final_prompt, n_prompt, randomize_seed, seed, auto_allocation, allocation_time, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, enable_preview, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch]
1223
 
 
1231
  0, # image_position
1232
  "Overcrowed street in Japan, photorealistic, realistic, intricate details, 8k, insanely detailed",
1233
  "text", # generation_mode
1234
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1235
  True, # randomize_seed
1236
  42, # seed
1237
  True, # auto_allocation
 
1267
  0, # image_position
1268
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks, the man stops talking and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens",
1269
  "image", # generation_mode
1270
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1271
  True, # randomize_seed
1272
  42, # seed
1273
  True, # auto_allocation
 
1291
  0, # image_position
1292
  "A dolphin emerges from the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1293
  "image", # generation_mode
1294
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1295
  True, # randomize_seed
1296
  42, # seed
1297
  True, # auto_allocation
 
1315
  1, # image_position
1316
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1317
  "image", # generation_mode
1318
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1319
  True, # randomize_seed
1320
  42, # seed
1321
  True, # auto_allocation
 
1339
  50, # image_position
1340
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1341
  "image", # generation_mode
1342
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1343
  True, # randomize_seed
1344
  42, # seed
1345
  True, # auto_allocation
 
1363
  100, # image_position
1364
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1365
  "image", # generation_mode
1366
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1367
  True, # randomize_seed
1368
  42, # seed
1369
  True, # auto_allocation
 
1396
  [
1397
  "./img_examples/Example1.mp4", # input_video
1398
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1399
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1400
  True, # randomize_seed
1401
  42, # seed
1402
  True, # auto_allocation
 
1420
  [
1421
  "./img_examples/Example1.mp4", # input_video
1422
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1423
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1424
  True, # randomize_seed
1425
  42, # seed
1426
  True, # auto_allocation
 
1458
  0, # image_position
1459
  "Overcrowed street in Japan, photorealistic, realistic, intricate details, 8k, insanely detailed",
1460
  "text", # generation_mode
1461
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1462
  True, # randomize_seed
1463
  42, # seed
1464
  True, # auto_allocation
 
1493
  0, # image_position
1494
  "A dolphin emerges from the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1495
  "image", # generation_mode
1496
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1497
  True, # randomize_seed
1498
  42, # seed
1499
  True, # auto_allocation
 
1517
  0, # image_position
1518
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks, the man stops talking and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens",
1519
  "image", # generation_mode
1520
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1521
  True, # randomize_seed
1522
  42, # seed
1523
  True, # auto_allocation
 
1541
  0, # image_position
1542
  "A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The woman talks and the man listens; A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks, the woman stops talking and the woman listens A man on the left and a woman on the right face each other ready to start a conversation, large space between the persons, full view, full-length view, 3D, pixar, 3D render, CGI. The man talks and the woman listens",
1543
  "image", # generation_mode
1544
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1545
  True, # randomize_seed
1546
  42, # seed
1547
  True, # auto_allocation
 
1565
  0, # image_position
1566
  "A boy is walking to the right, full view, full-length view, cartoon",
1567
  "image", # generation_mode
1568
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1569
  True, # randomize_seed
1570
  42, # seed
1571
  True, # auto_allocation
 
1589
  100, # image_position
1590
  "A building starting to explode, photorealistic, realisitc, 8k, insanely detailed",
1591
  "image", # generation_mode
1592
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1593
  True, # randomize_seed
1594
  42, # seed
1595
  True, # auto_allocation
 
1615
  cache_examples = False,
1616
  )
1617
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1618
  gr.Examples(
1619
  label = "🎥 Examples from video",
1620
  examples = [
1621
  [
1622
  "./img_examples/Example1.mp4", # input_video
1623
  "View of the sea as far as the eye can see, from the seaside, a piece of land is barely visible on the horizon at the middle, the sky is radiant, reflections of the sun in the water, photorealistic, realistic, intricate details, 8k, insanely detailed",
1624
+ "Missing arm, long hand, unrealistic position, impossible contortion, visible bone, muscle contraction, blurred, blurry, over-smooth", # n_prompt
1625
  True, # randomize_seed
1626
  42, # seed
1627
  True, # auto_allocation
 
1672
 
1673
  def handle_generation_mode_change(generation_mode_data):
1674
  if generation_mode_data == "text":
1675
+ return [gr.update(visible = True), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = True), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = True)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1676
  elif generation_mode_data == "image":
1677
+ return [gr.update(visible = False), gr.update(visible = True), gr.update(visible = True), gr.update(visible = False), gr.update(visible = True), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = True)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1678
  elif generation_mode_data == "video":
1679
+ return [gr.update(visible = False), gr.update(visible = False), gr.update(visible = False), gr.update(visible = True), gr.update(visible = False), gr.update(visible = True), gr.update(visible = True), gr.update(visible = True), gr.update(visible = True), gr.update(visible = True), gr.update(visible = True), gr.update(visible = False)]
1680
+
1681
+
1682
+ def handle_field_debug_change(input_image_debug_data, input_video_debug_data, prompt_debug_data, total_second_length_debug_data):
 
 
 
 
 
 
 
 
 
 
 
 
 
1683
  print("handle_field_debug_change")
1684
  input_image_debug_value[0] = input_image_debug_data
1685
  input_video_debug_value[0] = input_video_debug_data
 
1686
  prompt_debug_value[0] = prompt_debug_data
1687
  total_second_length_debug_value[0] = total_second_length_debug_data
1688
  return []
1689
 
1690
  input_image_debug.upload(
1691
  fn=handle_field_debug_change,
1692
+ inputs=[input_image_debug, input_video_debug, prompt_debug, total_second_length_debug],
1693
  outputs=[]
1694
  )
1695
 
1696
  input_video_debug.upload(
1697
  fn=handle_field_debug_change,
1698
+ inputs=[input_image_debug, input_video_debug, prompt_debug, total_second_length_debug],
 
 
 
 
 
 
1699
  outputs=[]
1700
  )
1701
 
1702
  prompt_debug.change(
1703
  fn=handle_field_debug_change,
1704
+ inputs=[input_image_debug, input_video_debug, prompt_debug, total_second_length_debug],
1705
  outputs=[]
1706
  )
1707
 
1708
  total_second_length_debug.change(
1709
  fn=handle_field_debug_change,
1710
+ inputs=[input_image_debug, input_video_debug, prompt_debug, total_second_length_debug],
1711
  outputs=[]
1712
  )
1713
 
 
1731
  generation_mode.change(
1732
  fn=handle_generation_mode_change,
1733
  inputs=[generation_mode],
1734
+ outputs=[text_to_video_hint, image_position, input_image, input_video, start_button, start_button_video, no_resize, batch, num_clean_frames, vae_batch, prompt_hint, fps_number]
1735
  )
1736
 
1737
  # Update display when the page loads
 
1739
  fn=handle_generation_mode_change, inputs = [
1740
  generation_mode
1741
  ], outputs = [
1742
+ text_to_video_hint, image_position, input_image, input_video, start_button, start_button_video, no_resize, batch, num_clean_frames, vae_batch, prompt_hint, fps_number
1743
  ]
1744
  )
1745