From 7e57b35b5e7c9a2cd20504633d2bcb5b4eaf600a Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:10:39 -0700 Subject: [PATCH] Clean up old code --- modules/ui_chat.py | 18 ++++++------------ modules/ui_default.py | 16 ++++------------ modules/ui_notebook.py | 13 ++++--------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/modules/ui_chat.py b/modules/ui_chat.py index fc850ea..a3a4ccf 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -120,53 +120,47 @@ def create_chat_settings_ui(): def create_event_handlers(): - gen_events = [] # Obsolete variables, kept for compatibility with old extensions shared.input_params = gradio(inputs) shared.reload_inputs = gradio(reload_arr) - gen_events.append(shared.gradio['Generate'].click( + 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( chat.generate_chat_reply_wrapper, gradio(inputs), 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}}}') - ) - gen_events.append(shared.gradio['textbox'].submit( + shared.gradio['textbox'].submit( 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( chat.generate_chat_reply_wrapper, gradio(inputs), 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}}}') - ) - gen_events.append(shared.gradio['Regenerate'].click( + shared.gradio['Regenerate'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( partial(chat.generate_chat_reply_wrapper, regenerate=True), gradio(inputs), 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}}}') - ) - gen_events.append(shared.gradio['Continue'].click( + shared.gradio['Continue'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( partial(chat.generate_chat_reply_wrapper, _continue=True), gradio(inputs), 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}}}') - ) - gen_events.append(shared.gradio['Impersonate'].click( + shared.gradio['Impersonate'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( lambda x: x, gradio('textbox'), gradio('Chat input'), show_progress=False).then( chat.impersonate_wrapper, gradio(inputs), 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}}}') - ) shared.gradio['Replace last reply'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( @@ -211,7 +205,7 @@ def create_event_handlers(): chat.redraw_html, gradio(reload_arr), gradio('display')) shared.gradio['Stop'].click( - stop_everything_event, None, None, queue=False, cancels=gen_events if shared.args.no_stream else None).then( + stop_everything_event, None, None, queue=False).then( chat.redraw_html, gradio(reload_arr), gradio('display')) shared.gradio['mode'].change( diff --git a/modules/ui_default.py b/modules/ui_default.py index e4771fb..9965722 100644 --- a/modules/ui_default.py +++ b/modules/ui_default.py @@ -45,36 +45,28 @@ def create_ui(): def create_event_handlers(): - gen_events = [] - - gen_events.append(shared.gradio['Generate-default'].click( + shared.gradio['Generate-default'].click( lambda x: x, gradio('textbox-default'), gradio('last_input-default')).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, gradio(inputs), gradio(outputs), 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="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") - ) - gen_events.append(shared.gradio['textbox-default'].submit( + shared.gradio['textbox-default'].submit( lambda x: x, gradio('textbox-default'), gradio('last_input-default')).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, gradio(inputs), gradio(outputs), 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="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") - ) shared.gradio['markdown_render-default'].click(lambda x: x, gradio('output_textbox'), gradio('markdown-default'), queue=False) - gen_events.append(shared.gradio['Continue-default'].click( + shared.gradio['Continue-default'].click( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, [shared.gradio['output_textbox']] + gradio(inputs)[1:], gradio(outputs), 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="() => {element = document.getElementsByTagName('textarea')[1]; element.scrollTop = element.scrollHeight}") - ) - shared.gradio['Stop-default'].click(stop_everything_event, None, None, queue=False, cancels=gen_events if shared.args.no_stream else None) + shared.gradio['Stop-default'].click(stop_everything_event, None, None, queue=False) shared.gradio['prompt_menu-default'].change(load_prompt, gradio('prompt_menu-default'), gradio('textbox-default'), show_progress=False) shared.gradio['save_prompt-default'].click( lambda x: x, gradio('textbox-default'), gradio('save_contents')).then( diff --git a/modules/ui_notebook.py b/modules/ui_notebook.py index dba9039..6949ed7 100644 --- a/modules/ui_notebook.py +++ b/modules/ui_notebook.py @@ -46,35 +46,30 @@ def create_ui(): def create_event_handlers(): - gen_events = [] - - gen_events.append(shared.gradio['Generate-notebook'].click( + shared.gradio['Generate-notebook'].click( lambda x: x, gradio('textbox-notebook'), gradio('last_input-notebook')).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, gradio(inputs), gradio(outputs), 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}}}') - ) - gen_events.append(shared.gradio['textbox-notebook'].submit( + shared.gradio['textbox-notebook'].submit( lambda x: x, gradio('textbox-notebook'), gradio('last_input-notebook')).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, gradio(inputs), gradio(outputs), 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}}}') - ) shared.gradio['Undo'].click(lambda x: x, gradio('last_input-notebook'), gradio('textbox-notebook'), show_progress=False) shared.gradio['markdown_render-notebook'].click(lambda x: x, gradio('textbox-notebook'), gradio('markdown-notebook'), queue=False) - gen_events.append(shared.gradio['Regenerate-notebook'].click( + shared.gradio['Regenerate-notebook'].click( lambda x: x, gradio('last_input-notebook'), gradio('textbox-notebook'), show_progress=False).then( ui.gather_interface_values, gradio(shared.input_elements), gradio('interface_state')).then( generate_reply_wrapper, gradio(inputs), gradio(outputs), 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}}}') - ) - shared.gradio['Stop-notebook'].click(stop_everything_event, None, None, queue=False, cancels=gen_events if shared.args.no_stream else None) + shared.gradio['Stop-notebook'].click(stop_everything_event, None, None, queue=False) shared.gradio['prompt_menu-notebook'].change(load_prompt, gradio('prompt_menu-notebook'), gradio('textbox-notebook'), show_progress=False) shared.gradio['save_prompt-notebook'].click( lambda x: x, gradio('textbox-notebook'), gradio('save_contents')).then(