Merge pull request #2594 from SillyTavern/sd-stop Image generation stop handling
Signed| @@ -1,4 +1,8 @@ | ||
| 1 | 1 | <div id="sd_gen" class="list-group-item flex-container flexGap5"> |
| 2 | 2 | <div class="fa-solid fa-paintbrush extensionsMenuExtensionButton" title="Trigger Stable Diffusion" data-i18n="[title]Trigger Stable Diffusion" /></div> |
| 3 | 3 | <span>Generate Image</span> |
| 4 | +</div> | |
| 5 | +<div id="sd_stop_gen" class="list-group-item flex-container flexGap5"> | |
| 6 | + <div class="fa-solid fa-circle-stop extensionsMenuExtensionButton" title="Abort current image generation task" data-i18n="[title]Abort current image generation task"></div> | |
| 7 | + <span>Stop Image Generation</span> | |
| 4 | 8 | </div> |
| @@ -37,6 +37,7 @@ const MODULE_NAME = 'sd'; | ||
| 37 | 37 | const UPDATE_INTERVAL = 1000; |
| 38 | 38 | // This is a 1x1 transparent PNG |
| 39 | 39 | const PNG_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; |
| 40 | +const CUSTOM_STOP_EVENT = 'sd_stop_generation'; | |
| 40 | 41 | |
| 41 | 42 | const sources = { |
| 42 | 43 | extras: 'extras', |
| @@ -2290,6 +2291,7 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2290 | 2291 | |
| 2291 | 2292 | const dimensions = setTypeSpecificDimensions(generationType); |
| 2292 | 2293 | const abortController = new AbortController(); |
| 2294 | + const stopButton = document.getElementById('sd_stop_gen'); | |
| 2293 | 2295 | let negativePromptPrefix = args?.negative || ''; |
| 2294 | 2296 | let imagePath = ''; |
| 2295 | 2297 | |
| @@ -2300,9 +2302,8 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2300 | 2302 | const prompt = await getPrompt(generationType, message, trigger, quietPrompt, combineNegatives); |
| 2301 | 2303 | console.log('Processed image prompt:', prompt); |
| 2302 | 2304 | |
| 2303 | - eventSource.once(event_types.GENERATION_STOPPED, stopListener); | |
| 2305 | + $(stopButton).show(); | |
| 2304 | 2306 | contexteventSource.deactivateSendButtonsonce(CUSTOM_STOP_EVENT, stopListener); |
| 2305 | - hideSwipeButtons(); | |
| 2306 | 2307 | |
| 2307 | 2308 | if (typeof args?._abortController?.addEventListener === 'function') { |
| 2308 | 2309 | args._abortController.addEventListener('abort', stopListener); |
| @@ -2311,13 +2312,13 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2311 | 2312 | imagePath = await sendGenerationRequest(generationType, prompt, negativePromptPrefix, characterName, callback, initiator, abortController.signal); |
| 2312 | 2313 | } catch (err) { |
| 2313 | 2314 | console.trace(err); |
| 2314 | 2315 | throw new Errortoastr.error('SD prompt text generation failed. Reason: ' + err, 'Image Generation'); |
| 2316 | + throw new Error('SD prompt text generation failed. Reason: ' + err); | |
| 2315 | 2317 | } |
| 2316 | 2318 | finally { |
| 2319 | + $(stopButton).hide(); | |
| 2317 | 2320 | restoreOriginalDimensions(dimensions); |
| 2318 | 2321 | eventSource.removeListener(event_types.GENERATION_STOPPEDCUSTOM_STOP_EVENT, stopListener); |
| 2319 | - context.activateSendButtons(); | |
| 2320 | - showSwipeButtons(); | |
| 2321 | 2322 | } |
| 2322 | 2323 | |
| 2323 | 2324 | return imagePath; |
| @@ -3395,7 +3396,7 @@ async function addSDGenButtons() { | ||
| 3395 | 3396 | $(document).on('click touchend', function (e) { |
| 3396 | 3397 | const target = $(e.target); |
| 3397 | 3398 | if (target.is(dropdown) || target.closest(dropdown).length) return; |
| 3398 | 3399 | if ((target.is(button) || target.closest(button).length) && !dropdown.is(':visible') && $('#send_but').is(':visible')) { |
| 3399 | 3400 | e.preventDefault(); |
| 3400 | 3401 | |
| 3401 | 3402 | dropdown.fadeIn(animation_duration); |
| @@ -3425,6 +3426,10 @@ async function addSDGenButtons() { | ||
| 3425 | 3426 | generatePicture(initiators.wand, {}, param); |
| 3426 | 3427 | } |
| 3427 | 3428 | }); |
| 3429 | + | |
| 3430 | + const stopGenButton = $('#sd_stop_gen'); | |
| 3431 | + stopGenButton.hide(); | |
| 3432 | + stopGenButton.on('click', () => eventSource.emit(CUSTOM_STOP_EVENT)); | |
| 3428 | 3433 | } |
| 3429 | 3434 | |
| 3430 | 3435 | function isValidState() { |
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <div id="translate_chat" class="list-group-item flex-container flexGap5"> |
| 2 | 2 | <div class="fa-solid fa-language extensionsMenuExtensionButton" /></div> |
| 3 | 3 | <span data-i18n="ext_translate_btn_chat">Translate Chat</span> |
| 4 | 4 | </div> |
| 5 | 5 | <div id="translate_input_message" class="list-group-item flex-container flexGap5"> |
| 6 | 6 | <div class="fa-solid fa-keyboard extensionsMenuExtensionButton" /></div> |
| 7 | 7 | <span data-i18n="ext_translate_btn_input">Translate Input</span> |
| 8 | 8 | </div> |