Tophness2022 commited on
Commit
2217223
·
1 Parent(s): 197c1dd

move load/save/clear buttons to accordion

Browse files
Files changed (1) hide show
  1. wgp.py +30 -19
wgp.py CHANGED
@@ -3479,7 +3479,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3479
  with gr.Row():
3480
  onemore_btn = gr.Button("One More Sample Please !")
3481
  abort_btn = gr.Button("Abort")
3482
-
3483
  queue_df = gr.DataFrame(
3484
  headers=["Qty","Prompt", "Length","Steps","", "", "", "", ""],
3485
  datatype=[ "str","markdown","str", "markdown", "markdown", "markdown", "str", "str", "str"],
@@ -3489,14 +3489,14 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3489
  wrap=True,
3490
  value=[],
3491
  line_breaks= True,
3492
- visible= False,
3493
  elem_id="queue_df"
3494
  )
3495
- with gr.Row():
3496
- queue_zip_base64_output = gr.Text(visible=False)
3497
- save_queue_btn = gr.DownloadButton("Save Queue", size="sm")
3498
- load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
3499
- clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
3500
  trigger_zip_download_js = """
3501
  (base64String) => {
3502
  if (!base64String) {
@@ -3544,9 +3544,9 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3544
  inputs=[load_queue_btn, state],
3545
  outputs=[queue_df]
3546
  ).then(
3547
- fn=lambda s: gr.update(visible=bool(get_gen_info(s).get("queue",[]))),
3548
  inputs=[state],
3549
- outputs=[current_gen_column]
3550
  )
3551
 
3552
  clear_queue_btn.click(
@@ -3554,9 +3554,9 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3554
  inputs=[state],
3555
  outputs=[queue_df]
3556
  ).then(
3557
- fn=lambda: gr.update(visible=False),
3558
  inputs=None,
3559
- outputs=[current_gen_column]
3560
  )
3561
 
3562
  extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
@@ -3639,6 +3639,10 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3639
  ).then(finalize_generation,
3640
  inputs= [state],
3641
  outputs= [output, abort_btn, generate_btn, add_to_queue_btn, current_gen_column, gen_info]
 
 
 
 
3642
  ).then(unload_model_if_needed,
3643
  inputs= [state],
3644
  outputs= []
@@ -3653,6 +3657,10 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3653
  ).then(fn=process_prompt_and_add_tasks,
3654
  inputs = [state, model_choice],
3655
  outputs=queue_df
 
 
 
 
3656
  ).then(
3657
  fn=update_status,
3658
  inputs = [state],
@@ -3670,7 +3678,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
3670
  gen_info,
3671
  prompt, wizard_prompt, wizard_prompt_activated_var, wizard_variables_var,
3672
  prompt_column_advanced, prompt_column_wizard, prompt_column_wizard_vars,
3673
- advanced_row, image_prompt_column, video_prompt_column,
3674
  *prompt_vars
3675
  )
3676
 
@@ -4153,7 +4161,7 @@ def create_demo():
4153
  gen_info,
4154
  prompt, wizard_prompt, wizard_prompt_activated_var, wizard_variables_var,
4155
  prompt_column_advanced, prompt_column_wizard, prompt_column_wizard_vars,
4156
- advanced_row, image_prompt_column, video_prompt_column,
4157
  *prompt_vars_outputs
4158
  ) = generate_video_tab(model_choice=model_choice, header=header)
4159
  with gr.Tab("Informations"):
@@ -4170,7 +4178,8 @@ def create_demo():
4170
  def run_autoload_and_prepare_ui(current_state):
4171
  df_update, loaded_flag, modified_state = autoload_queue(current_state)
4172
  should_start_processing = loaded_flag
4173
- return df_update, gr.update(visible=loaded_flag), should_start_processing, modified_state
 
4174
 
4175
  def start_processing_if_needed(should_start, current_state):
4176
  if not isinstance(current_state, dict) or 'gen' not in current_state:
@@ -4179,18 +4188,20 @@ def create_demo():
4179
  if should_start:
4180
  yield from process_tasks(current_state)
4181
  else:
4182
- yield "Autoload complete. Processing not started."
4183
 
4184
  def finalize_generation_with_state(current_state):
4185
  if not isinstance(current_state, dict) or 'gen' not in current_state:
4186
- return gr.update(), gr.update(interactive=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False, value=""), current_state
 
4187
  gallery_update, abort_btn_update, gen_btn_update, add_queue_btn_update, current_gen_col_update, gen_info_update = finalize_generation(current_state)
4188
- return gallery_update, abort_btn_update, gen_btn_update, add_queue_btn_update, current_gen_col_update, gen_info_update, current_state
 
4189
 
4190
  demo.load(
4191
  fn=run_autoload_and_prepare_ui,
4192
  inputs=[state],
4193
- outputs=[queue_df, current_gen_column, should_start_flag, state]
4194
  ).then(
4195
  fn=start_processing_if_needed,
4196
  inputs=[should_start_flag, state],
@@ -4199,7 +4210,7 @@ def create_demo():
4199
  ).then(
4200
  fn=finalize_generation_with_state,
4201
  inputs=[state],
4202
- outputs=[output, abort_btn, generate_btn, add_to_queue_btn, current_gen_column, gen_info, state],
4203
  trigger_mode="always_last"
4204
  )
4205
 
 
3479
  with gr.Row():
3480
  onemore_btn = gr.Button("One More Sample Please !")
3481
  abort_btn = gr.Button("Abort")
3482
+ with gr.Accordion("Queue Management", open=False) as queue_accordion:
3483
  queue_df = gr.DataFrame(
3484
  headers=["Qty","Prompt", "Length","Steps","", "", "", "", ""],
3485
  datatype=[ "str","markdown","str", "markdown", "markdown", "markdown", "str", "str", "str"],
 
3489
  wrap=True,
3490
  value=[],
3491
  line_breaks= True,
3492
+ visible= True,
3493
  elem_id="queue_df"
3494
  )
3495
+ with gr.Row():
3496
+ queue_zip_base64_output = gr.Text(visible=False)
3497
+ save_queue_btn = gr.DownloadButton("Save Queue", size="sm")
3498
+ load_queue_btn = gr.UploadButton("Load Queue", file_types=[".zip"], size="sm")
3499
+ clear_queue_btn = gr.Button("Clear Queue", size="sm", variant="stop")
3500
  trigger_zip_download_js = """
3501
  (base64String) => {
3502
  if (!base64String) {
 
3544
  inputs=[load_queue_btn, state],
3545
  outputs=[queue_df]
3546
  ).then(
3547
+ fn=lambda s: (gr.update(visible=bool(get_gen_info(s).get("queue",[]))), gr.Accordion(open=True)) if bool(get_gen_info(s).get("queue",[])) else (gr.update(visible=False), gr.update()),
3548
  inputs=[state],
3549
+ outputs=[current_gen_column, queue_accordion]
3550
  )
3551
 
3552
  clear_queue_btn.click(
 
3554
  inputs=[state],
3555
  outputs=[queue_df]
3556
  ).then(
3557
+ fn=lambda: (gr.update(visible=False), gr.Accordion(open=False)),
3558
  inputs=None,
3559
+ outputs=[current_gen_column, queue_accordion]
3560
  )
3561
 
3562
  extra_inputs = prompt_vars + [wizard_prompt, wizard_variables_var, wizard_prompt_activated_var, video_prompt_column, image_prompt_column,
 
3639
  ).then(finalize_generation,
3640
  inputs= [state],
3641
  outputs= [output, abort_btn, generate_btn, add_to_queue_btn, current_gen_column, gen_info]
3642
+ ).then(
3643
+ fn=lambda s: gr.Accordion(open=False) if len(get_gen_info(s).get("queue", [])) <= 1 else gr.update(),
3644
+ inputs=[state],
3645
+ outputs=[queue_accordion]
3646
  ).then(unload_model_if_needed,
3647
  inputs= [state],
3648
  outputs= []
 
3657
  ).then(fn=process_prompt_and_add_tasks,
3658
  inputs = [state, model_choice],
3659
  outputs=queue_df
3660
+ ).then(
3661
+ 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)
3662
+ inputs=[state],
3663
+ outputs=[queue_accordion]
3664
  ).then(
3665
  fn=update_status,
3666
  inputs = [state],
 
3678
  gen_info,
3679
  prompt, wizard_prompt, wizard_prompt_activated_var, wizard_variables_var,
3680
  prompt_column_advanced, prompt_column_wizard, prompt_column_wizard_vars,
3681
+ advanced_row, image_prompt_column, video_prompt_column, queue_accordion,
3682
  *prompt_vars
3683
  )
3684
 
 
4161
  gen_info,
4162
  prompt, wizard_prompt, wizard_prompt_activated_var, wizard_variables_var,
4163
  prompt_column_advanced, prompt_column_wizard, prompt_column_wizard_vars,
4164
+ advanced_row, image_prompt_column, video_prompt_column, queue_accordion,
4165
  *prompt_vars_outputs
4166
  ) = generate_video_tab(model_choice=model_choice, header=header)
4167
  with gr.Tab("Informations"):
 
4178
  def run_autoload_and_prepare_ui(current_state):
4179
  df_update, loaded_flag, modified_state = autoload_queue(current_state)
4180
  should_start_processing = loaded_flag
4181
+ accordion_update = gr.Accordion(open=True) if loaded_flag else gr.update()
4182
+ return df_update, gr.update(visible=loaded_flag), accordion_update, should_start_processing, modified_state
4183
 
4184
  def start_processing_if_needed(should_start, current_state):
4185
  if not isinstance(current_state, dict) or 'gen' not in current_state:
 
4188
  if should_start:
4189
  yield from process_tasks(current_state)
4190
  else:
4191
+ yield None
4192
 
4193
  def finalize_generation_with_state(current_state):
4194
  if not isinstance(current_state, dict) or 'gen' not in current_state:
4195
+ return gr.update(), gr.update(interactive=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False, value=""), gr.update(), current_state
4196
+
4197
  gallery_update, abort_btn_update, gen_btn_update, add_queue_btn_update, current_gen_col_update, gen_info_update = finalize_generation(current_state)
4198
+ accordion_update = gr.Accordion(open=False) if len(get_gen_info(current_state).get("queue", [])) <= 1 else gr.update()
4199
+ return gallery_update, abort_btn_update, gen_btn_update, add_queue_btn_update, current_gen_col_update, gen_info_update, accordion_update, current_state
4200
 
4201
  demo.load(
4202
  fn=run_autoload_and_prepare_ui,
4203
  inputs=[state],
4204
+ outputs=[queue_df, current_gen_column, queue_accordion, should_start_flag, state]
4205
  ).then(
4206
  fn=start_processing_if_needed,
4207
  inputs=[should_start_flag, state],
 
4210
  ).then(
4211
  fn=finalize_generation_with_state,
4212
  inputs=[state],
4213
+ outputs=[output, abort_btn, generate_btn, add_to_queue_btn, current_gen_column, gen_info, queue_accordion, state],
4214
  trigger_mode="always_last"
4215
  )
4216