Use Esc to Stop the generation

This commit is contained in:
oobabooga 2023-08-03 08:13:17 -07:00
parent 3e70bce576
commit 1839dff763
2 changed files with 13 additions and 2 deletions

View File

@ -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();
}
}
});

View File

@ -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')