Skip to content
Python

Merge remote-tracking branch 'upstream/main' into queues

Chris Malone8abc52cdee53
diff --cc gradio_server.py
index 088cf12,78076a2..b429867
--- a/gradio_server.py
+++ b/gradio_server.py
@@@ -30,216 -29,6 +30,222 @@@ mmgp_version = version("mmgp"
if mmgp_version != target_mmgp_version:
print(f"Incorrect version of mmgp ({mmgp_version}), version {target_mmgp_version} is needed. Please upgrade with the command 'pip install -r requirements.txt'")
exit()
+queue = []
+lock = threading.Lock()
+current_task_id = None
+task_id = 0
+progress_tracker = {}
+tracker_lock = threading.Lock()
+file_list = []
+last_model_type = None
+
+def format_time(seconds):
+ if seconds < 60:
+ return f"{seconds:.1f}s"
+ elif seconds < 3600:
+ minutes = seconds / 60
+ return f"{minutes:.1f}m"
+ else:
+ hours = int(seconds // 3600)
+ minutes = int((seconds % 3600) // 60)
+ return f"{hours}h {minutes}m"
+
+def runner():
+ global current_task_id
+ while True:
+ with lock:
+ for item in queue:
+ task_id_runner = item['id']
+ with tracker_lock:
+ progress = progress_tracker.get(task_id_runner, {})
+
+ if item['state'] == "Processing":
+ current_step = progress.get('current_step', 0)
+ total_steps = progress.get('total_steps', 0)
+ elapsed = time.time() - progress.get('start_time', time.time())
+ status = progress.get('status', "")
+ repeats = progress.get("repeats", "0/0")
+ item.update({
+ 'progress': f"{((current_step/total_steps)*100 if total_steps > 0 else 0):.1f}%",
+ 'steps': f"{current_step}/{total_steps}",
+ 'time': format_time(elapsed),
+ 'repeats': f"{repeats}",
+ 'status': f"{status}"
+ })
+ if not any(item['state'] == "Processing" for item in queue):
+ for item in queue:
+ if item['state'] == "Queued":
+ item['status'] = "Processing"
+ item['state'] = "Processing"
+ current_task_id = item['id']
+ threading.Thread(target=process_task, args=(item,)).start()
+ break
+ time.sleep(1)
+
+def process_prompt_and_add_tasks(
+ prompt,
+ negative_prompt,
+ resolution,
+ video_length,
+ seed,
+ num_inference_steps,
+ guidance_scale,
+ flow_shift,
+ embedded_guidance_scale,
+ repeat_generation,
+ multi_images_gen_type,
+ tea_cache,
+ tea_cache_start_step_perc,
+ loras_choices,
+ loras_mult_choices,
++ image_prompt_type,
+ image_to_continue,
+ image_to_end,
+ video_to_continue,
+ max_frames,
+ RIFLEx_setting,
+ slg_switch,
+ slg_layers,
+ slg_start,
+ slg_end,
++ cfg_star_switch,
++ cfg_zero_step,
+ state_arg,
+ image2video
+):
+ if len(prompt) ==0:
+ return
+ prompt, errors = prompt_parser.process_template(prompt)
+ if len(errors) > 0:
+ gr.Info("Error processing prompt template: " + errors)
+ return
+ prompts = prompt.replace("\r", "").split("\n")
+ prompts = [prompt.strip() for prompt in prompts if len(prompt.strip())>0 and not prompt.startswith("#")]
+ if len(prompts) ==0:
+ return
+
+ for single_prompt in prompts:
+ task_params = (
+ single_prompt,
+ negative_prompt,
+ resolution,
+ video_length,
+ seed,
+ num_inference_steps,
+ guidance_scale,
+ flow_shift,
+ embedded_guidance_scale,
+ repeat_generation,
+ multi_images_gen_type,
+ tea_cache,
+ tea_cache_start_step_perc,
+ loras_choices,
+ loras_mult_choices,
++ image_prompt_type,
+ image_to_continue,
+ image_to_end,
+ video_to_continue,
+ max_frames,
+ RIFLEx_setting,
+ slg_switch,
+ slg_layers,
+ slg_start,
+ slg_end,
++ cfg_star_switch,
++ cfg_zero_step,
+ state_arg,
+ image2video
+ )
+ add_video_task(*task_params)
+ return update_queue_data()
+
+def process_task(task):
+ try:
+ task_id, *params = task['params']
+ generate_video(task_id, *params)
+ finally:
+ with lock:
+ queue[:] = [item for item in queue if item['id'] != task['id']]
+ with tracker_lock:
+ if task['id'] in progress_tracker:
+ del progress_tracker[task['id']]
+
+def add_video_task(*params):
+ global task_id
+ with lock:
+ task_id += 1
+ current_task_id = task_id
+ queue.append({
+ "id": current_task_id,
+ "params": (current_task_id,) + params,
+ "state": "Queued",
+ "status": "Queued",
+ "repeats": "0/0",
+ "progress": "0.0%",
+ "steps": f"0/{params[5]}",
+ "time": "--",
+ "prompt": params[0]
+ })
+ return
+
+def move_up(selected_indices):
+ if not selected_indices or len(selected_indices) == 0:
+ return update_queue_data()
+ idx = selected_indices[0]
+ if isinstance(idx, list):
+ idx = idx[0]
+ idx = int(idx)
+ with lock:
+ if idx > 0:
+ queue[idx], queue[idx-1] = queue[idx-1], queue[idx]
+ return update_queue_data()
+
+def move_down(selected_indices):
+ if not selected_indices or len(selected_indices) == 0:
+ return update_queue_data()
+ idx = selected_indices[0]
+ if isinstance(idx, list):
+ idx = idx[0]
+ idx = int(idx)
+ with lock:
+ if idx < len(queue)-1:
+ queue[idx], queue[idx+1] = queue[idx+1], queue[idx]
+ return update_queue_data()
+
+def remove_task(selected_indices):
+ if not selected_indices or len(selected_indices) == 0:
+ return update_queue_data()
+ idx = selected_indices[0]
+ if isinstance(idx, list):
+ idx = idx[0]
+ idx = int(idx)
+ with lock:
+ if idx < len(queue):
+ if idx == 0:
+ wan_model._interrupt = True
+ del queue[idx]
+ return update_queue_data()
+
+def update_queue_data():
+ with lock:
+ data = []
+ for item in queue:
+ truncated_prompt = (item['prompt'][:97] + '...') if len(item['prompt']) > 100 else item['prompt']
+ full_prompt = item['prompt'].replace('"', '&quot;')
+ prompt_cell = f'<span title="{full_prompt}">{truncated_prompt}</span>'
+ data.append([
+ item.get('status', "Starting"),
+ item.get('repeats', "0/0"),
+ item.get('progress', "0.0%"),
+ item.get('steps', ''),
+ item.get('time', '--'),
+ prompt_cell,
+ "↑",
+ "↓",
+ "✖"
+ ])
+ return data
+
def _parse_args():
parser = argparse.ArgumentParser(
description="Generate a video from a text prompt or image using Gradio")
@@@ -513,9 -300,9 +517,10 @@@ if not Path(server_config_filename).is_
"metadata_type": "metadata",
"default_ui": "t2v",
"boost" : 1,
+ "clear_file_list" : 0,
"vae_config": 0,
- "profile" : profile_type.LowRAM_LowVRAM }
+ "profile" : profile_type.LowRAM_LowVRAM,
+ "reload_model": 2 }
with open(server_config_filename, "w", encoding="utf-8") as writer:
writer.write(json.dumps(server_config))
@@@ -956,7 -742,7 +960,8 @@@ def apply_changes( state
metadata_choice,
default_ui_choice ="t2v",
boost_choice = 1,
+ clear_file_list = 0,
+ reload_choice = 1
):
if args.lock_config:
return
@@@ -975,7 -761,7 +980,8 @@@
"metadata_choice": metadata_choice,
"default_ui" : default_ui_choice,
"boost" : boost_choice,
+ "clear_file_list" : clear_file_list
+ "reload_model" : reload_choice,
}
if Path(server_config_filename).is_file():
@@@ -1280,160 -1184,199 +1292,189 @@@ def generate_video
if seed == None or seed <0:
seed = random.randint(0, 999999999)
+ global file_list
- state["file_list"] = file_list
+ clear_file_list = server_config.get("clear_file_list", 0)
+ file_list = state.get("file_list", [])
+ if clear_file_list > 0:
+ file_list_current_size = len(file_list)
+ keep_file_from = max(file_list_current_size - clear_file_list, 0)
+ files_removed = keep_file_from
+ choice = state.get("selected",0)
+ choice = max(choice- files_removed, 0)
+ file_list = file_list[ keep_file_from: ]
+ else:
+ file_list = []
+ choice = 0
+ state["selected"] = choice
+ state["file_list"] = file_list
+
global save_path
os.makedirs(save_path, exist_ok=True)
- abort = False
- if trans.enable_teacache:
- trans.teacache_counter = 0
- trans.num_steps = num_inference_steps
- trans.teacache_skipped_steps = 0
- trans.previous_residual_uncond = None
- trans.previous_residual_cond = None
video_no = 0
- total_video = repeat_generation * len(prompts)
- state["total_video"] = total_video
- extra_generation = 0
+ abort = False
- start_time = time.time()
- state["prompts_max"] = len(prompts)
- for no, prompt in enumerate(prompts):
- state["prompt"] = prompt
- repeat_no = 0
- state["prompt_no"] = no
- extra_generation = 0
- yield f"Prompt No{no}"
- while True:
- extra_orders = state.get("extra_orders",0)
- state["extra_orders"] = 0
- extra_generation += extra_orders
- state["total_generation"] = repeat_generation + extra_generation
- # total_video += (len(prompts)- no) * extra_orders
- total_video += extra_orders
- if abort or repeat_no >= (repeat_generation + extra_generation):
- break
-
+ repeats = f"{video_no}/{repeat_generation}"
+ callback = build_callback(task_id, state, trans, num_inference_steps, repeats)
+ offload.shared_state["callback"] = callback
+ gc.collect()
+ torch.cuda.empty_cache()
+ wan_model._interrupt = False
+ for i in range(repeat_generation):
+ try:
+ with tracker_lock:
++ start_time = time.time()
+ progress_tracker[task_id] = {
+ 'current_step': 0,
+ 'total_steps': num_inference_steps,
- 'start_time': time.time(),
- 'last_update': time.time(),
++ 'start_time': start_time,
++ 'last_update': start_time,
+ 'repeats': f"{video_no}/{repeat_generation}",
+ 'status': "Encoding Prompt"
+ }
+ if trans.enable_teacache:
+ trans.teacache_counter = 0
+ trans.num_steps = num_inference_steps
+ trans.teacache_skipped_steps = 0
+ trans.previous_residual_uncond = None
+ trans.previous_residual_cond = None
+
video_no += 1
- status = f"Video {video_no}/{total_video}"
- state["video_no"] = video_no
- state["progress_status"] = status
- state["progress_phase"] = (" - Encoding Prompt", -1 )
- progress(0, desc=status + " - Encoding Prompt" )
- callback = build_callback(state, trans, progress, status, num_inference_steps)
- offload.shared_state["callback"] = callback
-
+ if image2video:
+ samples = wan_model.generate(
+ prompt,
+ image_to_continue.convert('RGB'),
+ image_to_end.convert('RGB') if image_to_end != None else None,
+ frame_num=(video_length // 4)* 4 + 1,
+ max_area=MAX_AREA_CONFIGS[resolution],
+ shift=flow_shift,
+ sampling_steps=num_inference_steps,
+ guide_scale=guidance_scale,
+ n_prompt=negative_prompt,
+ seed=seed,
+ offload_model=False,
+ callback=callback,
+ enable_RIFLEx = enable_RIFLEx,
+ VAE_tile_size = VAE_tile_size,
+ joint_pass = joint_pass,
+ slg_layers = slg_layers,
+ slg_start = slg_start/100,
+ slg_end = slg_end/100,
++ cfg_star_switch = cfg_star_switch,
++ cfg_zero_step = cfg_zero_step,
+ )
+ else:
+ samples = wan_model.generate(
+ prompt,
+ frame_num=(video_length // 4)* 4 + 1,
+ size=(width, height),
+ shift=flow_shift,
+ sampling_steps=num_inference_steps,
+ guide_scale=guidance_scale,
+ n_prompt=negative_prompt,
+ seed=seed,
+ offload_model=False,
+ callback=callback,
+ enable_RIFLEx = enable_RIFLEx,
+ VAE_tile_size = VAE_tile_size,
+ joint_pass = joint_pass,
+ slg_layers = slg_layers,
+ slg_start = slg_start/100,
+ slg_end = slg_end/100,
++ cfg_star_switch = cfg_star_switch,
++ cfg_zero_step = cfg_zero_step,
+ )
+ except Exception as e:
+ gen_in_progress = False
+ if temp_filename!= None and os.path.isfile(temp_filename):
+ os.remove(temp_filename)
- if(offload.last_offload_obj): offload.last_offload_obj.unload_all()
- if(trans): offload.unload_loras_from_model(trans)
++ offload.last_offload_obj.unload_all()
++ offload.unload_loras_from_model(trans)
+ # if compile:
+ # cache_size = torch._dynamo.config.cache_size_limit
+ # torch.compiler.reset()
+ # torch._dynamo.config.cache_size_limit = cache_size
gc.collect()
torch.cuda.empty_cache()
- wan_model._interrupt = False
- try:
- if image2video:
- samples = wan_model.generate(
- prompt,
- image_to_continue[no].convert('RGB'),
- image_to_end[no].convert('RGB') if image_to_end != None else None,
- frame_num=(video_length // 4)* 4 + 1,
- max_area=MAX_AREA_CONFIGS[resolution],
- shift=flow_shift,
- sampling_steps=num_inference_steps,
- guide_scale=guidance_scale,
- n_prompt=negative_prompt,
- seed=seed,
- offload_model=False,
- callback=callback,
- enable_RIFLEx = enable_RIFLEx,
- VAE_tile_size = VAE_tile_size,
- joint_pass = joint_pass,
- slg_layers = slg_layers,
- slg_start = slg_start/100,
- slg_end = slg_end/100,
- cfg_star_switch = cfg_star_switch,
- cfg_zero_step = cfg_zero_step,
- )
-
- else:
- samples = wan_model.generate(
- prompt,
- frame_num=(video_length // 4)* 4 + 1,
- size=(width, height),
- shift=flow_shift,
- sampling_steps=num_inference_steps,
- guide_scale=guidance_scale,
- n_prompt=negative_prompt,
- seed=seed,
- offload_model=False,
- callback=callback,
- enable_RIFLEx = enable_RIFLEx,
- VAE_tile_size = VAE_tile_size,
- joint_pass = joint_pass,
- slg_layers = slg_layers,
- slg_start = slg_start/100,
- slg_end = slg_end/100,
- cfg_star_switch = cfg_star_switch,
- cfg_zero_step = cfg_zero_step,
- )
- except Exception as e:
- gen_in_progress = False
- if temp_filename!= None and os.path.isfile(temp_filename):
- os.remove(temp_filename)
- offload.last_offload_obj.unload_all()
- offload.unload_loras_from_model(trans)
- # if compile:
- # cache_size = torch._dynamo.config.cache_size_limit
- # torch.compiler.reset()
- # torch._dynamo.config.cache_size_limit = cache_size
-
- gc.collect()
- torch.cuda.empty_cache()
- s = str(e)
- keyword_list = ["vram", "VRAM", "memory","allocat"]
- VRAM_crash= False
- if any( keyword in s for keyword in keyword_list):
- VRAM_crash = True
- else:
- stack = traceback.extract_stack(f=None, limit=5)
- for frame in stack:
- if any( keyword in frame.name for keyword in keyword_list):
- VRAM_crash = True
- break
- state["prompt"] = ""
- if VRAM_crash:
- raise gr.Error("The generation of the video has encountered an error: it is likely that you have unsufficient VRAM and you should therefore reduce the video resolution or its number of frames.")
- else:
- raise gr.Error(f"The generation of the video has encountered an error, please check your terminal for more information. '{s}'")
-
- if trans.enable_teacache:
- print(f"Teacache Skipped Steps:{trans.teacache_skipped_steps}/{num_inference_steps}" )
- trans.previous_residual_uncond = None
- trans.previous_residual_cond = None
+ s = str(e)
+ keyword_list = ["vram", "VRAM", "memory","allocat"]
+ VRAM_crash= False
+ if any( keyword in s for keyword in keyword_list):
+ VRAM_crash = True
+ else:
+ stack = traceback.extract_stack(f=None, limit=5)
+ for frame in stack:
+ if any( keyword in frame.name for keyword in keyword_list):
+ VRAM_crash = True
+ break
+ state["prompt"] = ""
+ if VRAM_crash:
+ raise gr.Error("The generation of the video has encountered an error: it is likely that you have unsufficient VRAM and you should therefore reduce the video resolution or its number of frames.")
+ else:
+ raise gr.Error(f"The generation of the video has encountered an error, please check your terminal for more information. '{s}'")
+ finally:
+ with tracker_lock:
+ if task_id in progress_tracker:
+ del progress_tracker[task_id]
+
+ if trans.enable_teacache:
+ print(f"Teacache Skipped Steps:{trans.teacache_skipped_steps}/{num_inference_steps}" )
+ trans.previous_residual_uncond = None
+ trans.previous_residual_cond = None
+
+ if samples != None:
+ samples = samples.to("cpu")
+ offload.last_offload_obj.unload_all()
+ gc.collect()
+ torch.cuda.empty_cache()
- if samples != None:
- samples = samples.to("cpu")
- offload.last_offload_obj.unload_all()
- gc.collect()
- torch.cuda.empty_cache()
+ if samples == None:
+ end_time = time.time()
+ abort = True
+ state["prompt"] = ""
++ yield f"Video generation was aborted. Total Generation Time: {end_time-start_time:.1f}s"
+ else:
+ sample = samples.cpu()
+ # video = rearrange(sample.cpu().numpy(), "c t h w -> t h w c")
- if samples == None:
+ time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%Hh%Mm%Ss")
+ if os.name == 'nt':
+ file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:50]).strip()}.mp4"
+ else:
+ file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:100]).strip()}.mp4"
+ video_path = os.path.join(save_path, file_name)
+ cache_video(
+ tensor=sample[None],
+ save_file=video_path,
+ fps=16,
+ nrow=1,
+ normalize=True,
+ value_range=(-1, 1))
-
++
+ configs = get_settings_dict(state, use_image2video, prompt, 0 if image_to_end == None else 1 , video_length, raw_resolution, num_inference_steps, seed, repeat_generation, multi_images_gen_type, guidance_scale, flow_shift, negative_prompt, loras_choices,
- loras_mult_choices, tea_cache , tea_cache_start_step_perc, RIFLEx_setting, slg_switch, slg_layers, slg_start, slg_end)
++ loras_mult_choices, tea_cache , tea_cache_start_step_perc, RIFLEx_setting, slg_switch, slg_layers, slg_start, slg_end, cfg_star_switch, cfg_zero_step)
+
+ metadata_choice = server_config.get("metadata_choice","metadata")
+ if metadata_choice == "json":
+ with open(video_path.replace('.mp4', '.json'), 'w') as f:
+ json.dump(configs, f, indent=4)
+ elif metadata_choice == "metadata":
+ from mutagen.mp4 import MP4
+ file = MP4(video_path)
+ file.tags['©cmt'] = [json.dumps(configs)]
+ file.save()
+
+ print(f"New video saved to Path: "+video_path)
+ file_list.append(video_path)
++ if video_no < total_video:
++ yield status
++ else:
+ end_time = time.time()
- abort = True
+ state["prompt"] = ""
- yield f"Video generation was aborted. Total Generation Time: {end_time-start_time:.1f}s"
- else:
- sample = samples.cpu()
- # video = rearrange(sample.cpu().numpy(), "c t h w -> t h w c")
++ yield f"Total Generation Time: {end_time-start_time:.1f}s"
+ seed += 1
++ repeat_no += 1
+
- time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%Hh%Mm%Ss")
- if os.name == 'nt':
- file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:50]).strip()}.mp4"
- else:
- file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:100]).strip()}.mp4"
- video_path = os.path.join(save_path, file_name)
- cache_video(
- tensor=sample[None],
- save_file=video_path,
- fps=16,
- nrow=1,
- normalize=True,
- value_range=(-1, 1))
-
- configs = get_settings_dict(state, use_image2video, prompt, 0 if image_to_end == None else 1 , video_length, raw_resolution, num_inference_steps, seed, repeat_generation, multi_images_gen_type, guidance_scale, flow_shift, negative_prompt, loras_choices,
- loras_mult_choices, tea_cache , tea_cache_start_step_perc, RIFLEx_setting, slg_switch, slg_layers, slg_start, slg_end, cfg_star_switch, cfg_zero_step)
-
- metadata_choice = server_config.get("metadata_choice","metadata")
- if metadata_choice == "json":
- with open(video_path.replace('.mp4', '.json'), 'w') as f:
- json.dump(configs, f, indent=4)
- elif metadata_choice == "metadata":
- from mutagen.mp4 import MP4
- file = MP4(video_path)
- file.tags['©cmt'] = [json.dumps(configs)]
- file.save()
-
- print(f"New video saved to Path: "+video_path)
- file_list.append(video_path)
- if video_no < total_video:
- yield status
- else:
- end_time = time.time()
- state["prompt"] = ""
- yield f"Total Generation Time: {end_time-start_time:.1f}s"
- seed += 1
- repeat_no += 1
+ last_model_type = image2video
if temp_filename!= None and os.path.isfile(temp_filename):
os.remove(temp_filename)
@@@ -2116,43 -2058,51 +2179,46 @@@ def generate_video_tab(image2video=Fals
refresh_lora_btn.click(refresh_lora_list, inputs=[state, lset_name,loras_choices], outputs=[lset_name, loras_choices])
refresh_lora_btn2.click(refresh_lora_list, inputs=[state, lset_name,loras_choices], outputs=[lset_name, loras_choices])
download_loras_btn.click(fn=download_loras, inputs=[], outputs=[download_status_row, download_status, presets_column, loras_column]).then(fn=refresh_lora_list, inputs=[state, lset_name,loras_choices], outputs=[lset_name, loras_choices])
- gen_status.change(refresh_gallery, inputs = [state, gen_info], outputs = [output, gen_info] )
- abort_btn.click(abort_generation,state,abort_btn )
output.select(select_video, state, None )
- onemore_btn.click(fn=one_more_video,inputs=[state], outputs= [state])
- generate_btn.click(fn=prepare_generate_video,inputs=[], outputs= [generate_btn, onemore_btn]
- ).then(
- fn=validate_wizard_prompt, inputs =[state, wizard_prompt_activated_var, wizard_variables_var, prompt, wizard_prompt, *prompt_vars] , outputs= [prompt]
- ).then(
- fn=generate_video,
- inputs=[
- prompt,
- negative_prompt,
- resolution,
- video_length,
- seed,
- num_inference_steps,
- guidance_scale,
- flow_shift,
- embedded_guidance_scale,
- repeat_generation,
- multi_images_gen_type,
- tea_cache_setting,
- tea_cache_start_step_perc,
- loras_choices,
- loras_mult_choices,
- image_prompt_type_radio,
- image_to_continue,
- image_to_end,
- video_to_continue,
- max_frames,
- RIFLEx_setting,
- slg_switch,
- slg_layers,
- slg_start_perc,
- slg_end_perc,
- cfg_star_switch,
- cfg_zero_step,
- state,
- gr.State(image2video)
- ],
- outputs= [gen_status]
- ).then(
- finalize_gallery,
- [state],
- [output , abort_btn, generate_btn, onemore_btn, gen_info]
+ original_inputs = [
+ prompt,
+ negative_prompt,
+ resolution,
+ video_length,
+ seed,
+ num_inference_steps,
+ guidance_scale,
+ flow_shift,
+ embedded_guidance_scale,
+ repeat_generation,
+ multi_images_gen_type,
+ tea_cache_setting,
+ tea_cache_start_step_perc,
+ loras_choices,
+ loras_mult_choices,
++ image_prompt_type_radio,
+ image_to_continue,
+ image_to_end,
+ video_to_continue,
+ max_frames,
+ RIFLEx_setting,
+ slg_switch,
+ slg_layers,
+ slg_start_perc,
+ slg_end_perc,
++ cfg_star_switch,
++ cfg_zero_step,
+ state,
+ gr.State(image2video)
+ ]
+
+ #generate_btn.click(
+ # fn=validate_wizard_prompt, inputs =[state, wizard_prompt_activated_var, wizard_variables_var, prompt, wizard_prompt, *prompt_vars] , outputs= [prompt]
+ #).then(
+ generate_btn.click(
+ fn=process_prompt_and_add_tasks,
+ inputs=original_inputs,
+ outputs=queue_df
)
return loras_choices, lset_name, header, state
@@@ -2276,17 -2226,24 +2342,32 @@@ def generate_configuration_tab()
("Add metadata to video", "metadata"),
("Neither", "none")
],
- value=metadata,
+ value=server_config.get("metadata_type", "metadata"),
label="Metadata Handling"
)
+ reload_choice = gr.Dropdown(
+ choices=[
+ ("When changing tabs", 1),
+ ("When pressing generate", 2),
+ ],
+ value=server_config.get("reload_model",2),
+ label="Reload model"
+ )
+
+ clear_file_list_choice = gr.Dropdown(
+ choices=[
+ ("None", 0),
+ ("Keep the last video", 1),
+ ("Keep the last 5 videos", 5),
+ ("Keep the last 10 videos", 10),
+ ("Keep the last 20 videos", 20),
+ ("Keep the last 30 videos", 30),
+ ],
+ value=server_config.get("clear_file_list", 0),
+ label="Keep Previously Generated Videos when starting a Generation Batch"
+ )
+
+
msg = gr.Markdown()
apply_btn = gr.Button("Apply Changes")
apply_btn.click(
@@@ -2304,7 -2261,7 +2385,8 @@@
metadata_choice,
default_ui_choice,
boost_choice,
+ clear_file_list_choice,
+ reload_choice,
],
outputs= msg
)
@@@ -2326,24 -2286,6 +2411,21 @@@ def on_tab_select(t2v_state, i2v_state
new_i2v = evt.index == 1
use_image2video = new_i2v
+ if(server_config.get("reload_model",2) == 1):
+ with lock:
+ queue_empty = len(queue) == 0
+ if queue_empty:
+ global wan_model, offloadobj
+ if wan_model is not None:
+ if offloadobj is not None:
+ offloadobj.release()
+ offloadobj = None
+ wan_model = None
+ gc.collect()
+ torch.cuda.empty_cache()
+ wan_model, offloadobj, trans = load_models(use_image2video)
+ del trans
+
- t2v_header = generate_header(transformer_filename_t2v, compile, attention_mode)
- i2v_header = generate_header(transformer_filename_i2v, compile, attention_mode)
-
if new_t2v:
lora_model_filename = t2v_state["loras_model"]
if ("1.3B" in transformer_filename_t2v and not "1.3B" in lora_model_filename or "14B" in transformer_filename_t2v and not "14B" in lora_model_filename):
@@@ -2385,92 -2327,9 +2467,92 @@@ def create_demo()
margin: 0 20px;
white-space: nowrap;
}
+ .queue-item {
+ border: 1px solid #ccc;
+ padding: 10px;
+ margin: 5px 0;
+ border-radius: 5px;
+ }
+ .current {
+ background: #f8f9fa;
+ border-left: 4px solid #007bff;
+ }
+ .task-header {
+ display: flex;
+ justify-content: space-between;
+ margin-bottom: 5px;
+ }
+ .progress-container {
+ height: 10px;
+ background: #e9ecef;
+ border-radius: 5px;
+ overflow: hidden;
+ }
+ .progress-bar {
+ height: 100%;
+ background: #007bff;
+ transition: width 0.3s ease;
+ }
+ .task-details {
+ display: flex;
+ justify-content: space-between;
+ font-size: 0.9em;
+ color: #6c757d;
+ margin-top: 5px;
+ }
+ .task-prompt {
+ font-size: 0.8em;
+ color: #868e96;
+ margin-top: 5px;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+ #queue_df td:nth-child(-n+6) {
+ cursor: default !important;
+ pointer-events: none;
+ }
+ #queue_df th {
+ pointer-events: none;
+ }
+ #queue_df .tabulator-col {
+ pointer-events: none;
+ }
+ #queue_df .tabulator-col .tabulator-arrow {
+ display: none;
+ }
+ #queue_df table {
+ overflow: hidden !important;
+ }
+
+ #queue_df::-webkit-scrollbar {
+ display: none !important;
+ }
+ #queue_df {
+ scrollbar-width: none !important;
+ -ms-overflow-style: none !important;
+ }
+ #queue_df td:nth-child(1) {
+ width: 100px;
+ }
+ #queue_df td:nth-child(6) {
+ width: 300px;
+ }
+ #queue_df td:nth-child(7),
+ #queue_df td:nth-child(8),
+ #queue_df td:nth-child(9) {
+ cursor: pointer;
+ text-align: center;
+ font-weight: bold;
+ }
+ #queue_df td:nth-child(7):hover,
+ #queue_df td:nth-child(8):hover,
+ #queue_df td:nth-child(9):hover {
+ background-color: #e0e0e0;
+ }
"""
with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="sky", neutral_hue="slate", text_size="md")) as demo:
- gr.Markdown("<div align=center><H1>Wan 2.1<SUP>GP</SUP> v3.1 <FONT SIZE=4>by <I>DeepBeepMeep</I></FONT> <FONT SIZE=3> (<A HREF='https://github.com/deepbeepmeep/Wan2GP'>Updates</A>)</FONT SIZE=3></H1></div>")
+ gr.Markdown("<div align=center><H1>Wan 2.1<SUP>GP</SUP> v3.2 <FONT SIZE=4>by <I>DeepBeepMeep</I></FONT> <FONT SIZE=3> (<A HREF='https://github.com/deepbeepmeep/Wan2GP'>Updates</A>)</FONT SIZE=3></H1></div>")
gr.Markdown("<FONT SIZE=3>Welcome to Wan 2.1GP a super fast and low VRAM AI Video Generator !</FONT>")
with gr.Accordion("Click here for some Info on how to use Wan2GP", open = False):