DeepBeepMeep commited on
Commit
4cb7e96
·
2 Parent(s): 25e8685b7aa11b

Merge branch 'dev3' of https://github.com/deepbeepmeep/Wan2GP into dev3

Browse files
Files changed (1) hide show
  1. wgp.py +94 -6
wgp.py CHANGED
@@ -705,6 +705,15 @@ def clear_queue_action(state):
705
  if aborted_current or cleared_pending:
706
  gen["prompts_max"] = 0
707
 
 
 
 
 
 
 
 
 
 
708
  if aborted_current and cleared_pending:
709
  gr.Info("Queue cleared and current generation aborted.")
710
  elif aborted_current:
@@ -722,6 +731,12 @@ def quit_application():
722
  import signal
723
  os.kill(os.getpid(), signal.SIGINT)
724
 
 
 
 
 
 
 
725
  def autosave_queue():
726
  global global_queue_ref
727
  if not global_queue_ref:
@@ -3598,6 +3613,55 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3598
  load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
3599
  clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
3600
  quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3601
  trigger_zip_download_js = """
3602
  (base64String) => {
3603
  if (!base64String) {
@@ -3629,6 +3693,35 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3629
  }
3630
  }
3631
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3632
  save_queue_btn.click(
3633
  fn=save_queue_action,
3634
  inputs=[state],
@@ -3682,11 +3775,6 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3682
  inputs=None,
3683
  outputs=[current_gen_column, queue_accordion]
3684
  )
3685
- quit_button.click(
3686
- fn=quit_application,
3687
- inputs=[],
3688
- outputs=[]
3689
- )
3690
 
3691
  extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
3692
  prompt_column_advanced, prompt_column_wizard_vars, prompt_column_wizard, lset_name, advanced_row] # show_advanced presets_column,
@@ -3787,7 +3875,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3787
  inputs = [state, model_choice],
3788
  outputs=queue_df
3789
  ).then(
3790
- fn=lambda s: gr.Accordion(open=True) if len(get_gen_info(s).get("queue", [])) > 1 else gr.update(), # Expand if queue has items (len > 1 assumes placeholder)
3791
  inputs=[state],
3792
  outputs=[queue_accordion]
3793
  ).then(
 
705
  if aborted_current or cleared_pending:
706
  gen["prompts_max"] = 0
707
 
708
+ if cleared_pending:
709
+ try:
710
+ if os.path.isfile(AUTOSAVE_FILENAME):
711
+ os.remove(AUTOSAVE_FILENAME)
712
+ print(f"Clear Queue: Deleted autosave file '{AUTOSAVE_FILENAME}'.")
713
+ except OSError as e:
714
+ print(f"Clear Queue: Error deleting autosave file '{AUTOSAVE_FILENAME}': {e}")
715
+ gr.Warning(f"Could not delete the autosave file '{AUTOSAVE_FILENAME}'. You may need to remove it manually.")
716
+
717
  if aborted_current and cleared_pending:
718
  gr.Info("Queue cleared and current generation aborted.")
719
  elif aborted_current:
 
731
  import signal
732
  os.kill(os.getpid(), signal.SIGINT)
733
 
734
+ def request_quit_confirmation():
735
+ return gr.update(visible=False), gr.update(visible=True)
736
+
737
+ def cancel_quit_confirmation():
738
+ return gr.update(visible=True), gr.update(visible=False)
739
+
740
  def autosave_queue():
741
  global global_queue_ref
742
  if not global_queue_ref:
 
3613
  load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
3614
  clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
3615
  quit_button = gr.Button("Save and Quit", size="sm", variant="secondary")
3616
+ with gr.Row(visible=False) as quit_confirmation_row:
3617
+ gr.Markdown("Quitting in 5 seconds...", elem_id="quit_timer_label")
3618
+ confirm_quit_button = gr.Button("Confirm Quit Now", elem_id="comfirm_quit_btn_hidden", size="sm", variant="stop")
3619
+ cancel_quit_button = gr.Button("Cancel Quit", size="sm", variant="secondary")
3620
+ hidden_force_quit_trigger = gr.Button("force_quit", visible=False, elem_id="force_quit_btn_hidden")
3621
+
3622
+ start_quit_timer_js = """
3623
+ () => {
3624
+ function findAndClickGradioButton(elemId) {
3625
+ const gradioApp = document.querySelector('gradio-app') || document;
3626
+ const button = gradioApp.querySelector(`#${elemId}`);
3627
+ if (button) {
3628
+ button.click();
3629
+ }
3630
+ }
3631
+ window.quitTimerId = setTimeout(() => {
3632
+ }, 5000);
3633
+ let countdown = 5;
3634
+ const label = document.getElementById('quit_timer_label');
3635
+ if (label) {
3636
+ label.innerText = `Quitting in ${countdown}...`;
3637
+ window.quitCountdownInterval = setInterval(() => {
3638
+ countdown--;
3639
+ if (countdown > 0) {
3640
+ label.innerText = `Quitting in ${countdown}...`;
3641
+ } else {
3642
+ clearInterval(window.quitCountdownInterval);
3643
+ findAndClickGradioButton('comfirm_quit_btn_hidden');
3644
+ }
3645
+ }, 1000);
3646
+ }
3647
+ }
3648
+ """
3649
+
3650
+ cancel_quit_timer_js = """
3651
+ () => {
3652
+ if (window.quitTimerId) {
3653
+ clearTimeout(window.quitTimerId);
3654
+ window.quitTimerId = null;
3655
+ }
3656
+ if(window.quitCountdownInterval) {
3657
+ clearInterval(window.quitCountdownInterval);
3658
+ window.quitCountdownInterval = null;
3659
+ }
3660
+ const label = document.getElementById('quit_timer_label');
3661
+ if(label) { label.innerText = 'Quit cancelled.'; }
3662
+ }
3663
+ """
3664
+
3665
  trigger_zip_download_js = """
3666
  (base64String) => {
3667
  if (!base64String) {
 
3693
  }
3694
  }
3695
  """
3696
+
3697
+ quit_button.click(
3698
+ fn=request_quit_confirmation,
3699
+ inputs=[],
3700
+ outputs=[quit_button, quit_confirmation_row]
3701
+ ).then(
3702
+ fn=None, inputs=None, outputs=None, js=start_quit_timer_js
3703
+ )
3704
+
3705
+ confirm_quit_button.click(
3706
+ fn=quit_application,
3707
+ inputs=[],
3708
+ outputs=[]
3709
+ )
3710
+
3711
+ cancel_quit_button.click(
3712
+ fn=cancel_quit_confirmation,
3713
+ inputs=[],
3714
+ outputs=[quit_button, quit_confirmation_row]
3715
+ ).then(
3716
+ fn=None, inputs=None, outputs=None, js=cancel_quit_timer_js
3717
+ )
3718
+
3719
+ hidden_force_quit_trigger.click(
3720
+ fn=quit_application,
3721
+ inputs=[],
3722
+ outputs=[]
3723
+ )
3724
+
3725
  save_queue_btn.click(
3726
  fn=save_queue_action,
3727
  inputs=[state],
 
3775
  inputs=None,
3776
  outputs=[current_gen_column, queue_accordion]
3777
  )
 
 
 
 
 
3778
 
3779
  extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
3780
  prompt_column_advanced, prompt_column_wizard_vars, prompt_column_wizard, lset_name, advanced_row] # show_advanced presets_column,
 
3875
  inputs = [state, model_choice],
3876
  outputs=queue_df
3877
  ).then(
3878
+ fn=lambda s: gr.Accordion(open=True) if len(get_gen_info(s).get("queue", [])) > 1 else gr.update(),
3879
  inputs=[state],
3880
  outputs=[queue_accordion]
3881
  ).then(