easydiffusion/ui/media/js/main.js

1365 lines
50 KiB
JavaScript
Raw Normal View History

"use strict" // Opt in to a restricted variant of JavaScript
const MAX_INIT_IMAGE_DIMENSION = 768
const MIN_GPUS_TO_SHOW_SELECTION = 2
const IMAGE_REGEX = new RegExp('data:image/[A-Za-z]+;base64')
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const htmlTaskMap = new WeakMap()
let promptField = document.querySelector('#prompt')
let promptsFromFileSelector = document.querySelector('#prompt_from_file')
let promptsFromFileBtn = document.querySelector('#promptsFromFileBtn')
let negativePromptField = document.querySelector('#negative_prompt')
let numOutputsTotalField = document.querySelector('#num_outputs_total')
let numOutputsParallelField = document.querySelector('#num_outputs_parallel')
let numInferenceStepsField = document.querySelector('#num_inference_steps')
let guidanceScaleSlider = document.querySelector('#guidance_scale_slider')
let guidanceScaleField = document.querySelector('#guidance_scale')
let outputQualitySlider = document.querySelector('#output_quality_slider')
let outputQualityField = document.querySelector('#output_quality')
let outputQualityRow = document.querySelector('#output_quality_row')
let randomSeedField = document.querySelector("#random_seed")
let seedField = document.querySelector('#seed')
let widthField = document.querySelector('#width')
let heightField = document.querySelector('#height')
let initImageSelector = document.querySelector("#init_image")
let initImagePreview = document.querySelector("#init_image_preview")
2022-10-17 08:10:01 +02:00
let initImageSizeBox = document.querySelector("#init_image_size_box")
let maskImageSelector = document.querySelector("#mask")
let maskImagePreview = document.querySelector("#mask_preview")
let promptStrengthSlider = document.querySelector('#prompt_strength_slider')
let promptStrengthField = document.querySelector('#prompt_strength')
let samplerField = document.querySelector('#sampler')
let samplerSelectionContainer = document.querySelector("#samplerSelection")
let useFaceCorrectionField = document.querySelector("#use_face_correction")
let useUpscalingField = document.querySelector("#use_upscale")
let upscaleModelField = document.querySelector("#upscale_model")
let stableDiffusionModelField = document.querySelector('#stable_diffusion_model')
let vaeModelField = document.querySelector('#vae_model')
let hypernetworkModelField = document.querySelector('#hypernetwork_model')
let hypernetworkStrengthSlider = document.querySelector('#hypernetwork_strength_slider')
let hypernetworkStrengthField = document.querySelector('#hypernetwork_strength')
let outputFormatField = document.querySelector('#output_format')
let showOnlyFilteredImageField = document.querySelector("#show_only_filtered_image")
let updateBranchLabel = document.querySelector("#updateBranchLabel")
let streamImageProgressField = document.querySelector("#stream_image_progress")
let makeImageBtn = document.querySelector('#makeImage')
let stopImageBtn = document.querySelector('#stopImage')
let imagesContainer = document.querySelector('#current-images')
let initImagePreviewContainer = document.querySelector('#init_image_preview_container')
let initImageClearBtn = document.querySelector('.init_image_clear')
let promptStrengthContainer = document.querySelector('#prompt_strength_container')
2022-09-27 14:39:07 +02:00
let initialText = document.querySelector("#initial-text")
let previewTools = document.querySelector("#preview-tools")
let clearAllPreviewsBtn = document.querySelector("#clear-all-previews")
let maskSetting = document.querySelector('#enable_mask')
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const processOrder = document.querySelector('#process_order_toggle')
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let imagePreview = document.querySelector("#preview")
imagePreview.addEventListener('drop', function(ev) {
const data = ev.dataTransfer?.getData("text/plain");
if (!data) {
return
}
const movedTask = document.getElementById(data)
if (!movedTask) {
return
}
ev.preventDefault()
let moveTarget = ev.target
while (moveTarget && typeof moveTarget === 'object' && moveTarget.parentNode !== imagePreview) {
moveTarget = moveTarget.parentNode
}
if (moveTarget === initialText || moveTarget === previewTools) {
moveTarget = null
}
if (moveTarget === movedTask) {
return
}
if (moveTarget) {
const childs = Array.from(imagePreview.children)
if (moveTarget.nextSibling && childs.indexOf(movedTask) < childs.indexOf(moveTarget)) {
// Move after the target if lower than current position.
moveTarget = moveTarget.nextSibling
}
}
const newNode = imagePreview.insertBefore(movedTask, moveTarget || previewTools.nextSibling)
if (newNode === movedTask) {
return
}
imagePreview.removeChild(movedTask)
const task = htmlTaskMap.get(movedTask)
if (task) {
htmlTaskMap.delete(movedTask)
}
if (task) {
htmlTaskMap.set(newNode, task)
}
})
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let showConfigToggle = document.querySelector('#configToggleBtn')
// let configBox = document.querySelector('#config')
// let outputMsg = document.querySelector('#outputMsg')
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let soundToggle = document.querySelector('#sound_toggle')
2022-09-27 14:39:07 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let serverStatusColor = document.querySelector('#server-status-color')
let serverStatusMsg = document.querySelector('#server-status-msg')
function getLocalStorageBoolItem(key, fallback) {
let item = localStorage.getItem(key)
if (item === null) {
return fallback
}
return (item === 'true' ? true : false)
}
function handleBoolSettingChange(key) {
return function(e) {
localStorage.setItem(key, e.target.checked.toString())
}
}
function handleStringSettingChange(key) {
return function(e) {
localStorage.setItem(key, e.target.value.toString())
}
}
function isSoundEnabled() {
return getSetting("sound_toggle")
}
function getSavedDiskPath() {
return getSetting("diskPath")
}
function setStatus(statusType, msg, msgType) {
2022-10-14 09:47:25 +02:00
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function setServerStatus(event) {
switch(event.type) {
2022-10-14 09:47:25 +02:00
case 'online':
serverStatusColor.style.color = 'green'
serverStatusMsg.style.color = 'green'
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
serverStatusMsg.innerText = 'Stable Diffusion is ' + event.message
2022-10-14 09:47:25 +02:00
break
case 'busy':
2022-10-17 14:22:55 +02:00
serverStatusColor.style.color = 'rgb(200, 139, 0)'
serverStatusMsg.style.color = 'rgb(200, 139, 0)'
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
serverStatusMsg.innerText = 'Stable Diffusion is ' + event.message
2022-10-14 09:47:25 +02:00
break
case 'error':
serverStatusColor.style.color = 'red'
serverStatusMsg.style.color = 'red'
serverStatusMsg.innerText = 'Stable Diffusion has stopped'
break
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (SD.serverState.devices) {
setDeviceInfo(SD.serverState.devices)
}
}
// shiftOrConfirm(e, prompt, fn)
// e : MouseEvent
// prompt : Text to be shown as prompt. Should be a question to which "yes" is a good answer.
// fn : function to be called if the user confirms the dialog or has the shift key pressed
//
// If the user had the shift key pressed while clicking, the function fn will be executed.
// If the setting "confirm_dangerous_actions" in the system settings is disabled, the function
// fn will be executed.
// Otherwise, a confirmation dialog is shown. If the user confirms, the function fn will also
// be executed.
function shiftOrConfirm(e, prompt, fn) {
e.stopPropagation()
if (e.shiftKey || !confirmDangerousActionsField.checked) {
fn(e)
} else {
2022-12-01 09:24:49 +01:00
$.confirm({
theme: 'modern',
title: prompt,
2022-12-01 09:24:49 +01:00
useBootstrap: false,
animateFromElement: false,
content: '<small>Tip: To skip this dialog, use shift-click or disable the "Confirm dangerous actions" setting in the Settings tab.</small>',
buttons: {
yes: () => { fn(e) },
cancel: () => {}
}
});
}
}
2022-09-27 14:39:07 +02:00
function logMsg(msg, level, outputMsg) {
if (outputMsg.hasChildNodes()) {
outputMsg.appendChild(document.createElement('br'))
}
if (level === 'error') {
outputMsg.innerHTML += '<span style="color: red">Error: ' + msg + '</span>'
} else if (level === 'warn') {
outputMsg.innerHTML += '<span style="color: orange">Warning: ' + msg + '</span>'
} else {
outputMsg.innerText += msg
}
console.log(level, msg)
}
2022-09-27 14:39:07 +02:00
function logError(msg, res, outputMsg) {
logMsg(msg, 'error', outputMsg)
console.log('request error', res)
setStatus('request', 'error', 'error')
}
function playSound() {
const audio = new Audio('/media/ding.mp3')
audio.volume = 0.2
2022-10-20 06:12:01 +02:00
var promise = audio.play()
2022-10-17 08:10:01 +02:00
if (promise !== undefined) {
promise.then(_ => {}).catch(error => {
2022-10-20 06:12:01 +02:00
console.warn("browser blocked autoplay")
})
2022-10-17 08:10:01 +02:00
}
}
function showImages(reqBody, res, outputContainer, livePreview) {
2022-09-29 09:38:42 +02:00
let imageItemElements = outputContainer.querySelectorAll('.imgItem')
if(typeof res != 'object') return
2022-09-29 10:22:48 +02:00
res.output.reverse()
2022-09-27 16:23:19 +02:00
res.output.forEach((result, index) => {
const imageData = result?.data || result?.path + '?t=' + Date.now(),
imageSeed = result?.seed,
imagePrompt = reqBody.prompt,
imageInferenceSteps = reqBody.num_inference_steps,
imageGuidanceScale = reqBody.guidance_scale,
imageWidth = reqBody.width,
imageHeight = reqBody.height;
2022-09-27 23:05:34 +02:00
if (!imageData.includes('/')) {
2022-09-27 16:23:19 +02:00
// res contained no data for the image, stop execution
2022-09-29 09:38:42 +02:00
setStatus('request', 'invalid image', 'error')
return
2022-09-25 01:55:11 +02:00
}
let imageItemElem = (index < imageItemElements.length ? imageItemElements[index] : null)
2022-09-27 16:23:19 +02:00
if(!imageItemElem) {
2022-09-29 09:38:42 +02:00
imageItemElem = document.createElement('div')
imageItemElem.className = 'imgItem'
2022-09-27 16:23:19 +02:00
imageItemElem.innerHTML = `
<div class="imgContainer">
<img/>
<div class="imgItemInfo">
<span class="imgSeedLabel"></span>
</div>
2022-09-25 01:55:11 +02:00
</div>
2022-09-29 09:38:42 +02:00
`
outputContainer.appendChild(imageItemElem)
}
const imageElem = imageItemElem.querySelector('img')
imageElem.src = imageData
imageElem.width = parseInt(imageWidth)
imageElem.height = parseInt(imageHeight)
imageElem.setAttribute('data-prompt', imagePrompt)
imageElem.setAttribute('data-steps', imageInferenceSteps)
imageElem.setAttribute('data-guidance', imageGuidanceScale)
const imageInfo = imageItemElem.querySelector('.imgItemInfo')
imageInfo.style.visibility = (livePreview ? 'hidden' : 'visible')
if ('seed' in result && !imageElem.hasAttribute('data-seed')) {
const req = Object.assign({}, reqBody, {
seed: result?.seed || reqBody.seed
})
imageElem.setAttribute('data-seed', req.seed)
const imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel')
imageSeedLabel.innerText = 'Seed: ' + req.seed
let buttons = [
{ text: 'Use as Input', on_click: onUseAsInputClick },
{ text: 'Download', on_click: onDownloadImageClick },
{ text: 'Make Similar Images', on_click: onMakeSimilarClick },
2022-10-19 18:38:42 +02:00
{ text: 'Draw another 25 steps', on_click: onContinueDrawingClick },
2022-10-20 08:44:09 +02:00
{ text: 'Upscale', on_click: onUpscaleClick, filter: (req, img) => !req.use_upscale },
{ text: 'Fix Faces', on_click: onFixFacesClick, filter: (req, img) => !req.use_face_correction }
]
// include the plugins
buttons = buttons.concat(PLUGINS['IMAGE_INFO_BUTTONS'])
const imgItemInfo = imageItemElem.querySelector('.imgItemInfo')
const img = imageItemElem.querySelector('img')
const createButton = function(btnInfo) {
const newButton = document.createElement('button')
newButton.classList.add('tasksBtns')
2022-10-19 14:53:34 +02:00
newButton.innerText = btnInfo.text
2022-10-19 13:56:35 +02:00
newButton.addEventListener('click', function() {
btnInfo.on_click(req, img)
2022-10-19 13:56:35 +02:00
})
imgItemInfo.appendChild(newButton)
}
buttons.forEach(btn => {
if (btn.filter && btn.filter(req, img) === false) {
return
}
createButton(btn)
})
2022-09-27 16:23:19 +02:00
}
2022-09-29 09:38:42 +02:00
})
}
function onUseAsInputClick(req, img) {
const imgData = img.src
2022-10-19 13:56:35 +02:00
initImageSelector.value = null
initImagePreview.src = imgData
2022-10-19 13:56:35 +02:00
maskSetting.checked = false
}
function onDownloadImageClick(req, img) {
const imgData = img.src
const imageSeed = img.getAttribute('data-seed')
const imagePrompt = img.getAttribute('data-prompt')
const imageInferenceSteps = img.getAttribute('data-steps')
const imageGuidanceScale = img.getAttribute('data-guidance')
2022-10-19 13:56:35 +02:00
const imgDownload = document.createElement('a')
imgDownload.download = createFileName(imagePrompt, imageSeed, imageInferenceSteps, imageGuidanceScale, req['output_format'])
imgDownload.href = imgData
imgDownload.click()
}
2022-10-19 13:56:35 +02:00
function modifyCurrentRequest(...reqDiff) {
2022-10-20 11:40:34 +02:00
const newTaskRequest = getCurrentUserRequest()
2022-10-19 13:56:35 +02:00
newTaskRequest.reqBody = Object.assign(newTaskRequest.reqBody, ...reqDiff, {
2022-10-20 11:40:34 +02:00
use_cpu: useCPUField.checked
})
newTaskRequest.seed = newTaskRequest.reqBody.seed
return newTaskRequest
}
function onMakeSimilarClick(req, img) {
const newTaskRequest = modifyCurrentRequest(req, {
2022-10-19 13:56:35 +02:00
num_outputs: 1,
num_inference_steps: 50,
guidance_scale: 7.5,
prompt_strength: 0.7,
init_image: img.src,
2022-10-19 13:56:35 +02:00
seed: Math.floor(Math.random() * 10000000)
})
newTaskRequest.numOutputsTotal = 5
newTaskRequest.batchCount = 5
delete newTaskRequest.reqBody.mask
createTask(newTaskRequest)
}
2022-10-20 11:40:34 +02:00
function enqueueImageVariationTask(req, img, reqDiff) {
const imageSeed = img.getAttribute('data-seed')
const newRequestBody = {
2022-10-20 11:40:34 +02:00
num_outputs: 1, // this can be user-configurable in the future
seed: imageSeed
}
// If the user is editing pictures, stop modifyCurrentRequest from importing
// new values by setting the missing properties to undefined
if (!('init_image' in req) && !('init_image' in reqDiff)) {
newRequestBody.init_image = undefined
newRequestBody.mask = undefined
} else if (!('mask' in req) && !('mask' in reqDiff)) {
newRequestBody.mask = undefined
}
const newTaskRequest = modifyCurrentRequest(req, reqDiff, newRequestBody)
2022-10-20 11:40:34 +02:00
newTaskRequest.numOutputsTotal = 1 // this can be user-configurable in the future
newTaskRequest.batchCount = 1
createTask(newTaskRequest)
}
2022-10-20 11:40:34 +02:00
function onUpscaleClick(req, img) {
enqueueImageVariationTask(req, img, {
use_upscale: upscaleModelField.value
})
2022-10-20 11:40:34 +02:00
}
2022-10-20 11:40:34 +02:00
function onFixFacesClick(req, img) {
enqueueImageVariationTask(req, img, {
use_face_correction: 'GFPGANv1.3'
})
}
2022-10-19 18:38:42 +02:00
function onContinueDrawingClick(req, img) {
2022-10-20 11:40:34 +02:00
enqueueImageVariationTask(req, img, {
num_inference_steps: parseInt(req.num_inference_steps) + 25
2022-10-19 18:38:42 +02:00
})
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function getUncompletedTaskEntries() {
const taskEntries = Array.from(
document.querySelectorAll('#preview .imageTaskContainer .taskStatusLabel')
).filter((taskLabel) => taskLabel.style.display !== 'none'
).map(function(taskLabel) {
let imageTaskContainer = taskLabel.parentNode
while(!imageTaskContainer.classList.contains('imageTaskContainer') && imageTaskContainer.parentNode) {
imageTaskContainer = imageTaskContainer.parentNode
}
return imageTaskContainer
})
if (!processOrder.checked) {
taskEntries.reverse()
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
return taskEntries
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function makeImage() {
if (!SD.isServerAvailable()) {
alert('The server is not available.')
return
}
if (!randomSeedField.checked && seedField.value == '') {
alert('The "Seed" field must not be empty.')
return
}
if (numInferenceStepsField.value == '') {
alert('The "Inference Steps" field must not be empty.')
return
}
if (numOutputsTotalField.value == '') {
numOutputsTotalField.value = 1
}
if (numOutputsParallelField.value == '') {
numOutputsParallelField.value = 1
}
if (guidanceScaleField.value == '') {
guidanceScaleField.value = guidanceScaleSlider.value / 10
}
const taskTemplate = getCurrentUserRequest()
const newTaskRequests = getPrompts().map((prompt) => Object.assign({}, taskTemplate, {
reqBody: Object.assign({ prompt: prompt }, taskTemplate.reqBody)
}))
newTaskRequests.forEach(createTask)
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
initialText.style.display = 'none'
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function onIdle() {
const serverCapacity = SD.serverCapacity
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
for (const taskEntry of getUncompletedTaskEntries()) {
if (SD.activeTasks.size >= serverCapacity) {
break
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
}
const task = htmlTaskMap.get(taskEntry)
if (!task) {
const taskStatusLabel = taskEntry.querySelector('.taskStatusLabel')
taskStatusLabel.style.display = 'none'
continue
}
onTaskStart(task)
}
}
2022-09-27 14:39:07 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function getTaskUpdater(task, reqBody, outputContainer) {
2022-09-27 14:39:07 +02:00
const outputMsg = task['outputMsg']
const progressBar = task['progressBar']
2022-10-28 02:03:09 +02:00
const progressBarInner = progressBar.querySelector("div")
2022-09-27 14:39:07 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const batchCount = task.batchCount
let lastStatus = undefined
return async function(event) {
if (this.status !== lastStatus) {
lastStatus = this.status
switch(this.status) {
case SD.TaskStatus.pending:
task['taskStatusLabel'].innerText = "Pending"
task['taskStatusLabel'].classList.add('waitingTaskLabel')
break
case SD.TaskStatus.waiting:
task['taskStatusLabel'].innerText = "Waiting"
task['taskStatusLabel'].classList.add('waitingTaskLabel')
task['taskStatusLabel'].classList.remove('activeTaskLabel')
break
case SD.TaskStatus.processing:
case SD.TaskStatus.completed:
task['taskStatusLabel'].innerText = "Processing"
task['taskStatusLabel'].classList.add('activeTaskLabel')
task['taskStatusLabel'].classList.remove('waitingTaskLabel')
break
case SD.TaskStatus.stopped:
break
case SD.TaskStatus.failed:
if (!SD.isServerAvailable()) {
logError("Stable Diffusion is still starting up, please wait. If this goes on beyond a few minutes, Stable Diffusion has probably crashed. Please check the error message in the command-line window.", event, outputMsg)
} else if (typeof event?.response === 'object') {
let msg = 'Stable Diffusion had an error reading the response:<br/><pre>'
if (this.exception) {
msg += `Error: ${this.exception.message}<br/>`
}
try { // 'Response': body stream already read
msg += 'Read: ' + await event.response.text()
} catch(e) {
msg += 'Unexpected end of stream. '
}
const bufferString = event.reader.bufferedString
if (bufferString) {
msg += 'Buffered data: ' + bufferString
}
msg += '</pre>'
logError(msg, event, outputMsg)
} else {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let msg = `Unexpected Read Error:<br/><pre>Error:${this.exception}<br/>EventInfo: ${JSON.stringify(event, undefined, 4)}</pre>`
logError(msg, event, outputMsg)
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
break
2022-10-14 09:47:25 +02:00
}
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if ('update' in event) {
const stepUpdate = event.update
if (!('step' in stepUpdate)) {
return
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
// task.instances can be a mix of different tasks with uneven number of steps (Render Vs Filter Tasks)
const overallStepCount = task.instances.reduce(
(sum, instance) => sum + (instance.isPending ? Math.max(0, instance.step || stepUpdate.step) / (instance.total_steps || stepUpdate.total_steps) : 1),
0 // Initial value
) * stepUpdate.total_steps // Scale to current number of steps.
const totalSteps = task.instances.reduce(
(sum, instance) => sum + (instance.total_steps || stepUpdate.total_steps),
stepUpdate.total_steps * (batchCount - task.batchesDone) // Initial value at (unstarted task count * Nbr of steps)
)
const percent = Math.min(100, 100 * (overallStepCount / totalSteps)).toFixed(0)
const timeTaken = stepUpdate.step_time // sec
const stepsRemaining = Math.max(0, totalSteps - overallStepCount)
const timeRemaining = (timeTaken < 0 ? '' : millisecondsToStr(stepsRemaining * timeTaken * 1000))
outputMsg.innerHTML = `Batch ${task.batchesDone} of ${batchCount}. Generating image(s): ${percent}%. Time remaining (approx): ${timeRemaining}`
outputMsg.style.display = 'block'
progressBarInner.style.width = `${percent}%`
if (stepUpdate.output) {
showImages(reqBody, stepUpdate, outputContainer, true)
}
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
}
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function abortTask(task) {
if (!task.isProcessing) {
return false
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
task.isProcessing = false
task.progressBar.classList.remove("active")
task['taskStatusLabel'].style.display = 'none'
task['stopTask'].innerHTML = '<i class="fa-solid fa-trash-can"></i> Remove'
if (!task.instances?.some((r) => r.isPending)) {
return
}
task.instances.forEach((instance) => {
try {
instance.abort()
} catch (e) {
console.error(e)
}
})
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function onTaskErrorHandler(task, reqBody, instance, reason) {
if (!task.isProcessing) {
return
}
console.log('Render request %o, Instance: %o, Error: %s', reqBody, instance, reason)
abortTask(task)
const outputMsg = task['outputMsg']
logError('Stable Diffusion had an error. Please check the logs in the command-line window. <br/><br/>' + reason + '<br/><pre>' + reason.stack + '</pre>', task, outputMsg)
setStatus('request', 'error', 'error')
}
2022-09-28 09:47:45 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function onTaskCompleted(task, reqBody, instance, outputContainer, stepUpdate) {
if (typeof stepUpdate !== 'object') {
return
}
if (stepUpdate.status !== 'succeeded') {
const outputMsg = task['outputMsg']
let msg = ''
if ('detail' in stepUpdate && typeof stepUpdate.detail === 'string' && stepUpdate.detail.length > 0) {
msg = stepUpdate.detail
if (msg.toLowerCase().includes('out of memory')) {
msg += `<br/><br/>
<b>Suggestions</b>:
<br/>
1. If you have set an initial image, please try reducing its dimension to ${MAX_INIT_IMAGE_DIMENSION}x${MAX_INIT_IMAGE_DIMENSION} or smaller.<br/>
2. Try disabling the '<em>Turbo mode</em>' under '<em>Advanced Settings</em>'.<br/>
3. Try generating a smaller image.<br/>`
2022-09-28 09:47:45 +02:00
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
} else {
msg = `Unexpected Read Error:<br/><pre>StepUpdate: ${JSON.stringify(stepUpdate, undefined, 4)}</pre>`
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
logError(msg, stepUpdate, outputMsg)
return false
}
showImages(reqBody, stepUpdate, outputContainer, false)
if (task.isProcessing && task.batchesDone < task.batchCount) {
task['taskStatusLabel'].innerText = "Pending"
task['taskStatusLabel'].classList.add('waitingTaskLabel')
task['taskStatusLabel'].classList.remove('activeTaskLabel')
2022-09-27 14:39:07 +02:00
return
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if ('instances' in task && task.instances.some((ins) => ins != instance && ins.isPending)) {
return
}
2022-09-27 14:39:07 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
setStatus('request', 'done', 'success')
2022-09-27 14:39:07 +02:00
task.isProcessing = false
task['stopTask'].innerHTML = '<i class="fa-solid fa-trash-can"></i> Remove'
2022-09-27 15:07:21 +02:00
task['taskStatusLabel'].style.display = 'none'
2022-09-27 14:39:07 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
let time = Date.now() - task.startTime
2022-09-27 14:39:07 +02:00
time /= 1000
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (task.batchesDone == task.batchCount) {
task.outputMsg.innerText = `Processed ${task.numOutputsTotal} images in ${time} seconds`
task.progressBar.style.height = "0px"
task.progressBar.style.border = "0px solid var(--background-color3)"
task.progressBar.classList.remove("active")
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
setStatus('request', 'done', 'success')
} else {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
task.outputMsg.innerText += `Task ended after ${time} seconds`
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (randomSeedField.checked) {
seedField.value = task.seed
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (SD.activeTasks.size > 0) {
return
}
const uncompletedTasks = getUncompletedTaskEntries()
if (uncompletedTasks && uncompletedTasks.length > 0) {
return
2022-10-11 04:30:17 +02:00
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
stopImageBtn.style.display = 'none'
renameMakeImageButton()
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (isSoundEnabled()) {
playSound()
}
}
2022-10-09 13:17:43 +02:00
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function onTaskStart(task) {
if (!task.isProcessing || task.batchesDone >= task.batchCount) {
return
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (typeof task.startTime !== 'number') {
task.startTime = Date.now()
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (!('instances' in task)) {
task['instances'] = []
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
task['stopTask'].innerHTML = '<i class="fa-solid fa-circle-stop"></i> Stop'
task['taskStatusLabel'].innerText = "Starting"
task['taskStatusLabel'].classList.add('waitingTaskLabel')
let newTaskReqBody = task.reqBody
if (task.batchCount > 1) {
// Each output render batch needs it's own task reqBody instance to avoid altering the other runs after they are completed.
newTaskReqBody = Object.assign({}, task.reqBody)
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const startSeed = task.seed || newTaskReqBody.seed
const genSeeds = Boolean(typeof newTaskReqBody.seed !== 'number' || (newTaskReqBody.seed === task.seed && task.numOutputsTotal > 1))
if (genSeeds) {
newTaskReqBody.seed = parseInt(startSeed) + (task.batchesDone * newTaskReqBody.num_outputs)
2022-10-09 13:17:43 +02:00
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
// Update the seed *before* starting the processing so it's retained if user stops the task
if (randomSeedField.checked) {
seedField.value = task.seed
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const outputContainer = document.createElement('div')
outputContainer.className = 'img-batch'
task.outputContainer.insertBefore(outputContainer, task.outputContainer.firstChild)
const eventInfo = {reqBody:newTaskReqBody}
PLUGINS['TASK_CREATE'].forEach((hook) => {
if (typeof hook !== 'function') {
console.error('The provided TASK_CREATE hook is not a function. Hook: %o', hook)
return
}
try {
hook.call(task, eventInfo)
} catch (err) {
console.error(err)
}
})
let instance = eventInfo.instance
if (!instance) {
const factory = PLUGINS.OUTPUTS_FORMATS.get(eventInfo.reqBody?.output_format || newTaskReqBody.output_format)
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (factory) {
instance = factory(eventInfo.reqBody || newTaskReqBody)
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
}
if (!instance) {
console.error(`${factory ? "Factory " + String(factory) : 'No factory defined'} for output format ${eventInfo.reqBody?.output_format || newTaskReqBody.output_format}. Instance is ${instance || 'undefined'}. Using default renderer.`)
instance = new SD.RenderTask(eventInfo.reqBody || newTaskReqBody)
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
}
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
task['instances'].push(instance)
task.batchesDone++
instance.enqueue(getTaskUpdater(task, newTaskReqBody, outputContainer)).then(
(renderResult) => {
onTaskCompleted(task, newTaskReqBody, instance, outputContainer, renderResult)
},
(reason) => {
onTaskErrorHandler(task, newTaskReqBody, instance, reason)
}
)
setStatus('request', 'fetching..')
stopImageBtn.style.display = 'block'
renameMakeImageButton()
previewTools.style.display = 'block'
2022-10-09 13:17:43 +02:00
}
2022-10-09 13:17:43 +02:00
function createTask(task) {
let taskConfig = `<b>Seed:</b> ${task.seed}, <b>Sampler:</b> ${task.reqBody.sampler}, <b>Inference Steps:</b> ${task.reqBody.num_inference_steps}, <b>Guidance Scale:</b> ${task.reqBody.guidance_scale}, <b>Model:</b> ${task.reqBody.use_stable_diffusion_model}`
if (task.reqBody.use_vae_model.trim() !== '') {
taskConfig += `, <b>VAE:</b> ${task.reqBody.use_vae_model}`
}
if (task.reqBody.negative_prompt.trim() !== '') {
taskConfig += `, <b>Negative Prompt:</b> ${task.reqBody.negative_prompt}`
}
2022-10-09 13:17:43 +02:00
if (task.reqBody.init_image !== undefined) {
taskConfig += `, <b>Prompt Strength:</b> ${task.reqBody.prompt_strength}`
2022-09-27 14:39:07 +02:00
}
if (task.reqBody.use_face_correction) {
taskConfig += `, <b>Fix Faces:</b> ${task.reqBody.use_face_correction}`
2022-09-27 14:39:07 +02:00
}
if (task.reqBody.use_upscale) {
taskConfig += `, <b>Upscale:</b> ${task.reqBody.use_upscale}`
}
if (task.reqBody.use_hypernetwork_model) {
taskConfig += `, <b>Hypernetwork:</b> ${task.reqBody.use_hypernetwork_model}`
taskConfig += `, <b>Hypernetwork Strength:</b> ${task.reqBody.hypernetwork_strength}`
}
2022-09-27 14:39:07 +02:00
let taskEntry = document.createElement('div')
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
taskEntry.id = `imageTaskContainer-${Date.now()}`
2022-09-27 14:39:07 +02:00
taskEntry.className = 'imageTaskContainer'
taskEntry.innerHTML = ` <div class="header-content panel collapsible active">
<div class="taskStatusLabel">Enqueued</div>
<button class="secondaryButton stopTask"><i class="fa-solid fa-trash-can"></i> Remove</button>
2022-11-18 16:41:34 +01:00
<button class="secondaryButton useSettings"><i class="fa-solid fa-redo"></i> Use these settings</button>
<div class="preview-prompt collapsible active"></div>
<div class="taskConfig">${taskConfig}</div>
2022-09-28 10:14:48 +02:00
<div class="outputMsg"></div>
2022-10-28 02:03:09 +02:00
<div class="progress-bar active"><div></div></div>
</div>
<div class="collapsible-content">
2022-09-28 10:14:48 +02:00
<div class="img-preview">
</div>`
createCollapsibles(taskEntry)
2022-09-27 14:39:07 +02:00
task['taskStatusLabel'] = taskEntry.querySelector('.taskStatusLabel')
task['outputContainer'] = taskEntry.querySelector('.img-preview')
task['outputMsg'] = taskEntry.querySelector('.outputMsg')
task['previewPrompt'] = taskEntry.querySelector('.preview-prompt')
2022-10-28 02:03:09 +02:00
task['progressBar'] = taskEntry.querySelector('.progress-bar')
2022-09-27 14:39:07 +02:00
task['stopTask'] = taskEntry.querySelector('.stopTask')
2022-12-01 09:24:49 +01:00
task['stopTask'].addEventListener('click', (e) => {
let question = (task['isProcessing'] ? "Stop this task?" : "Remove this task?")
shiftOrConfirm(e, question, async function(e) {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (task.batchesDone <= 0 || !task.isProcessing) {
taskEntry.remove()
2022-12-01 09:24:49 +01:00
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
abortTask(task)
2022-12-01 09:24:49 +01:00
})
})
2022-11-11 03:36:39 +01:00
task['useSettings'] = taskEntry.querySelector('.useSettings')
task['useSettings'].addEventListener('click', function(e) {
e.stopPropagation()
restoreTaskToUI(task, TASK_REQ_NO_EXPORT)
2022-11-11 03:36:39 +01:00
})
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
task.isProcessing = true
taskEntry = imagePreview.insertBefore(taskEntry, previewTools.nextSibling)
taskEntry.draggable = true
htmlTaskMap.set(taskEntry, task)
taskEntry.addEventListener('dragstart', function(ev) {
ev.dataTransfer.setData("text/plain", ev.target.id);
})
2022-10-09 13:17:43 +02:00
task.previewPrompt.innerText = task.reqBody.prompt
if (task.previewPrompt.innerText.trim() === '') {
task.previewPrompt.innerHTML = '&nbsp;' // allows the results to be collapsed
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
// Allow prompt text to be selected.
task.previewPrompt.addEventListener("mouseover", function() {
taskEntry.setAttribute("draggable", "false");
});
task.previewPrompt.addEventListener("mouseout", function() {
taskEntry.setAttribute("draggable", "true");
});
}
function getCurrentUserRequest() {
const numOutputsTotal = parseInt(numOutputsTotalField.value)
const numOutputsParallel = parseInt(numOutputsParallelField.value)
const seed = (randomSeedField.checked ? Math.floor(Math.random() * 10000000) : parseInt(seedField.value))
const newTask = {
batchesDone: 0,
numOutputsTotal: numOutputsTotal,
batchCount: Math.ceil(numOutputsTotal / numOutputsParallel),
seed,
reqBody: {
seed,
negative_prompt: negativePromptField.value.trim(),
num_outputs: numOutputsParallel,
num_inference_steps: parseInt(numInferenceStepsField.value),
guidance_scale: parseFloat(guidanceScaleField.value),
width: parseInt(widthField.value),
height: parseInt(heightField.value),
// allow_nsfw: allowNSFWField.checked,
turbo: turboField.checked,
//render_device: undefined, // Set device affinity. Prefer this device, but wont activate.
use_full_precision: useFullPrecisionField.checked,
use_stable_diffusion_model: stableDiffusionModelField.value,
use_vae_model: vaeModelField.value,
stream_progress_updates: true,
stream_image_progress: (numOutputsTotal > 50 ? false : streamImageProgressField.checked),
show_only_filtered_image: showOnlyFilteredImageField.checked,
output_format: outputFormatField.value,
output_quality: parseInt(outputQualityField.value),
original_prompt: promptField.value,
active_tags: (activeTags.map(x => x.name))
}
}
if (IMAGE_REGEX.test(initImagePreview.src)) {
newTask.reqBody.init_image = initImagePreview.src
newTask.reqBody.prompt_strength = parseFloat(promptStrengthField.value)
// if (IMAGE_REGEX.test(maskImagePreview.src)) {
// newTask.reqBody.mask = maskImagePreview.src
// }
if (maskSetting.checked) {
newTask.reqBody.mask = imageInpainter.getImg()
}
newTask.reqBody.sampler = 'ddim'
} else {
newTask.reqBody.sampler = samplerField.value
}
if (saveToDiskField.checked && diskPathField.value.trim() !== '') {
newTask.reqBody.save_to_disk_path = diskPathField.value.trim()
}
if (useFaceCorrectionField.checked) {
newTask.reqBody.use_face_correction = 'GFPGANv1.3'
}
if (useUpscalingField.checked) {
newTask.reqBody.use_upscale = upscaleModelField.value
}
if (hypernetworkModelField.value) {
newTask.reqBody.use_hypernetwork_model = hypernetworkModelField.value
newTask.reqBody.hypernetwork_strength = parseFloat(hypernetworkStrengthField.value)
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
return newTask
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
function getPrompts(prompts) {
if (typeof prompts === 'undefined') {
prompts = promptField.value
}
if (prompts.trim() === '') {
return ['']
}
prompts = prompts.split('\n')
prompts = prompts.map(prompt => prompt.trim())
prompts = prompts.filter(prompt => prompt !== '')
let promptsToMake = applyPermuteOperator(prompts)
promptsToMake = applySetOperator(promptsToMake)
const newTags = activeTags.filter(tag => tag.inactive === undefined || tag.inactive === false)
if (newTags.length > 0) {
const promptTags = newTags.map(x => x.name).join(", ")
promptsToMake = promptsToMake.map((prompt) => `${prompt}, ${promptTags}`)
}
2022-11-30 07:48:34 +01:00
promptsToMake = applyPermuteOperator(promptsToMake)
promptsToMake = applySetOperator(promptsToMake)
return promptsToMake
}
function applySetOperator(prompts) {
let promptsToMake = []
let braceExpander = new BraceExpander()
prompts.forEach(prompt => {
let expandedPrompts = braceExpander.expand(prompt)
promptsToMake = promptsToMake.concat(expandedPrompts)
})
return promptsToMake
}
function applyPermuteOperator(prompts) {
let promptsToMake = []
prompts.forEach(prompt => {
let promptMatrix = prompt.split('|')
prompt = promptMatrix.shift().trim()
promptsToMake.push(prompt)
promptMatrix = promptMatrix.map(p => p.trim())
promptMatrix = promptMatrix.filter(p => p !== '')
if (promptMatrix.length > 0) {
let promptPermutations = permutePrompts(prompt, promptMatrix)
promptsToMake = promptsToMake.concat(promptPermutations)
}
})
return promptsToMake
}
function permutePrompts(promptBase, promptMatrix) {
let prompts = []
let permutations = permute(promptMatrix)
permutations.forEach(perm => {
let prompt = promptBase
if (perm.length > 0) {
let promptAddition = perm.join(', ')
if (promptAddition.trim() === '') {
return
}
prompt += ', ' + promptAddition
}
prompts.push(prompt)
})
return prompts
}
// create a file name with embedded prompt and metadata
// for easier cateloging and comparison
function createFileName(prompt, seed, steps, guidance, outputFormat) {
// Most important information is the prompt
let underscoreName = prompt.replace(/[^a-zA-Z0-9]/g, '_')
underscoreName = underscoreName.substring(0, 100)
//const steps = numInferenceStepsField.value
//const guidance = guidanceScaleField.value
// name and the top level metadata
let fileName = `${underscoreName}_Seed-${seed}_Steps-${steps}_Guidance-${guidance}`
// add the tags
2022-09-29 09:38:42 +02:00
// let tags = []
// let tagString = ''
// document.querySelectorAll(modifyTagsSelector).forEach(function(tag) {
2022-09-29 09:38:42 +02:00
// tags.push(tag.innerHTML)
// })
// join the tags with a pipe
// if (activeTags.length > 0) {
2022-09-29 09:38:42 +02:00
// tagString = '_Tags-'
// tagString += tags.join('|')
// }
// // append empty or populated tags
2022-09-29 09:38:42 +02:00
// fileName += `${tagString}`
// add the file extension
fileName += '.' + (outputFormat === 'png' ? 'png' : 'jpeg')
return fileName
}
2022-09-27 14:39:07 +02:00
async function stopAllTasks() {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
getUncompletedTaskEntries().forEach((taskEntry) => {
const taskStatusLabel = taskEntry.querySelector('.taskStatusLabel')
if (taskStatusLabel) {
taskStatusLabel.style.display = 'none'
}
const task = htmlTaskMap.get(taskEntry)
if (!task) {
return
}
abortTask(task)
2022-09-27 14:39:07 +02:00
})
}
function removeTask(taskToRemove) {
taskToRemove.remove()
2022-11-28 09:14:12 +01:00
if (document.querySelector('.imageTaskContainer') === null) {
previewTools.style.display = 'none'
initialText.style.display = 'block'
}
}
2022-12-01 09:24:49 +01:00
clearAllPreviewsBtn.addEventListener('click', (e) => { shiftOrConfirm(e, "Clear all the results and tasks in this window?", async function() {
2022-09-27 14:39:07 +02:00
await stopAllTasks()
2022-09-27 14:39:07 +02:00
let taskEntries = document.querySelectorAll('.imageTaskContainer')
taskEntries.forEach(removeTask)
})})
2022-09-27 14:39:07 +02:00
2022-12-01 09:24:49 +01:00
stopImageBtn.addEventListener('click', (e) => { shiftOrConfirm(e, "Stop all the tasks?", async function(e) {
2022-09-27 14:39:07 +02:00
await stopAllTasks()
})})
widthField.addEventListener('change', onDimensionChange)
heightField.addEventListener('change', onDimensionChange)
function renameMakeImageButton() {
let totalImages = Math.max(parseInt(numOutputsTotalField.value), parseInt(numOutputsParallelField.value))
let imageLabel = 'Image'
if (totalImages > 1) {
imageLabel = totalImages + ' Images'
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
if (SD.activeTasks.size == 0) {
makeImageBtn.innerText = 'Make ' + imageLabel
} else {
makeImageBtn.innerText = 'Enqueue Next ' + imageLabel
}
}
numOutputsTotalField.addEventListener('change', renameMakeImageButton)
numOutputsParallelField.addEventListener('change', renameMakeImageButton)
function onDimensionChange() {
let widthValue = parseInt(widthField.value)
let heightValue = parseInt(heightField.value)
if (!initImagePreviewContainer.classList.contains("has-image")) {
imageEditor.setImage(null, widthValue, heightValue)
}
else {
imageInpainter.setImage(initImagePreview.src, widthValue, heightValue)
}
}
2022-10-29 03:25:54 +02:00
diskPathField.disabled = !saveToDiskField.checked
2022-10-29 03:25:54 +02:00
upscaleModelField.disabled = !useUpscalingField.checked
useUpscalingField.addEventListener('change', function(e) {
upscaleModelField.disabled = !this.checked
})
makeImageBtn.addEventListener('click', makeImage)
2022-11-10 10:29:01 +01:00
document.onkeydown = function(e) {
if (e.ctrlKey && e.code === 'Enter') {
makeImage()
e.preventDefault()
}
}
/********************* Guidance **************************/
function updateGuidanceScale() {
guidanceScaleField.value = guidanceScaleSlider.value / 10
2022-10-20 06:12:01 +02:00
guidanceScaleField.dispatchEvent(new Event("change"))
}
function updateGuidanceScaleSlider() {
if (guidanceScaleField.value < 0) {
guidanceScaleField.value = 0
} else if (guidanceScaleField.value > 50) {
guidanceScaleField.value = 50
}
guidanceScaleSlider.value = guidanceScaleField.value * 10
guidanceScaleSlider.dispatchEvent(new Event("change"))
}
guidanceScaleSlider.addEventListener('input', updateGuidanceScale)
guidanceScaleField.addEventListener('input', updateGuidanceScaleSlider)
updateGuidanceScale()
/********************* Prompt Strength *******************/
function updatePromptStrength() {
promptStrengthField.value = promptStrengthSlider.value / 100
2022-10-20 06:12:01 +02:00
promptStrengthField.dispatchEvent(new Event("change"))
}
function updatePromptStrengthSlider() {
if (promptStrengthField.value < 0) {
promptStrengthField.value = 0
} else if (promptStrengthField.value > 0.99) {
promptStrengthField.value = 0.99
}
promptStrengthSlider.value = promptStrengthField.value * 100
promptStrengthSlider.dispatchEvent(new Event("change"))
}
promptStrengthSlider.addEventListener('input', updatePromptStrength)
promptStrengthField.addEventListener('input', updatePromptStrengthSlider)
updatePromptStrength()
/********************* Hypernetwork Strength **********************/
function updateHypernetworkStrength() {
hypernetworkStrengthField.value = hypernetworkStrengthSlider.value / 100
hypernetworkStrengthField.dispatchEvent(new Event("change"))
}
function updateHypernetworkStrengthSlider() {
if (hypernetworkStrengthField.value < 0) {
hypernetworkStrengthField.value = 0
} else if (hypernetworkStrengthField.value > 0.99) {
hypernetworkStrengthField.value = 0.99
}
hypernetworkStrengthSlider.value = hypernetworkStrengthField.value * 100
hypernetworkStrengthSlider.dispatchEvent(new Event("change"))
}
hypernetworkStrengthSlider.addEventListener('input', updateHypernetworkStrength)
hypernetworkStrengthField.addEventListener('input', updateHypernetworkStrengthSlider)
updateHypernetworkStrength()
/********************* JPEG Quality **********************/
function updateOutputQuality() {
outputQualityField.value = 0 | outputQualitySlider.value
outputQualityField.dispatchEvent(new Event("change"))
}
function updateOutputQualitySlider() {
if (outputQualityField.value < 10) {
outputQualityField.value = 10
} else if (outputQualityField.value > 95) {
outputQualityField.value = 95
}
outputQualitySlider.value = 0 | outputQualityField.value
outputQualitySlider.dispatchEvent(new Event("change"))
}
outputQualitySlider.addEventListener('input', updateOutputQuality)
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
outputQualityField.addEventListener('input', debounce(updateOutputQualitySlider, 1500))
updateOutputQuality()
outputFormatField.addEventListener('change', e => {
if (outputFormatField.value == 'jpeg') {
outputQualityRow.style.display='table-row'
} else {
outputQualityRow.style.display='none'
}
})
async function getModels() {
try {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const sd_model_setting_key = "stable_diffusion_model"
const vae_model_setting_key = "vae_model"
const hypernetwork_model_key = "hypernetwork_model"
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const selectedSDModel = SETTINGS[sd_model_setting_key].value
const selectedVaeModel = SETTINGS[vae_model_setting_key].value
const selectedHypernetworkModel = SETTINGS[hypernetwork_model_key].value
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const models = await SD.getModels()
const modelsOptions = models['options']
if ("scan-error" in models) {
// let previewPane = document.getElementById('tab-content-wrapper')
let previewPane = document.getElementById('preview')
previewPane.style.background="red"
previewPane.style.textAlign="center"
previewPane.innerHTML = '<H1>🔥Malware alert!🔥</H1><h2>The file <i>' + models['scan-error'] + '</i> in your <tt>models/stable-diffusion</tt> folder is probably malware infected.</h2><h2>Please delete this file from the folder before proceeding!</h2>After deleting the file, reload this page.<br><br><button onClick="window.location.reload();">Reload Page</button>'
makeImageBtn.disabled = true
}
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const stableDiffusionOptions = modelsOptions['stable-diffusion']
const vaeOptions = modelsOptions['vae']
const hypernetworkOptions = modelsOptions['hypernetwork']
vaeOptions.unshift('') // add a None option
hypernetworkOptions.unshift('') // add a None option
function createModelOptions(modelField, selectedModel) {
return function(modelName) {
engine.js (#615) * New engine.js first draft. * Small fixes... * Bump version for cache... * Improved cancellation code. * Cleaning * Wrong argument used in Task.waitUntil * session_id needs to always match SD.sessionId * Removed passing explicit Session ID from UI. Use SD.sessionID to replace. * Cleaning... Removed a disabled line and a hardcoded value. * Fix return if tasks are still waiting. * Added checkbox to reverse processing order. * Fixed progress not displaying properly. * Renamed reverse label. * Only hide progress bar inside onCompleted. * Thanks to rbertus2000 for helping testing and debugging! * Resolve async promises when used optionally. * when removed var should have used let, not const. * Renamed getTaskErrorHandler to onTaskErrorHandler to better reflect actual implementation. * Switched to the unsafer and less git friendly end of lines comma as requested in review. * Raised SERVER_STATE_VALIDITY_DURATION to 90 seconds to match the changes to Beta. * Added logging. * Added one more hook before those inside the SD engine. * Added selftest.plugin.js as part of core. * Removed a tests that wasn't yet implemented... * Groupped task stopping and abort in single function. * Added optional test for plugins. * Allow prompt text to be selected. * Added comment. * Improved isServerAvailable for better mobile usage and added comments for easier debugging. * Comments... * Normalized EVENT_STATUS_CHANGED to follow the same pattern as the other events. * Disable plugins if editorModifierTagsList is not defined. * Adds a new ServiceContainer to register IOC handlers. * Added expect test for a missing dependency in a ServiceContainer * Moved all event code in it's own sub class for easier reuse. * Removed forgotten unused var... * Allow getPrompts to be reused be plugins. * Renamed EventSource to GenericEventSource to avoid redefining an existing class name. * Added missing time argument to debounce * Added output_quality to engine.js * output_quality need to be an int. * Fixed typo. * Replaced the default euler_a by dpm2 to work with both SD1.# and SD2 * Remove generic completed tasks from plugins on generator complete. * dpm2 starts at step 2, replaced with plms to start at step 1. * Merge error * Merge error * changelog Co-authored-by: Marc-Andre Ferland <madrang@gmail.com>
2022-12-06 12:34:08 +01:00
const modelOption = document.createElement('option')
modelOption.value = modelName
modelOption.innerText = modelName !== '' ? modelName : 'None'
if (modelName === selectedModel) {
modelOption.selected = true
}
modelField.appendChild(modelOption)
}
}
stableDiffusionOptions.forEach(createModelOptions(stableDiffusionModelField, selectedSDModel))
vaeOptions.forEach(createModelOptions(vaeModelField, selectedVaeModel))
hypernetworkOptions.forEach(createModelOptions(hypernetworkModelField, selectedHypernetworkModel))
2022-10-20 06:12:01 +02:00
// TODO: set default for model here too
SETTINGS[sd_model_setting_key].default = stableDiffusionOptions[0]
if (getSetting(sd_model_setting_key) == '' || SETTINGS[sd_model_setting_key].value == '') {
setSetting(sd_model_setting_key, stableDiffusionOptions[0])
2022-10-20 06:12:01 +02:00
}
} catch (e) {
console.log('get models error', e)
}
}
function checkRandomSeed() {
if (randomSeedField.checked) {
seedField.disabled = true
//seedField.value = "0" // This causes the seed to be lost if the user changes their mind after toggling the checkbox
} else {
seedField.disabled = false
}
}
randomSeedField.addEventListener('input', checkRandomSeed)
checkRandomSeed()
function loadImg2ImgFromFile() {
if (initImageSelector.files.length === 0) {
return
}
let reader = new FileReader()
let file = initImageSelector.files[0]
2022-10-17 08:10:01 +02:00
reader.addEventListener('load', function(event) {
initImagePreview.src = reader.result
})
if (file) {
reader.readAsDataURL(file)
}
}
initImageSelector.addEventListener('change', loadImg2ImgFromFile)
loadImg2ImgFromFile()
function img2imgLoad() {
promptStrengthContainer.style.display = 'table-row'
samplerSelectionContainer.style.display = "none"
initImagePreviewContainer.classList.add("has-image")
2022-10-17 08:10:01 +02:00
initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight
imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight)
imageInpainter.setImage(this.src, parseInt(widthField.value), parseInt(heightField.value))
}
function img2imgUnload() {
initImageSelector.value = null
initImagePreview.src = ''
maskSetting.checked = false
promptStrengthContainer.style.display = "none"
samplerSelectionContainer.style.display = ""
initImagePreviewContainer.classList.remove("has-image")
imageEditor.setImage(null, parseInt(widthField.value), parseInt(heightField.value))
}
initImagePreview.addEventListener('load', img2imgLoad)
initImageClearBtn.addEventListener('click', img2imgUnload)
maskSetting.addEventListener('click', function() {
onDimensionChange()
})
promptsFromFileBtn.addEventListener('click', function() {
promptsFromFileSelector.click()
})
promptsFromFileSelector.addEventListener('change', function() {
if (promptsFromFileSelector.files.length === 0) {
return
}
let reader = new FileReader()
let file = promptsFromFileSelector.files[0]
reader.addEventListener('load', function() {
promptField.value = reader.result
})
if (file) {
reader.readAsText(file)
}
})
2022-10-29 01:48:32 +02:00
/* setup popup handlers */
document.querySelectorAll('.popup').forEach(popup => {
popup.addEventListener('click', event => {
if (event.target == popup) {
popup.classList.remove("active")
}
})
var closeButton = popup.querySelector(".close-button")
if (closeButton) {
closeButton.addEventListener('click', () => {
popup.classList.remove("active")
})
}
})
var tabElements = []
function selectTab(tab_id) {
let tabInfo = tabElements.find(t => t.tab.id == tab_id)
if (!tabInfo.tab.classList.contains("active")) {
tabElements.forEach(info => {
if (info.tab.classList.contains("active")) {
info.tab.classList.toggle("active")
info.content.classList.toggle("active")
}
})
tabInfo.tab.classList.toggle("active")
tabInfo.content.classList.toggle("active")
}
}
function linkTabContents(tab) {
var name = tab.id.replace("tab-", "")
var content = document.getElementById(`tab-content-${name}`)
tabElements.push({
name: name,
tab: tab,
content: content
})
tab.addEventListener("click", event => selectTab(tab.id))
}
document.querySelectorAll(".tab").forEach(linkTabContents)
window.addEventListener("beforeunload", function(e) {
const msg = "Unsaved pictures will be lost!";
let elementList = document.getElementsByClassName("imageTaskContainer");
if (elementList.length != 0) {
e.preventDefault();
(e || window.event).returnValue = msg;
return msg;
} else {
return true;
}
});
2022-10-22 05:08:19 +02:00
createCollapsibles()
prettifyInputs(document);