Make "Show controls" customizable through settings.yaml

This commit is contained in:
oobabooga 2023-08-16 07:03:53 -07:00
parent 2a29208224
commit 73d9befb65
7 changed files with 10 additions and 7 deletions

View File

@ -273,7 +273,6 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
height: calc(100dvh - 200px);
}
#show-controls {
position: absolute;
background-color: transparent;

View File

@ -29,6 +29,7 @@ session_is_loading = False
# UI defaults
settings = {
'dark_theme': True,
'show_controls': True,
'start_with': '',
'mode': 'chat',
'chat_style': 'TheEncrypted777',

View File

@ -178,7 +178,7 @@ def apply_interface_values(state, use_persistent=False):
return [state[k] if k in state else gr.update() for k in elements]
def save_settings(state, preset, instruction_template, extensions):
def save_settings(state, preset, instruction_template, extensions, show_controls):
output = copy.deepcopy(shared.settings)
exclude = ['name1', 'name2', 'greeting', 'context', 'turn_template']
for k in state:
@ -192,6 +192,7 @@ def save_settings(state, preset, instruction_template, extensions):
output['instruction_template'] = instruction_template
output['default_extensions'] = extensions
output['seed'] = int(output['seed'])
output['show_controls'] = show_controls
return yaml.dump(output, sort_keys=False, width=float("inf"))

View File

@ -22,9 +22,9 @@ def create_ui():
with gr.Tab('Chat', elem_id='chat-tab'):
shared.gradio['display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, shared.settings['name1'], shared.settings['name2'], 'chat', 'cai-chat'))
shared.gradio['textbox'] = gr.Textbox(label='Input', elem_id='chat-input')
shared.gradio['show-controls'] = gr.Checkbox(value=True, label='Show controls', elem_id='show-controls')
shared.gradio['show_controls'] = gr.Checkbox(value=shared.settings['show_controls'], label='Show controls', elem_id='show-controls')
with gr.Row():
shared.gradio['Stop'] = gr.Button('Stop', elem_id='stop')
shared.gradio['Generate'] = gr.Button('Generate', elem_id='Generate', variant='primary')
@ -127,8 +127,6 @@ def create_event_handlers():
shared.input_params = gradio(inputs)
shared.reload_inputs = gradio(reload_arr)
shared.gradio['show-controls'].change(None, gradio('show-controls'), None, _js=f'(x) => {{{ui.show_controls_js}; toggle_controls(x)}}')
shared.gradio['Generate'].click(
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
lambda x: (x, ''), gradio('textbox'), gradio('Chat input', 'textbox'), show_progress=False).then(
@ -276,3 +274,5 @@ def create_event_handlers():
shared.gradio['send_instruction_to_negative_prompt'].click(
prompts.load_instruction_prompt_simple, gradio('instruction_template'), gradio('negative_prompt')).then(
lambda: None, None, None, _js=f'() => {{{ui.switch_tabs_js}; switch_to_generation_parameters()}}')
shared.gradio['show_controls'].change(None, gradio('show_controls'), None, _js=f'(x) => {{{ui.show_controls_js}; toggle_controls(x)}}')

View File

@ -41,7 +41,7 @@ def create_ui():
shared.gradio['toggle_dark_mode'].click(lambda: None, None, None, _js='() => {document.getElementsByTagName("body")[0].classList.toggle("dark")}')
shared.gradio['save_settings'].click(
ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then(
ui.save_settings, gradio('interface_state', 'preset_menu', 'instruction_template', 'extensions_menu'), gradio('save_contents')).then(
ui.save_settings, gradio('interface_state', 'preset_menu', 'instruction_template', 'extensions_menu', 'show_controls'), gradio('save_contents')).then(
lambda: './', None, gradio('save_root')).then(
lambda: 'settings.yaml', None, gradio('save_filename')).then(
lambda: gr.update(visible=True), None, gradio('file_saver'))

View File

@ -128,6 +128,7 @@ def create_interface():
shared.gradio['interface'].load(lambda: None, None, None, _js="() => document.getElementsByTagName('body')[0].classList.add('dark')")
shared.gradio['interface'].load(lambda: None, None, None, _js=f"() => {{{js}}}")
shared.gradio['interface'].load(None, gradio('show_controls'), None, _js=f'(x) => {{{ui.show_controls_js}; toggle_controls(x)}}')
shared.gradio['interface'].load(partial(ui.apply_interface_values, {}, use_persistent=True), None, gradio(ui.list_interface_input_elements()), show_progress=False)
shared.gradio['interface'].load(chat.redraw_html, gradio(ui_chat.reload_arr), gradio('display'))

View File

@ -1,4 +1,5 @@
dark_theme: true
show_controls: true
start_with: ''
mode: chat
chat_style: TheEncrypted777