From 96a6b11ab4d9af11dd90c90903efd091896efb11 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 5 Sep 2022 13:10:19 +0530 Subject: [PATCH 1/3] Show a warning if the initial image is larger than 768x768, can cause out of memory errors --- ui/index.html | 53 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/ui/index.html b/ui/index.html index 4578ec04..3cff9ebd 100644 --- a/ui/index.html +++ b/ui/index.html @@ -384,6 +384,8 @@ const USE_FULL_PRECISION_KEY = "useFullPrecision" const USE_TURBO_MODE_KEY = "useTurboMode" const HEALTH_PING_INTERVAL = 5 // seconds +const IMAGE_REGEX = new RegExp('data:image/[A-Za-z]+;base64') + let promptField = document.querySelector('#prompt') let numOutputsTotalField = document.querySelector('#num_outputs_total') let numOutputsParallelField = document.querySelector('#num_outputs_parallel') @@ -495,8 +497,21 @@ function setStatus(statusType, msg, msgType) { } } +function logMsg(msg, level) { + if (level === 'error') { + outputMsg.innerHTML = 'Error: ' + msg + '' + } else if (level === 'warn') { + outputMsg.innerHTML = 'Warning: ' + msg + '' + } else { + outputMsg.innerHTML = msg + } + + console.log(level, msg) +} + function logError(msg, res) { - outputMsg.innerHTML = 'Error: ' + msg + '' + logMsg(msg, 'error') + console.log('request error', res) setStatus('request', 'error', 'error') } @@ -643,20 +658,46 @@ async function doMakeImage(reqBody) { return true } +function validateInput() { + const MAX_INIT_IMAGE_DIMENSION = 768 + + let width = parseInt(widthField.value) + let height = parseInt(heightField.value) + + if (IMAGE_REGEX.test(initImagePreview.src)) { + if (initImagePreview.naturalWidth > MAX_INIT_IMAGE_DIMENSION || initImagePreview.naturalHeight > MAX_INIT_IMAGE_DIMENSION) { + return {'isValid': false, 'warning': `The dimensions of your initial image are very large, and can cause 'Out of Memory' errors! Please ensure that its dimensions are equal (or smaller) than the desired output image. +

+ Your initial image size is ${initImagePreview.naturalWidth}x${initImagePreview.naturalHeight} pixels. Please try to keep it smaller than ${MAX_INIT_IMAGE_DIMENSION}x${MAX_INIT_IMAGE_DIMENSION}.`} + } + } + + return {'isValid': true} +} + async function makeImage() { if (serverStatus !== 'online') { logError('The server is still starting up..') return } + let validation = validateInput() + if (validation['isValid']) { + outputMsg.innerHTML = 'Fetching..' + } else { + if (validation['error']) { + logError(validation['error']) + return + } else if (validation['warning']) { + logMsg(validation['warning'], 'warn') + } + } + setStatus('request', 'fetching..') makeImageBtn.innerHTML = 'Processing..' makeImageBtn.disabled = true - outputMsg.innerHTML = 'Fetching..' - - const imageRegex = new RegExp('data:image/[A-Za-z]+;base64') let seed = (randomSeedField.checked ? Math.floor(Math.random() * 10000) : parseInt(seedField.value)) let numOutputsTotal = parseInt(numOutputsTotalField.value) let numOutputsParallel = parseInt(numOutputsParallelField.value) @@ -685,11 +726,11 @@ async function makeImage() { use_full_precision: useFullPrecisionField.checked } - if (imageRegex.test(initImagePreview.src)) { + if (IMAGE_REGEX.test(initImagePreview.src)) { reqBody['init_image'] = initImagePreview.src reqBody['prompt_strength'] = parseInt(promptStrengthField.value) / 10 - // if (imageRegex.test(maskImagePreview.src)) { + // if (IMAGE_REGEX.test(maskImagePreview.src)) { // reqBody['mask'] = maskImagePreview.src // } } From 44a3f63f99af82917197b53e92e97b7e3faf1d47 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 5 Sep 2022 13:22:34 +0530 Subject: [PATCH 2/3] Show suggestions if an out of memory error is encountered by the user --- ui/index.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ui/index.html b/ui/index.html index 3cff9ebd..efbb82c4 100644 --- a/ui/index.html +++ b/ui/index.html @@ -383,6 +383,7 @@ const USE_CPU_KEY = "useCPU" const USE_FULL_PRECISION_KEY = "useFullPrecision" const USE_TURBO_MODE_KEY = "useTurboMode" const HEALTH_PING_INTERVAL = 5 // seconds +const MAX_INIT_IMAGE_DIMENSION = 768 const IMAGE_REGEX = new RegExp('data:image/[A-Za-z]+;base64') @@ -565,6 +566,15 @@ async function doMakeImage(reqBody) { let msg = '' if (res.detail !== undefined) { msg = res.detail + + if (msg.toLowerCase().includes('out of memory')) { + msg += `

+ Suggestions: +
+ 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.
+ 2. Try disabling the 'Turbo mode' under 'Advanced Settings'.
+ 3. Try generating a smaller image.
` + } } else { msg = res } @@ -659,8 +669,6 @@ async function doMakeImage(reqBody) { } function validateInput() { - const MAX_INIT_IMAGE_DIMENSION = 768 - let width = parseInt(widthField.value) let height = parseInt(heightField.value) From 458b0150ef9e5e33fee37cbb996f3e66fe176239 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 5 Sep 2022 13:23:54 +0530 Subject: [PATCH 3/3] Bump version --- ui/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/index.html b/ui/index.html index efbb82c4..922e9070 100644 --- a/ui/index.html +++ b/ui/index.html @@ -265,7 +265,7 @@
 
Stable Diffusion is starting.. -

Stable Diffusion UI v2.05 (beta)

+

Stable Diffusion UI v2.06 (beta)