Refresh the Preset menu after saving a preset

This commit is contained in:
oobabooga 2023-11-18 14:03:42 -08:00
parent 83b64e7fc1
commit 47d9e2618b

View File

@ -37,6 +37,14 @@ def create_ui():
shared.gradio['delete_character_confirm'] = gr.Button('Delete', elem_classes="small-button", variant='stop', interactive=not mu) shared.gradio['delete_character_confirm'] = gr.Button('Delete', elem_classes="small-button", variant='stop', interactive=not mu)
shared.gradio['delete_character_cancel'] = gr.Button('Cancel', elem_classes="small-button") shared.gradio['delete_character_cancel'] = gr.Button('Cancel', elem_classes="small-button")
# Preset saver
with gr.Group(visible=False, elem_classes='file-saver') as shared.gradio['preset_saver']:
shared.gradio['save_preset_filename'] = gr.Textbox(lines=1, label='File name', info='The preset will be saved to your presets/ folder with this base filename.')
shared.gradio['save_preset_contents'] = gr.Textbox(lines=10, label='File contents')
with gr.Row():
shared.gradio['save_preset_confirm'] = gr.Button('Save', elem_classes="small-button", variant='primary', interactive=not mu)
shared.gradio['save_preset_cancel'] = gr.Button('Cancel', elem_classes="small-button")
def create_event_handlers(): def create_event_handlers():
shared.gradio['save_confirm'].click( shared.gradio['save_confirm'].click(
@ -65,10 +73,16 @@ def create_event_handlers():
shared.gradio['save_preset'].click( shared.gradio['save_preset'].click(
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
presets.generate_preset_yaml, gradio('interface_state'), gradio('save_contents')).then( presets.generate_preset_yaml, gradio('interface_state'), gradio('save_preset_contents')).then(
lambda: 'presets/', None, gradio('save_root')).then( lambda: 'My Preset', None, gradio('save_preset_filename')).then(
lambda: 'My Preset.yaml', None, gradio('save_filename')).then( lambda: gr.update(visible=True), None, gradio('preset_saver'))
lambda: gr.update(visible=True), None, gradio('file_saver'))
shared.gradio['save_preset_confirm'].click(
lambda x, y: utils.save_file(f'presets/{x}.yaml', y), gradio('save_preset_filename', 'save_preset_contents'), None).then(
lambda: gr.update(visible=False), None, gradio('preset_saver')).then(
lambda x: gr.update(choices=utils.get_available_presets(), value=x), gradio('save_preset_filename'), gradio('preset_menu'))
shared.gradio['save_preset_cancel'].click(lambda: gr.update(visible=False), None, gradio('preset_saver'))
shared.gradio['delete_preset'].click( shared.gradio['delete_preset'].click(
lambda x: f'{x}.yaml', gradio('preset_menu'), gradio('delete_filename')).then( lambda x: f'{x}.yaml', gradio('preset_menu'), gradio('delete_filename')).then(