Code cleaning

This commit is contained in:
DeepBeepMeep 2025-04-11 08:10:01 +02:00
parent 9e9a952022
commit bb73359772
3 changed files with 19 additions and 8 deletions

View File

@ -960,7 +960,7 @@ class WanModel(ModelMixin, ConfigMixin):
]) ])
kwargs['context_scale'] = vace_context_scale kwargs['context_scale'] = vace_context_scale
hints_list = [ [c] if i==0 else [c.clone()] for i in range(len(x_list)) ] hints_list = [ [c] for _ in range(len(x_list)) ]
del c del c
should_calc = True should_calc = True

View File

@ -511,9 +511,9 @@ class WanT2V:
def adapt_vace_model(self): def adapt_vace_model(self):
model = self.model model = self.model
modules_dict= { k: m for k, m in model.named_modules()} modules_dict= { k: m for k, m in model.named_modules()}
for num in range(15): for model_layer, vace_layer in model.vace_layers_mapping.items():
module = modules_dict[f"vace_blocks.{num}"] module = modules_dict[f"vace_blocks.{vace_layer}"]
target = modules_dict[f"blocks.{2*num}"] target = modules_dict[f"blocks.{model_layer}"]
setattr(target, "vace", module ) setattr(target, "vace", module )
delattr(model, "vace_blocks") delattr(model, "vace_blocks")

19
wgp.py
View File

@ -421,7 +421,8 @@ def save_queue_action(state):
if image_filenames_for_json: if image_filenames_for_json:
params_copy[key] = image_filenames_for_json if is_originally_list else image_filenames_for_json[0] params_copy[key] = image_filenames_for_json if is_originally_list else image_filenames_for_json[0]
else: else:
params_copy.pop(key, None) pass
# params_copy.pop(key, None) #cant pop otherwise crash during reload
for key in video_keys: for key in video_keys:
video_path_orig = params_copy.get(key) video_path_orig = params_copy.get(key)
@ -885,6 +886,15 @@ def autoload_queue(state):
update_global_queue_ref([]) update_global_queue_ref([])
dataframe_update = update_queue_data([]) dataframe_update = update_queue_data([])
# need to remove queue otherwise every new tab will be processed it again
try:
if os.path.isfile(AUTOSAVE_FILENAME):
os.remove(AUTOSAVE_FILENAME)
print(f"Clear Queue: Deleted autosave file '{AUTOSAVE_FILENAME}'.")
except OSError as e:
print(f"Clear Queue: Error deleting autosave file '{AUTOSAVE_FILENAME}': {e}")
gr.Warning(f"Could not delete the autosave file '{AUTOSAVE_FILENAME}'. You may need to remove it manually.")
else: else:
if original_queue: if original_queue:
print("Autoload skipped: Queue is not empty.") print("Autoload skipped: Queue is not empty.")
@ -895,6 +905,7 @@ def autoload_queue(state):
update_global_queue_ref([]) update_global_queue_ref([])
dataframe_update = update_queue_data([]) dataframe_update = update_queue_data([])
return dataframe_update, loaded_flag, state return dataframe_update, loaded_flag, state
def run_autoload_and_prepare_ui(current_state): def run_autoload_and_prepare_ui(current_state):
@ -2313,10 +2324,10 @@ def generate_video(
progress(*progress_args ) progress(*progress_args )
gen["progress_args"] = progress_args gen["progress_args"] = progress_args
video_guide = preprocess_video(preprocess_type, width=width, height=height,video_in=video_guide, max_frames= video_length) video_guide = preprocess_video(preprocess_type, width=width, height=height,video_in=video_guide, max_frames= video_length)
image_refs = image_refs.copy() if image_refs != None else None # required since prepare_source do inplace modifications
src_video, src_mask, src_ref_images = wan_model.prepare_source([video_guide], src_video, src_mask, src_ref_images = wan_model.prepare_source([video_guide],
[video_mask], [video_mask],
[image_refs], [image_refs],
video_length, VACE_SIZE_CONFIGS[resolution_reformated], "cpu", video_length, VACE_SIZE_CONFIGS[resolution_reformated], "cpu",
original_video= "O" in video_prompt_type, original_video= "O" in video_prompt_type,
trim_video=max_frames) trim_video=max_frames)
@ -3598,7 +3609,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
queue_df = gr.DataFrame( queue_df = gr.DataFrame(
headers=["Qty","Prompt", "Length","Steps","", "", "", "", ""], headers=["Qty","Prompt", "Length","Steps","", "", "", "", ""],
datatype=[ "str","markdown","str", "markdown", "markdown", "markdown", "str", "str", "str"], datatype=[ "str","markdown","str", "markdown", "markdown", "markdown", "str", "str", "str"],
column_widths= ["5%", None, "7%", "7%", "10%", "10%", "3%", "3%", "3%"], column_widths= ["5%", None, "7%", "7%", "10%", "10%", "3%", "3%", "34"],
interactive=False, interactive=False,
col_count=(9, "fixed"), col_count=(9, "fixed"),
wrap=True, wrap=True,