diff --git a/css/main.js b/css/main.js index 9663d464..7a2368fe 100644 --- a/css/main.js +++ b/css/main.js @@ -24,3 +24,14 @@ for(i = 0; i < textareaElements.length; i++) { textareaElements[i].classList.add('pretty_scrollbar'); textareaElements[i].style.resize = "none"; } + +// Stop generation on Esc pressed +document.addEventListener("keydown", function(event) { + if (event.key === "Escape") { + // Find the element with id 'stop' and click it + var stopButton = document.getElementById("stop"); + if (stopButton) { + stopButton.click(); + } + } +}); diff --git a/server.py b/server.py index 601ae33f..10ea4ece 100644 --- a/server.py +++ b/server.py @@ -741,7 +741,7 @@ def create_interface(): 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") + 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") @@ -772,7 +772,7 @@ def create_interface(): shared.gradio['max_new_tokens'] = gr.Slider(minimum=shared.settings['max_new_tokens_min'], maximum=shared.settings['max_new_tokens_max'], step=1, label='max_new_tokens', value=shared.settings['max_new_tokens']) with gr.Row(): shared.gradio['Generate'] = gr.Button('Generate', variant='primary') - shared.gradio['Stop'] = gr.Button('Stop') + shared.gradio['Stop'] = gr.Button('Stop', elem_id='stop') shared.gradio['Continue'] = gr.Button('Continue') shared.gradio['count_tokens'] = gr.Button('Count tokens')