From f2ec880e814a9e5a846b4837650083aed83f4504 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:58:10 -0300 Subject: [PATCH] Auto-scroll to the bottom when streaming is over in notebook/default modes --- server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 36665a46..06bec5d3 100644 --- a/server.py +++ b/server.py @@ -573,12 +573,14 @@ def create_interface(): gen_events.append(shared.gradio['Generate'].click( gather_interface_values, [shared.gradio[k] for k in shared.input_elements], shared.gradio['interface_state']).then( - generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream) + generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream).then( + None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) gen_events.append(shared.gradio['textbox'].submit( gather_interface_values, [shared.gradio[k] for k in shared.input_elements], shared.gradio['interface_state']).then( - generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream) + generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream).then( + None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[0]; element.scrollTop = element.scrollHeight}") ) shared.gradio['Stop'].click(stop_everything_event, None, None, queue=False, cancels=gen_events if shared.args.no_stream else None) @@ -617,17 +619,20 @@ def create_interface(): gen_events.append(shared.gradio['Generate'].click( gather_interface_values, [shared.gradio[k] for k in shared.input_elements], shared.gradio['interface_state']).then( - generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream) + generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream).then( + None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[1]; element.scrollTop = element.scrollHeight}") ) gen_events.append(shared.gradio['textbox'].submit( gather_interface_values, [shared.gradio[k] for k in shared.input_elements], shared.gradio['interface_state']).then( - generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream) + generate_reply, shared.input_params, output_params, show_progress=shared.args.no_stream).then( + None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[1]; element.scrollTop = element.scrollHeight}") ) gen_events.append(shared.gradio['Continue'].click( gather_interface_values, [shared.gradio[k] for k in shared.input_elements], shared.gradio['interface_state']).then( - generate_reply, [shared.gradio['output_textbox']] + shared.input_params[1:], output_params, show_progress=shared.args.no_stream) + generate_reply, [shared.gradio['output_textbox']] + shared.input_params[1:], output_params, show_progress=shared.args.no_stream).then( + None, None, None, _js="() => {element = document.getElementsByTagName('textarea')[1]; element.scrollTop = element.scrollHeight}") ) shared.gradio['Stop'].click(stop_everything_event, None, None, queue=False, cancels=gen_events if shared.args.no_stream else None)