Re-commit the right code
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ import traceback
|
|
| 11 |
import einops
|
| 12 |
import safetensors.torch as sf
|
| 13 |
import numpy as np
|
| 14 |
-
import argparse
|
| 15 |
import random
|
| 16 |
import math
|
| 17 |
# 20250506 pftq: Added for video input loading
|
|
@@ -397,6 +396,24 @@ def worker(input_image, prompts, n_prompt, seed, total_second_length, latent_win
|
|
| 397 |
history_latents = torch.cat([history_latents, start_latent.to(history_latents)], dim=2)
|
| 398 |
total_generated_latent_frames = 1
|
| 399 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
for section_index in range(total_latent_sections):
|
| 401 |
if stream.input_queue.top() == 'end':
|
| 402 |
stream.output_queue.push(('end', None))
|
|
@@ -416,24 +433,6 @@ def worker(input_image, prompts, n_prompt, seed, total_second_length, latent_win
|
|
| 416 |
else:
|
| 417 |
transformer.initialize_teacache(enable_teacache=False)
|
| 418 |
|
| 419 |
-
def callback(d):
|
| 420 |
-
preview = d['denoised']
|
| 421 |
-
preview = vae_decode_fake(preview)
|
| 422 |
-
|
| 423 |
-
preview = (preview * 255.0).detach().cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 424 |
-
preview = einops.rearrange(preview, 'b c t h w -> (b h) (t w) c')
|
| 425 |
-
|
| 426 |
-
if stream.input_queue.top() == 'end':
|
| 427 |
-
stream.output_queue.push(('end', None))
|
| 428 |
-
raise KeyboardInterrupt('User ends the task.')
|
| 429 |
-
|
| 430 |
-
current_step = d['i'] + 1
|
| 431 |
-
percentage = int(100.0 * current_step / steps)
|
| 432 |
-
hint = f'Sampling {current_step}/{steps}'
|
| 433 |
-
desc = f'Total generated frames: {int(max(0, total_generated_latent_frames * 4 - 3))}, Video length: {max(0, (total_generated_latent_frames * 4 - 3) / 30) :.2f} seconds (FPS-30). The video is being extended now ...'
|
| 434 |
-
stream.output_queue.push(('progress', (preview, desc, make_progress_bar_html(percentage, hint))))
|
| 435 |
-
return
|
| 436 |
-
|
| 437 |
indices = torch.arange(0, sum([1, 16, 2, 1, latent_window_size])).unsqueeze(0)
|
| 438 |
clean_latent_indices_start, clean_latent_4x_indices, clean_latent_2x_indices, clean_latent_1x_indices, latent_indices = indices.split([1, 16, 2, 1, latent_window_size], dim=1)
|
| 439 |
clean_latent_indices = torch.cat([clean_latent_indices_start, clean_latent_1x_indices], dim=1)
|
|
@@ -512,7 +511,7 @@ def worker(input_image, prompts, n_prompt, seed, total_second_length, latent_win
|
|
| 512 |
return
|
| 513 |
|
| 514 |
def get_duration(input_image, prompt, generation_mode, n_prompt, randomize_seed, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, mp4_crf):
|
| 515 |
-
return total_second_length * 60
|
| 516 |
|
| 517 |
|
| 518 |
@spaces.GPU(duration=get_duration)
|
|
@@ -632,6 +631,24 @@ def worker_video(input_video, prompt, n_prompt, seed, batch, resolution, total_s
|
|
| 632 |
total_latent_sections = (total_second_length * fps) / (latent_window_size * 4)
|
| 633 |
total_latent_sections = int(max(round(total_latent_sections), 1))
|
| 634 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
for idx in range(batch):
|
| 636 |
if batch > 1:
|
| 637 |
print(f"Beginning video {idx+1} of {batch} with seed {seed} ")
|
|
@@ -671,24 +688,6 @@ def worker_video(input_video, prompt, n_prompt, seed, batch, resolution, total_s
|
|
| 671 |
else:
|
| 672 |
transformer.initialize_teacache(enable_teacache=False)
|
| 673 |
|
| 674 |
-
def callback(d):
|
| 675 |
-
preview = d['denoised']
|
| 676 |
-
preview = vae_decode_fake(preview)
|
| 677 |
-
|
| 678 |
-
preview = (preview * 255.0).detach().cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 679 |
-
preview = einops.rearrange(preview, 'b c t h w -> (b h) (t w) c')
|
| 680 |
-
|
| 681 |
-
if stream.input_queue.top() == 'end':
|
| 682 |
-
stream.output_queue.push(('end', None))
|
| 683 |
-
raise KeyboardInterrupt('User ends the task.')
|
| 684 |
-
|
| 685 |
-
current_step = d['i'] + 1
|
| 686 |
-
percentage = int(100.0 * current_step / steps)
|
| 687 |
-
hint = f'Sampling {current_step}/{steps}'
|
| 688 |
-
desc = f'Total frames: {int(max(0, total_generated_latent_frames * 4 - 3))}, Video length: {max(0, (total_generated_latent_frames * 4 - 3) / fps) :.2f} seconds (FPS-{fps}), Seed: {seed}, Video {idx+1} of {batch}. The video is generating part {section_index+1} of {total_latent_sections}...'
|
| 689 |
-
stream.output_queue.push(('progress', (preview, desc, make_progress_bar_html(percentage, hint))))
|
| 690 |
-
return
|
| 691 |
-
|
| 692 |
# 20250506 pftq: Use user-specified number of context frames, matching original allocation for num_clean_frames=2
|
| 693 |
available_frames = history_latents.shape[2] # Number of latent frames
|
| 694 |
max_pixel_frames = min(latent_window_size * 4 - 3, available_frames * 4) # Cap at available pixel frames
|
|
@@ -710,26 +709,32 @@ def worker_video(input_video, prompt, n_prompt, seed, batch, resolution, total_s
|
|
| 710 |
|
| 711 |
# 20250506 pftq: Split history_latents dynamically based on available frames
|
| 712 |
fallback_frame_count = 2 # 20250507 pftq: Changed 0 to 2 Edge case for <=1 sec videos
|
| 713 |
-
context_frames =
|
|
|
|
| 714 |
if total_context_frames > 0:
|
|
|
|
| 715 |
split_sizes = [num_4x_frames, num_2x_frames, effective_clean_frames]
|
| 716 |
split_sizes = [s for s in split_sizes if s > 0] # Remove zero sizes
|
| 717 |
if split_sizes:
|
| 718 |
splits = context_frames.split(split_sizes, dim=2)
|
| 719 |
split_idx = 0
|
| 720 |
-
|
|
|
|
|
|
|
|
|
|
| 721 |
if clean_latents_4x.shape[2] < 2: # 20250507 pftq: edge case for <=1 sec videos
|
| 722 |
clean_latents_4x = torch.cat([clean_latents_4x, clean_latents_4x[:, :, -1:, :, :]], dim=2)[:, :, :2, :, :]
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
|
|
|
| 733 |
|
| 734 |
clean_latents = torch.cat([start_latent.to(history_latents), clean_latents_1x], dim=2)
|
| 735 |
|
|
@@ -781,11 +786,6 @@ def worker_video(input_video, prompt, n_prompt, seed, batch, resolution, total_s
|
|
| 781 |
section_latent_frames = latent_window_size * 2
|
| 782 |
overlapped_frames = min(latent_window_size * 4 - 3, history_pixels.shape[2])
|
| 783 |
|
| 784 |
-
#if section_index == 0:
|
| 785 |
-
#extra_latents = 1 # Add up to 2 extra latent frames for smoother overlap to initial video
|
| 786 |
-
#extra_pixel_frames = extra_latents * 4 # Approx. 4 pixel frames per latent
|
| 787 |
-
#overlapped_frames = min(overlapped_frames + extra_pixel_frames, history_pixels.shape[2], section_latent_frames * 4)
|
| 788 |
-
|
| 789 |
current_pixels = vae_decode(real_history_latents[:, :, -section_latent_frames:], vae).cpu()
|
| 790 |
history_pixels = soft_append_bcthw(history_pixels, current_pixels, overlapped_frames)
|
| 791 |
|
|
@@ -828,12 +828,12 @@ def worker_video(input_video, prompt, n_prompt, seed, batch, resolution, total_s
|
|
| 828 |
return
|
| 829 |
|
| 830 |
def get_duration_video(input_video, prompt, n_prompt, randomize_seed, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
|
| 831 |
-
return total_second_length * 60 * 2
|
| 832 |
|
| 833 |
# 20250506 pftq: Modified process to pass clean frame count, etc from video_encode
|
| 834 |
@spaces.GPU(duration=get_duration_video)
|
| 835 |
def process_video(input_video, prompt, n_prompt, randomize_seed, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
|
| 836 |
-
global stream
|
| 837 |
|
| 838 |
if torch.cuda.device_count() == 0:
|
| 839 |
gr.Warning('Set this space to GPU config to make it work.')
|
|
@@ -886,19 +886,27 @@ def process_video(input_video, prompt, n_prompt, randomize_seed, seed, batch, re
|
|
| 886 |
def end_process():
|
| 887 |
stream.input_queue.push('end')
|
| 888 |
|
|
|
|
| 889 |
timed_prompts = {}
|
| 890 |
|
| 891 |
def handle_prompt_number_change():
|
| 892 |
-
timed_prompts
|
| 893 |
return []
|
| 894 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
def handle_timed_prompt_change(timed_prompt_id, timed_prompt):
|
| 896 |
timed_prompts[timed_prompt_id] = timed_prompt
|
|
|
|
|
|
|
|
|
|
| 897 |
dict_values = {k: v for k, v in timed_prompts.items()}
|
| 898 |
sorted_dict_values = sorted(dict_values.items(), key=lambda x: x[0])
|
| 899 |
array = []
|
| 900 |
for sorted_dict_value in sorted_dict_values:
|
| 901 |
-
array.append(sorted_dict_value[1])
|
| 902 |
print(str(array))
|
| 903 |
return ";".join(array)
|
| 904 |
|
|
@@ -929,19 +937,19 @@ with block:
|
|
| 929 |
text_to_video_hint = gr.HTML("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.", visible=False)
|
| 930 |
input_image = gr.Image(sources='upload', type="numpy", label="Image", height=320)
|
| 931 |
input_video = gr.Video(sources='upload', label="Input Video", height=320, visible=False)
|
| 932 |
-
|
| 933 |
prompt_number = gr.Slider(label="Timed prompt number", minimum=0, maximum=1000, value=0, step=1, info='Not for video extension')
|
| 934 |
prompt_number.change(fn=handle_prompt_number_change, inputs=[], outputs=[])
|
| 935 |
|
| 936 |
@gr.render(inputs=prompt_number)
|
| 937 |
def show_split(prompt_number):
|
| 938 |
-
timed_prompts = {}
|
| 939 |
-
|
| 940 |
for digit in range(prompt_number):
|
| 941 |
timed_prompt_id = gr.Textbox(value="timed_prompt_" + str(digit), visible=False)
|
| 942 |
timed_prompt = gr.Textbox(label="Timed prompt #" + str(digit + 1), elem_id="timed_prompt_" + str(digit), value="")
|
| 943 |
-
timed_prompt.change(fn=handle_timed_prompt_change, inputs=[timed_prompt_id, timed_prompt], outputs=[
|
| 944 |
|
|
|
|
|
|
|
| 945 |
total_second_length = gr.Slider(label="Video Length to Generate (seconds)", minimum=1, maximum=120, value=2, step=0.1)
|
| 946 |
|
| 947 |
with gr.Row():
|
|
@@ -993,8 +1001,8 @@ with block:
|
|
| 993 |
progress_bar = gr.HTML('', elem_classes='no-generating-animation')
|
| 994 |
|
| 995 |
# 20250506 pftq: Updated inputs to include num_clean_frames
|
| 996 |
-
ips = [input_image,
|
| 997 |
-
ips_video = [input_video,
|
| 998 |
|
| 999 |
start_button.click(fn = check_parameters, inputs = [
|
| 1000 |
generation_mode, input_image, input_video
|
|
@@ -1039,7 +1047,41 @@ with block:
|
|
| 1039 |
6, # gpu_memory_preservation
|
| 1040 |
False, # use_teacache
|
| 1041 |
16 # mp4_crf
|
| 1042 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1043 |
],
|
| 1044 |
run_on_click = True,
|
| 1045 |
fn = process,
|
|
@@ -1088,7 +1130,6 @@ with block:
|
|
| 1088 |
elif generation_mode_data == "video":
|
| 1089 |
return [gr.update(visible = False), gr.update(visible = False), gr.update(visible = True), gr.update(visible = False), gr.update(visible = True)]
|
| 1090 |
|
| 1091 |
-
|
| 1092 |
generation_mode.change(
|
| 1093 |
fn=handle_generation_mode_change,
|
| 1094 |
inputs=[generation_mode],
|
|
|
|
| 11 |
import einops
|
| 12 |
import safetensors.torch as sf
|
| 13 |
import numpy as np
|
|
|
|
| 14 |
import random
|
| 15 |
import math
|
| 16 |
# 20250506 pftq: Added for video input loading
|
|
|
|
| 396 |
history_latents = torch.cat([history_latents, start_latent.to(history_latents)], dim=2)
|
| 397 |
total_generated_latent_frames = 1
|
| 398 |
|
| 399 |
+
def callback(d):
|
| 400 |
+
preview = d['denoised']
|
| 401 |
+
preview = vae_decode_fake(preview)
|
| 402 |
+
|
| 403 |
+
preview = (preview * 255.0).detach().cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 404 |
+
preview = einops.rearrange(preview, 'b c t h w -> (b h) (t w) c')
|
| 405 |
+
|
| 406 |
+
if stream.input_queue.top() == 'end':
|
| 407 |
+
stream.output_queue.push(('end', None))
|
| 408 |
+
raise KeyboardInterrupt('User ends the task.')
|
| 409 |
+
|
| 410 |
+
current_step = d['i'] + 1
|
| 411 |
+
percentage = int(100.0 * current_step / steps)
|
| 412 |
+
hint = f'Sampling {current_step}/{steps}'
|
| 413 |
+
desc = f'Total generated frames: {int(max(0, total_generated_latent_frames * 4 - 3))}, Video length: {max(0, (total_generated_latent_frames * 4 - 3) / 30) :.2f} seconds (FPS-30). The video is being extended now ...'
|
| 414 |
+
stream.output_queue.push(('progress', (preview, desc, make_progress_bar_html(percentage, hint))))
|
| 415 |
+
return
|
| 416 |
+
|
| 417 |
for section_index in range(total_latent_sections):
|
| 418 |
if stream.input_queue.top() == 'end':
|
| 419 |
stream.output_queue.push(('end', None))
|
|
|
|
| 433 |
else:
|
| 434 |
transformer.initialize_teacache(enable_teacache=False)
|
| 435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
indices = torch.arange(0, sum([1, 16, 2, 1, latent_window_size])).unsqueeze(0)
|
| 437 |
clean_latent_indices_start, clean_latent_4x_indices, clean_latent_2x_indices, clean_latent_1x_indices, latent_indices = indices.split([1, 16, 2, 1, latent_window_size], dim=1)
|
| 438 |
clean_latent_indices = torch.cat([clean_latent_indices_start, clean_latent_1x_indices], dim=1)
|
|
|
|
| 511 |
return
|
| 512 |
|
| 513 |
def get_duration(input_image, prompt, generation_mode, n_prompt, randomize_seed, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, mp4_crf):
|
| 514 |
+
return total_second_length * 60 * (0.7 if use_teacache else 1.3)
|
| 515 |
|
| 516 |
|
| 517 |
@spaces.GPU(duration=get_duration)
|
|
|
|
| 631 |
total_latent_sections = (total_second_length * fps) / (latent_window_size * 4)
|
| 632 |
total_latent_sections = int(max(round(total_latent_sections), 1))
|
| 633 |
|
| 634 |
+
def callback(d):
|
| 635 |
+
preview = d['denoised']
|
| 636 |
+
preview = vae_decode_fake(preview)
|
| 637 |
+
|
| 638 |
+
preview = (preview * 255.0).detach().cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 639 |
+
preview = einops.rearrange(preview, 'b c t h w -> (b h) (t w) c')
|
| 640 |
+
|
| 641 |
+
if stream.input_queue.top() == 'end':
|
| 642 |
+
stream.output_queue.push(('end', None))
|
| 643 |
+
raise KeyboardInterrupt('User ends the task.')
|
| 644 |
+
|
| 645 |
+
current_step = d['i'] + 1
|
| 646 |
+
percentage = int(100.0 * current_step / steps)
|
| 647 |
+
hint = f'Sampling {current_step}/{steps}'
|
| 648 |
+
desc = f'Total frames: {int(max(0, total_generated_latent_frames * 4 - 3))}, Video length: {max(0, (total_generated_latent_frames * 4 - 3) / fps) :.2f} seconds (FPS-{fps}), Seed: {seed}, Video {idx+1} of {batch}. The video is generating part {section_index+1} of {total_latent_sections}...'
|
| 649 |
+
stream.output_queue.push(('progress', (preview, desc, make_progress_bar_html(percentage, hint))))
|
| 650 |
+
return
|
| 651 |
+
|
| 652 |
for idx in range(batch):
|
| 653 |
if batch > 1:
|
| 654 |
print(f"Beginning video {idx+1} of {batch} with seed {seed} ")
|
|
|
|
| 688 |
else:
|
| 689 |
transformer.initialize_teacache(enable_teacache=False)
|
| 690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
# 20250506 pftq: Use user-specified number of context frames, matching original allocation for num_clean_frames=2
|
| 692 |
available_frames = history_latents.shape[2] # Number of latent frames
|
| 693 |
max_pixel_frames = min(latent_window_size * 4 - 3, available_frames * 4) # Cap at available pixel frames
|
|
|
|
| 709 |
|
| 710 |
# 20250506 pftq: Split history_latents dynamically based on available frames
|
| 711 |
fallback_frame_count = 2 # 20250507 pftq: Changed 0 to 2 Edge case for <=1 sec videos
|
| 712 |
+
context_frames = clean_latents_4x = clean_latents_2x = clean_latents_1x = history_latents[:, :, :fallback_frame_count, :, :]
|
| 713 |
+
|
| 714 |
if total_context_frames > 0:
|
| 715 |
+
context_frames = history_latents[:, :, -total_context_frames:, :, :]
|
| 716 |
split_sizes = [num_4x_frames, num_2x_frames, effective_clean_frames]
|
| 717 |
split_sizes = [s for s in split_sizes if s > 0] # Remove zero sizes
|
| 718 |
if split_sizes:
|
| 719 |
splits = context_frames.split(split_sizes, dim=2)
|
| 720 |
split_idx = 0
|
| 721 |
+
|
| 722 |
+
if num_4x_frames > 0:
|
| 723 |
+
clean_latents_4x = splits[split_idx]
|
| 724 |
+
split_idx = 1
|
| 725 |
if clean_latents_4x.shape[2] < 2: # 20250507 pftq: edge case for <=1 sec videos
|
| 726 |
clean_latents_4x = torch.cat([clean_latents_4x, clean_latents_4x[:, :, -1:, :, :]], dim=2)[:, :, :2, :, :]
|
| 727 |
+
|
| 728 |
+
if num_2x_frames > 0 and split_idx < len(splits):
|
| 729 |
+
clean_latents_2x = splits[split_idx]
|
| 730 |
+
if clean_latents_2x.shape[2] < 2: # 20250507 pftq: edge case for <=1 sec videos
|
| 731 |
+
clean_latents_2x = torch.cat([clean_latents_2x, clean_latents_2x[:, :, -1:, :, :]], dim=2)[:, :, :2, :, :]
|
| 732 |
+
split_idx += 1
|
| 733 |
+
elif clean_latents_2x.shape[2] < 2: # 20250507 pftq: edge case for <=1 sec videos
|
| 734 |
+
clean_latents_2x = clean_latents_4x
|
| 735 |
+
|
| 736 |
+
if effective_clean_frames > 0 and split_idx < len(splits):
|
| 737 |
+
clean_latents_1x = splits[split_idx]
|
| 738 |
|
| 739 |
clean_latents = torch.cat([start_latent.to(history_latents), clean_latents_1x], dim=2)
|
| 740 |
|
|
|
|
| 786 |
section_latent_frames = latent_window_size * 2
|
| 787 |
overlapped_frames = min(latent_window_size * 4 - 3, history_pixels.shape[2])
|
| 788 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
current_pixels = vae_decode(real_history_latents[:, :, -section_latent_frames:], vae).cpu()
|
| 790 |
history_pixels = soft_append_bcthw(history_pixels, current_pixels, overlapped_frames)
|
| 791 |
|
|
|
|
| 828 |
return
|
| 829 |
|
| 830 |
def get_duration_video(input_video, prompt, n_prompt, randomize_seed, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
|
| 831 |
+
return total_second_length * 60 * (0.7 if use_teacache else 2)
|
| 832 |
|
| 833 |
# 20250506 pftq: Modified process to pass clean frame count, etc from video_encode
|
| 834 |
@spaces.GPU(duration=get_duration_video)
|
| 835 |
def process_video(input_video, prompt, n_prompt, randomize_seed, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch):
|
| 836 |
+
global stream, high_vram
|
| 837 |
|
| 838 |
if torch.cuda.device_count() == 0:
|
| 839 |
gr.Warning('Set this space to GPU config to make it work.')
|
|
|
|
| 886 |
def end_process():
|
| 887 |
stream.input_queue.push('end')
|
| 888 |
|
| 889 |
+
timeless_prompt_value = [""]
|
| 890 |
timed_prompts = {}
|
| 891 |
|
| 892 |
def handle_prompt_number_change():
|
| 893 |
+
timed_prompts.clear()
|
| 894 |
return []
|
| 895 |
|
| 896 |
+
def handle_timeless_prompt_change(timeless_prompt):
|
| 897 |
+
timeless_prompt_value[0] = timeless_prompt
|
| 898 |
+
return refresh_prompt()
|
| 899 |
+
|
| 900 |
def handle_timed_prompt_change(timed_prompt_id, timed_prompt):
|
| 901 |
timed_prompts[timed_prompt_id] = timed_prompt
|
| 902 |
+
return refresh_prompt()
|
| 903 |
+
|
| 904 |
+
def refresh_prompt():
|
| 905 |
dict_values = {k: v for k, v in timed_prompts.items()}
|
| 906 |
sorted_dict_values = sorted(dict_values.items(), key=lambda x: x[0])
|
| 907 |
array = []
|
| 908 |
for sorted_dict_value in sorted_dict_values:
|
| 909 |
+
array.append(timeless_prompt_value[0] + ". " + sorted_dict_value[1])
|
| 910 |
print(str(array))
|
| 911 |
return ";".join(array)
|
| 912 |
|
|
|
|
| 937 |
text_to_video_hint = gr.HTML("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.", visible=False)
|
| 938 |
input_image = gr.Image(sources='upload', type="numpy", label="Image", height=320)
|
| 939 |
input_video = gr.Video(sources='upload', label="Input Video", height=320, visible=False)
|
| 940 |
+
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, focus motion, consistent arm, consistent position, fixed camera")
|
| 941 |
prompt_number = gr.Slider(label="Timed prompt number", minimum=0, maximum=1000, value=0, step=1, info='Not for video extension')
|
| 942 |
prompt_number.change(fn=handle_prompt_number_change, inputs=[], outputs=[])
|
| 943 |
|
| 944 |
@gr.render(inputs=prompt_number)
|
| 945 |
def show_split(prompt_number):
|
|
|
|
|
|
|
| 946 |
for digit in range(prompt_number):
|
| 947 |
timed_prompt_id = gr.Textbox(value="timed_prompt_" + str(digit), visible=False)
|
| 948 |
timed_prompt = gr.Textbox(label="Timed prompt #" + str(digit + 1), elem_id="timed_prompt_" + str(digit), value="")
|
| 949 |
+
timed_prompt.change(fn=handle_timed_prompt_change, inputs=[timed_prompt_id, timed_prompt], outputs=[final_prompt])
|
| 950 |
|
| 951 |
+
final_prompt = gr.Textbox(label="Final prompt", value='', info='Use ; to separate in time')
|
| 952 |
+
timeless_prompt.change(fn=handle_timeless_prompt_change, inputs=[timeless_prompt], outputs=[final_prompt])
|
| 953 |
total_second_length = gr.Slider(label="Video Length to Generate (seconds)", minimum=1, maximum=120, value=2, step=0.1)
|
| 954 |
|
| 955 |
with gr.Row():
|
|
|
|
| 1001 |
progress_bar = gr.HTML('', elem_classes='no-generating-animation')
|
| 1002 |
|
| 1003 |
# 20250506 pftq: Updated inputs to include num_clean_frames
|
| 1004 |
+
ips = [input_image, final_prompt, generation_mode, n_prompt, randomize_seed, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, mp4_crf]
|
| 1005 |
+
ips_video = [input_video, final_prompt, n_prompt, randomize_seed, seed, batch, resolution, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache, no_resize, mp4_crf, num_clean_frames, vae_batch]
|
| 1006 |
|
| 1007 |
start_button.click(fn = check_parameters, inputs = [
|
| 1008 |
generation_mode, input_image, input_video
|
|
|
|
| 1047 |
6, # gpu_memory_preservation
|
| 1048 |
False, # use_teacache
|
| 1049 |
16 # mp4_crf
|
| 1050 |
+
],
|
| 1051 |
+
[
|
| 1052 |
+
"./img_examples/Example1.png", # input_image
|
| 1053 |
+
"We are sinking, photorealistic, realistic, intricate details, 8k, insanely detailed",
|
| 1054 |
+
"image", # generation_mode
|
| 1055 |
+
"Missing arm, unrealistic position, blurred, blurry", # n_prompt
|
| 1056 |
+
True, # randomize_seed
|
| 1057 |
+
42, # seed
|
| 1058 |
+
1, # total_second_length
|
| 1059 |
+
9, # latent_window_size
|
| 1060 |
+
25, # steps
|
| 1061 |
+
1.0, # cfg
|
| 1062 |
+
10.0, # gs
|
| 1063 |
+
0.0, # rs
|
| 1064 |
+
6, # gpu_memory_preservation
|
| 1065 |
+
False, # use_teacache
|
| 1066 |
+
16 # mp4_crf
|
| 1067 |
+
],
|
| 1068 |
+
[
|
| 1069 |
+
"./img_examples/Example1.png", # input_image
|
| 1070 |
+
"A boat is passing, photorealistic, realistic, intricate details, 8k, insanely detailed",
|
| 1071 |
+
"image", # generation_mode
|
| 1072 |
+
"Missing arm, unrealistic position, blurred, blurry", # n_prompt
|
| 1073 |
+
True, # randomize_seed
|
| 1074 |
+
42, # seed
|
| 1075 |
+
1, # total_second_length
|
| 1076 |
+
9, # latent_window_size
|
| 1077 |
+
25, # steps
|
| 1078 |
+
1.0, # cfg
|
| 1079 |
+
10.0, # gs
|
| 1080 |
+
0.0, # rs
|
| 1081 |
+
6, # gpu_memory_preservation
|
| 1082 |
+
False, # use_teacache
|
| 1083 |
+
16 # mp4_crf
|
| 1084 |
+
],
|
| 1085 |
],
|
| 1086 |
run_on_click = True,
|
| 1087 |
fn = process,
|
|
|
|
| 1130 |
elif generation_mode_data == "video":
|
| 1131 |
return [gr.update(visible = False), gr.update(visible = False), gr.update(visible = True), gr.update(visible = False), gr.update(visible = True)]
|
| 1132 |
|
|
|
|
| 1133 |
generation_mode.change(
|
| 1134 |
fn=handle_generation_mode_change,
|
| 1135 |
inputs=[generation_mode],
|