From 0e05818266570454c16d7c45b656338c99f22c46 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 11 Aug 2023 16:33:15 -0700 Subject: [PATCH] Style changes --- modules/ui_chat.py | 31 ++++++++++++++----------------- modules/ui_default.py | 8 ++++---- modules/ui_notebook.py | 17 ++++++++--------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/modules/ui_chat.py b/modules/ui_chat.py index 4471d2f4..1d73adf7 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -12,13 +12,10 @@ from modules.utils import gradio def create_ui(): - - shared.gradio.update({ - 'interface_state': gr.State({k: None for k in shared.input_elements}), - 'Chat input': gr.State(), - 'dummy': gr.State(), - 'history': gr.State({'internal': [], 'visible': []}), - }) + shared.gradio['interface_state'] = gr.State({k: None for k in shared.input_elements}) + shared.gradio['Chat input'] = gr.State() + shared.gradio['dummy'] = gr.State() + shared.gradio['history'] = gr.State({'internal': [], 'visible': []}) with gr.Tab('Text generation', elem_id='main'): shared.gradio['display'] = gr.HTML(value=chat_html_wrapper({'internal': [], 'visible': []}, shared.settings['name1'], shared.settings['name2'], 'chat', 'cai-chat')) @@ -52,7 +49,7 @@ def create_ui(): shared.gradio['chat_style'] = gr.Dropdown(choices=utils.get_available_chat_styles(), label='Chat style', value=shared.settings['chat_style'], visible=shared.settings['mode'] != 'instruct') with gr.Tab('Chat settings', elem_id='chat-settings'): - with gr.Tab("Character"): + with gr.Tab('Character'): with gr.Row(): with gr.Column(scale=8): with gr.Row(): @@ -70,7 +67,7 @@ def create_ui(): shared.gradio['character_picture'] = gr.Image(label='Character picture', type='pil') shared.gradio['your_picture'] = gr.Image(label='Your picture', type='pil', value=Image.open(Path('cache/pfp_me.png')) if Path('cache/pfp_me.png').exists() else None) - with gr.Tab("Instruction template"): + with gr.Tab('Instruction template'): with gr.Row(): with gr.Row(): shared.gradio['instruction_template'] = gr.Dropdown(choices=utils.get_available_instruction_templates(), label='Instruction template', value='None', info='Change this according to the model/LoRA that you are using. Used in instruct and chat-instruct modes.', elem_classes='slim-dropdown') @@ -91,7 +88,7 @@ def create_ui(): shared.gradio['save_chat_history'] = gr.Button(value='Save history') with gr.Column(): - shared.gradio['load_chat_history'] = gr.File(type='binary', file_types=['.json', '.txt'], label="Upload History JSON") + shared.gradio['load_chat_history'] = gr.File(type='binary', file_types=['.json', '.txt'], label='Upload History JSON') with gr.Tab('Upload character'): with gr.Tab('YAML or JSON'): @@ -104,7 +101,7 @@ def create_ui(): with gr.Tab('TavernAI PNG'): with gr.Row(): with gr.Column(): - shared.gradio['upload_img_tavern'] = gr.Image(type='pil', label='TavernAI PNG File', elem_id="upload_img_tavern") + shared.gradio['upload_img_tavern'] = gr.Image(type='pil', label='TavernAI PNG File', elem_id='upload_img_tavern') shared.gradio['tavern_json'] = gr.State() with gr.Column(): shared.gradio['tavern_name'] = gr.Textbox(value='', lines=1, label='Name', interactive=False) @@ -126,7 +123,7 @@ def create_event_handlers(): chat.generate_chat_reply_wrapper, shared.input_params, gradio('display', 'history'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( chat.save_persistent_history, gradio('history', 'character_menu', 'mode'), None).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') ) gen_events.append(shared.gradio['textbox'].submit( @@ -135,7 +132,7 @@ def create_event_handlers(): chat.generate_chat_reply_wrapper, shared.input_params, gradio('display', 'history'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( chat.save_persistent_history, gradio('history', 'character_menu', 'mode'), None).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') ) gen_events.append(shared.gradio['Regenerate'].click( @@ -143,7 +140,7 @@ def create_event_handlers(): partial(chat.generate_chat_reply_wrapper, regenerate=True), shared.input_params, gradio('display', 'history'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( chat.save_persistent_history, gradio('history', 'character_menu', 'mode'), None).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') ) gen_events.append(shared.gradio['Continue'].click( @@ -151,7 +148,7 @@ def create_event_handlers(): partial(chat.generate_chat_reply_wrapper, _continue=True), shared.input_params, gradio('display', 'history'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( chat.save_persistent_history, gradio('history', 'character_menu', 'mode'), None).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') ) gen_events.append(shared.gradio['Impersonate'].click( @@ -159,7 +156,7 @@ def create_event_handlers(): lambda x: x, gradio('textbox'), gradio('Chat input'), show_progress=False).then( chat.impersonate_wrapper, shared.input_params, gradio('textbox'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') ) shared.gradio['Replace last reply'].click( @@ -243,7 +240,7 @@ def create_event_handlers(): shared.gradio['save_chat_history'].click( lambda x: json.dumps(x, indent=4), gradio('history'), gradio('temporary_text')).then( - None, gradio('temporary_text', 'character_menu', 'mode'), None, _js=f"(hist, char, mode) => {{{ui.save_files_js}; saveHistory(hist, char, mode)}}") + None, gradio('temporary_text', 'character_menu', 'mode'), None, _js=f'(hist, char, mode) => {{{ui.save_files_js}; saveHistory(hist, char, mode)}}') shared.gradio['Submit character'].click( chat.upload_character, gradio('upload_json', 'upload_img_bot'), gradio('character_menu')).then( diff --git a/modules/ui_default.py b/modules/ui_default.py index f0ab74ef..b879e1ef 100644 --- a/modules/ui_default.py +++ b/modules/ui_default.py @@ -15,7 +15,7 @@ def create_ui(): shared.gradio['interface_state'] = gr.State({k: None for k in shared.input_elements}) shared.gradio['last_input'] = gr.State('') - with gr.Tab("Text generation", elem_id="main"): + with gr.Tab('Text generation', elem_id='main'): with gr.Row(): with gr.Column(): shared.gradio['textbox'] = gr.Textbox(value=default_text, elem_classes=['textbox_default', 'add_scrollbar'], lines=27, label='Input') @@ -56,7 +56,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, shared.input_params, output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) @@ -65,7 +65,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, shared.input_params, output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) @@ -74,7 +74,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, [shared.gradio['output_textbox']] + shared.input_params[1:], output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[1]; element.scrollTop = element.scrollHeight}") ) diff --git a/modules/ui_notebook.py b/modules/ui_notebook.py index 998a7cf7..9e8b3af6 100644 --- a/modules/ui_notebook.py +++ b/modules/ui_notebook.py @@ -11,11 +11,10 @@ from modules.utils import gradio def create_ui(): default_text = load_prompt(shared.settings['prompt']) - shared.gradio['interface_state'] = gr.State({k: None for k in shared.input_elements}) shared.gradio['last_input'] = gr.State('') - with gr.Tab("Text generation", elem_id="main"): + with gr.Tab('Text generation', elem_id='main'): with gr.Row(): with gr.Column(scale=4): with gr.Tab('Raw'): @@ -29,10 +28,10 @@ def create_ui(): shared.gradio['html'] = gr.HTML() with gr.Row(): - shared.gradio['Generate'] = gr.Button('Generate', variant='primary', elem_classes="small-button") - shared.gradio['Stop'] = gr.Button('Stop', elem_classes="small-button", elem_id='stop') - shared.gradio['Undo'] = gr.Button('Undo', elem_classes="small-button") - shared.gradio['Regenerate'] = gr.Button('Regenerate', elem_classes="small-button") + shared.gradio['Generate'] = gr.Button('Generate', variant='primary', elem_classes='small-button') + shared.gradio['Stop'] = gr.Button('Stop', elem_classes='small-button', elem_id='stop') + shared.gradio['Undo'] = gr.Button('Undo', elem_classes='small-button') + shared.gradio['Regenerate'] = gr.Button('Regenerate', elem_classes='small-button') with gr.Column(scale=1): gr.HTML('
') @@ -58,7 +57,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, shared.input_params, output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) @@ -67,7 +66,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, shared.input_params, output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) @@ -78,7 +77,7 @@ def create_event_handlers(): ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, shared.input_params, output_params, show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( - lambda: None, None, None, _js=f"() => {{{ui.audio_notification_js}}}") + lambda: None, None, None, _js=f'() => {{{ui.audio_notification_js}}}') # lambda: None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") )