Python
Merge remote-tracking branch 'upstream/main' into queues
Chris Malonecf5358431ac0
diff --cc gradio_server.pyindex 237b9dd,47c9f75..4e547bb--- a/gradio_server.py+++ b/gradio_server.py@@@ -1384,60 -1263,14 +1408,61 @@@ def generate_videotrans.previous_residual_cond = Nonevideo_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,++ cfg_zero_step = cfg_zero_step,++ add_frames_for_end_image = not "Fun" in transformer_filename_i2v+ )+ 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_sizegc.collect()torch.cuda.empty_cache()@@@ -2258,53 -2090,53 +2283,53 @@@ def generate_video_tab(image2video=Falsrefresh_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+ )+ close_modal_button.click(+ lambda: gr.update(visible=False),+ inputs=[],+ outputs=[modal_container])- return loras_choices, lset_name, header, state+ return loras_column, loras_choices, presets_column, lset_name, header, statedef generate_configuration_tab():state_dict = {}@@@ -2495,44 -2321,51 +2523,66 @@@ def on_tab_select(t2v_state, i2v_statenew_i2v = evt.index == 1use_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+- 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):+ if new_t2v or new_i2v:+ state = i2v_state if new_i2v else t2v_state+ lora_model_filename = state["loras_model"]+ model_filename = model_needed(new_i2v)+ if ("1.3B" in model_filename and not "1.3B" in lora_model_filename or "14B" in model_filename and not "14B" in lora_model_filename):lora_dir = get_lora_dir(new_i2v)loras, loras_names, loras_presets, _, _, _, _ = setup_loras(new_i2v, None, lora_dir, lora_preselected_preset, None)- t2v_state["loras"] = loras- t2v_state["loras_names"] = loras_names- t2v_state["loras_presets"] = loras_presets- t2v_state["loras_model"] = transformer_filename_t2v+ state["loras"] = loras+ state["loras_names"] = loras_names+ state["loras_presets"] = loras_presets+ state["loras_model"] = model_filename- t2v_advanced = t2v_state["advanced"]+ advanced = state["advanced"]new_loras_choices = [(name, str(i)) for i, name in enumerate(loras_names)]- lset_choices = [(preset, preset) for preset in loras_presets] + [(get_new_preset_msg(t2v_advanced), "")]- return [- gr.Dropdown(choices=new_loras_choices, visible=len(loras_names)>0, value=[]),- gr.Dropdown(choices=lset_choices, value=get_new_preset_msg(t2v_advanced), visible=len(loras_names)>0),- t2v_header,- gr.Dropdown(),- gr.Dropdown(),- i2v_header,- ]- return [gr.Dropdown(), gr.Dropdown(), t2v_header,- gr.Dropdown(), gr.Dropdown(), i2v_header]+ lset_choices = [(preset, preset) for preset in loras_presets] + [(get_new_preset_msg(advanced), "")]+ visible = len(loras_names)>0+ if new_t2v:+ return [+ gr.Column(visible= visible),+ gr.Dropdown(choices=new_loras_choices, visible=visible, value=[]),+ gr.Column(visible= visible),+ gr.Dropdown(choices=lset_choices, value=get_new_preset_msg(advanced), visible=visible),+ t2v_header,+ gr.Column(),+ gr.Dropdown(),+ gr.Column(),+ gr.Dropdown(),+ i2v_header,+ ]+ else:+ return [+ gr.Column(),+ gr.Dropdown(),+ gr.Column(),+ gr.Dropdown(),+ t2v_header,+ gr.Column(visible= visible),+ gr.Dropdown(choices=new_loras_choices, visible=visible, value=[]),+ gr.Column(visible= visible),+ gr.Dropdown(choices=lset_choices, value=get_new_preset_msg(advanced), visible=visible),+ i2v_header,+ ]++ return [gr.Column(), gr.Dropdown(), gr.Column(), gr.Dropdown(), t2v_header,+ gr.Column(), gr.Dropdown(), gr.Column(), gr.Dropdown(), i2v_header]def create_demo():@@@ -2551,130 -2384,9 +2601,130 @@@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 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: auto;+ min-width: 200px;+ }+ #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;+ width: 60px;+ text-align: center;+ padding: 2px !important;+ cursor: pointer;+ }+ #queue_df td:nth-child(10) img,+ #queue_df td:nth-child(11) img {+ max-width: 50px;+ max-height: 50px;+ object-fit: contain;+ display: block;+ margin: auto;+ }+ #image-modal-container {+ position: fixed;+ top: 0;+ left: 0;+ width: 100%;+ height: 100%;+ background-color: rgba(0, 0, 0, 0.7);+ justify-content: center;+ align-items: center;+ z-index: 1000;+ padding: 20px;+ box-sizing: border-box;+ }+ #image-modal-container > div {+ background-color: white;+ padding: 15px;+ border-radius: 8px;+ max-width: 90%;+ max-height: 90%;+ overflow: auto;+ position: relative;+ display: flex;+ flex-direction: column;+ }+ #image-modal-container img {+ max-width: 100%;+ max-height: 80vh;+ object-fit: contain;+ margin-top: 10px;+ }+ #image-modal-close-button-row {+ display: flex;+ justify-content: flex-end;+ }+ #image-modal-close-button-row button {+ cursor: pointer;+ }"""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.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("<div align=center><H1>Wan 2.1<SUP>GP</SUP> v3.3 <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):