From 62048c68f0ce27a0e63429efe8687d5b42b7a44d Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Sun, 25 Sep 2022 02:55:11 +0300 Subject: [PATCH 01/20] Image item refactor and redesign --- ui/media/main.css | 44 +++++------- ui/media/main.js | 168 ++++++++++++++++++++-------------------------- 2 files changed, 88 insertions(+), 124 deletions(-) diff --git a/ui/media/main.css b/ui/media/main.css index 388c8ccd..7b01e14b 100644 --- a/ui/media/main.css +++ b/ui/media/main.css @@ -69,38 +69,28 @@ label { font-size: 8pt; } .imgSeedLabel { - position: absolute; - transform: translateX(-100%); - margin-top: 5pt; - margin-left: -5pt; - font-size: 10pt; - - background-color: #333; - opacity: 0.8; - color: #ddd; - border-radius: 3pt; - padding: 1pt 3pt; -} -.imgUseBtn { - position: absolute; - transform: translateX(-100%); - margin-top: 30pt; - margin-left: -5pt; -} -.imgSaveBtn { - position: absolute; - transform: translateX(-100%); - margin-top: 55pt; - margin-left: -5pt; + font-size: 1.3em; } .imgItem { - display: inline; - padding-right: 10px; + display: inline-block; + width: fit-content; + height: fit-content; + padding: 0.5em; + border: 1px solid rgb(255 255 255 / 25%); + margin-top: 1em; + margin-right: 1em; } .imgItemInfo { - opacity: 0.5; + width: 100%; + height: 2em; + padding-bottom: 0.5em; + display: flex; + align-items: center; + justify-content: space-between; +} +.imgInfoLeft { + margin-right: 1em; } - #container { width: 90%; margin-left: auto; diff --git a/ui/media/main.js b/ui/media/main.js index 7633b7ee..fb394981 100644 --- a/ui/media/main.js +++ b/ui/media/main.js @@ -251,18 +251,74 @@ async function healthCheck() { } } -function makeImageElement(width, height) { - let imgItem = document.createElement('div') - imgItem.className = 'imgItem' +function showImages(res, req) { + res.output.forEach(result => { + if(typeof res != 'object') return; - let img = document.createElement('img') - img.width = parseInt(width) - img.height = parseInt(height) + const imageData = result?.data, + imageSeed = result?.seed, + imageWidth = req.width, + imageHeight = req.height; - imgItem.appendChild(img) - imagesContainer.appendChild(imgItem) + // don't continue if data is incorrect + if (!(imageData && imageSeed)) + { + setStatus('request', 'invalid image', 'error'); + console.log(imageData); + return; + } - return imgItem + const imageItemElem = document.createElement('div'); + imageItemElem.className = 'imgItem'; + imageItemElem.innerHTML = ` +
+
+ +
+
+ + +
+
+ + `; + + const imageElem = imageItemElem.querySelector('img'), + imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'), + useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'), + saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); + + imageElem.src = imageData; + imageElem.width = parseInt(imageWidth); + imageElem.height = parseInt(imageHeight); + + imageSeedLabel.innerText = imageSeed; + + useAsInputBtn.addEventListener('click', () => { + initImageSelector.value = null; + initImagePreview.src = imageData; + + initImagePreviewContainer.style.display = 'block'; + inpaintingEditorContainer.style.display = 'none'; + promptStrengthContainer.style.display = 'block'; + maskSetting.checked = false; + + // maskSetting.style.display = 'block'; + + randomSeedField.checked = false; + seedField.value = imageSeed; + seedField.disabled = false; + }); + + saveImageBtn.addEventListener('click', () => { + const imgDownload = document.createElement('a'); + imgDownload.download = createFileName(imageSeed); + imgDownload.href = imageData; + imgDownload.click(); + }); + + imagesContainer.appendChild(imageItemElem); + }); } // makes a single image. don't call this directly, use makeImage() instead @@ -275,14 +331,6 @@ async function doMakeImage(reqBody, batchCount) { let seed = reqBody['seed'] let numOutputs = parseInt(reqBody['num_outputs']) - let images = [] - - function makeImageContainers(numImages) { - for (let i = images.length; i < numImages; i++) { - images.push(makeImageElement(reqBody.width, reqBody.height)) - } - } - try { res = await fetch('/image', { method: 'POST', @@ -411,86 +459,13 @@ async function doMakeImage(reqBody, batchCount) { res = undefined } - if (!res) { - return false - } + if (!res) return false; - lastPromptUsed = reqBody['prompt'] + lastPromptUsed = reqBody['prompt']; - makeImageContainers(res.output.length) + showImages(res, reqBody); - for (let idx in res.output) { - let imgBody = '' - let seed = 0 - - try { - let imgData = res.output[idx] - imgBody = imgData.data - seed = imgData.seed - } catch (e) { - console.log(imgBody) - setStatus('request', 'invalid image', 'error') - continue - } - - let imgItem = images[idx] - let img = imgItem.firstChild - - img.src = imgBody - - let imgItemInfo = document.createElement('span') - imgItemInfo.className = 'imgItemInfo' - - let imgSeedLabel = document.createElement('span') - imgSeedLabel.className = 'imgSeedLabel' - imgSeedLabel.innerText = 'Seed: ' + seed - - let imgUseBtn = document.createElement('button') - imgUseBtn.className = 'imgUseBtn' - imgUseBtn.innerText = 'Use as Input' - - let imgSaveBtn = document.createElement('button') - imgSaveBtn.className = 'imgSaveBtn' - imgSaveBtn.innerText = 'Download' - - imgItem.appendChild(imgItemInfo) - imgItemInfo.appendChild(imgSeedLabel) - imgItemInfo.appendChild(imgUseBtn) - imgItemInfo.appendChild(imgSaveBtn) - - imgUseBtn.addEventListener('click', function() { - initImageSelector.value = null - initImagePreview.src = imgBody - - initImagePreviewContainer.style.display = 'block' - inpaintingEditorContainer.style.display = 'none' - promptStrengthContainer.style.display = 'block' - maskSetting.checked = false - - // maskSetting.style.display = 'block' - - randomSeedField.checked = false - seedField.value = seed - seedField.disabled = false - }) - - imgSaveBtn.addEventListener('click', function() { - let imgDownload = document.createElement('a') - imgDownload.download = createFileName(); - imgDownload.href = imgBody - imgDownload.click() - }) - - imgItem.addEventListener('mouseenter', function() { - imgItemInfo.style.opacity = 1 - }) - - imgItem.addEventListener('mouseleave', function() { - imgItemInfo.style.opacity = 0.5 - }) - } - - return true + return true; } function validateInput() { @@ -639,12 +614,11 @@ async function makeImage() { // create a file name with embedded prompt and metadata // for easier cateloging and comparison -function createFileName() { +function createFileName(seed) { // Most important information is the prompt let underscoreName = lastPromptUsed.replace(/[^a-zA-Z0-9]/g, '_') underscoreName = underscoreName.substring(0, 100) - const seed = seedField.value const steps = numInferenceStepsField.value const guidance = guidanceScaleField.value @@ -1215,4 +1189,4 @@ async function loadModifiers() { } catch (e) { console.log('error fetching modifiers', e) } -} +} \ No newline at end of file From 5ba802dc68f8a1dcc1fa4133e792dcb2a3e2b0b4 Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Mon, 26 Sep 2022 17:50:27 +0300 Subject: [PATCH 02/20] Overlaid info --- ui/media/main.css | 30 +++++++++++++++++++----------- ui/media/main.js | 10 ++++------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ui/media/main.css b/ui/media/main.css index 7b01e14b..4c742a1c 100644 --- a/ui/media/main.css +++ b/ui/media/main.css @@ -69,27 +69,35 @@ label { font-size: 8pt; } .imgSeedLabel { - font-size: 1.3em; + font-size: 1em; + background-color: rgb(44, 45, 48); + border-radius: 5px; + padding: 5px; } .imgItem { display: inline-block; - width: fit-content; - height: fit-content; - padding: 0.5em; - border: 1px solid rgb(255 255 255 / 25%); margin-top: 1em; margin-right: 1em; } +.imgContainer { + display: flex; + justify-content: flex-end; +} .imgItemInfo { - width: 100%; - height: 2em; padding-bottom: 0.5em; display: flex; - align-items: center; - justify-content: space-between; + align-items: flex-end; + flex-direction: column; + position: absolute; + padding: 5px; + opacity: 0.25; + transition: 0.1s all; } -.imgInfoLeft { - margin-right: 1em; +.imgContainer:hover > .imgItemInfo { + opacity: 1; +} +.imgItemInfo * { + margin-bottom: 7px; } #container { width: 90%; diff --git a/ui/media/main.js b/ui/media/main.js index fb394981..171545a1 100644 --- a/ui/media/main.js +++ b/ui/media/main.js @@ -271,16 +271,14 @@ function showImages(res, req) { const imageItemElem = document.createElement('div'); imageItemElem.className = 'imgItem'; imageItemElem.innerHTML = ` -
-
+
+ +
-
-
- `; const imageElem = imageItemElem.querySelector('img'), @@ -292,7 +290,7 @@ function showImages(res, req) { imageElem.width = parseInt(imageWidth); imageElem.height = parseInt(imageHeight); - imageSeedLabel.innerText = imageSeed; + imageSeedLabel.innerText = 'Seed: ' + imageSeed; useAsInputBtn.addEventListener('click', () => { initImageSelector.value = null; From c1dea44fa6581a48a0f3123b5a27ac3a87b5ee1c Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Tue, 27 Sep 2022 17:23:19 +0300 Subject: [PATCH 03/20] Fix for live preview --- ui/media/main.js | 127 ++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/ui/media/main.js b/ui/media/main.js index 171545a1..334947c0 100644 --- a/ui/media/main.js +++ b/ui/media/main.js @@ -251,71 +251,81 @@ async function healthCheck() { } } -function showImages(res, req) { - res.output.forEach(result => { +function showImages(req, res, livePreview) { + res.output.forEach((result, index) => { if(typeof res != 'object') return; - const imageData = result?.data, - imageSeed = result?.seed, + const imageData = result?.data || result?.path, + imageSeed = req.seed + index, imageWidth = req.width, - imageHeight = req.height; + imageHeight = req.height, + imageIdentifier = 'IMG_' + (imageSeed + '').replace(/\d/g, c => 'SUOMIPERKL'[c]); + + if (!imageData) { + // res contained no data for the image, stop execution - // don't continue if data is incorrect - if (!(imageData && imageSeed)) - { setStatus('request', 'invalid image', 'error'); - console.log(imageData); return; } - const imageItemElem = document.createElement('div'); - imageItemElem.className = 'imgItem'; - imageItemElem.innerHTML = ` -
- -
- - - -
-
- `; - - const imageElem = imageItemElem.querySelector('img'), - imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'), - useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'), - saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); + let imageItemElem = document.querySelector('#' + imageIdentifier); - imageElem.src = imageData; + if(!imageItemElem) { + imageItemElem = document.createElement('div'); + imageItemElem.className = 'imgItem'; + imageItemElem.id = imageIdentifier; + imageItemElem.innerHTML = ` +
+ +
+ + + +
+
+ `; + + const useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'); + const saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); + + useAsInputBtn.addEventListener('click', () => { + initImageSelector.value = null; + initImagePreview.src = imageData; + + initImagePreviewContainer.style.display = 'block'; + inpaintingEditorContainer.style.display = 'none'; + promptStrengthContainer.style.display = 'block'; + maskSetting.checked = false; + + // maskSetting.style.display = 'block'; + + randomSeedField.checked = false; + seedField.value = imageSeed; + seedField.disabled = false; + }); + + saveImageBtn.addEventListener('click', () => { + const imgDownload = document.createElement('a'); + imgDownload.download = createFileName(imageSeed); + imgDownload.href = imageData; + imgDownload.click(); + }); + + imagesContainer.appendChild(imageItemElem); + } + + const imageElem = imageItemElem.querySelector('img'); + const imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'); + + imageElem.src = livePreview + ? imageData + '?t=' + new Date().getTime() + : imageData; imageElem.width = parseInt(imageWidth); imageElem.height = parseInt(imageHeight); - imageSeedLabel.innerText = 'Seed: ' + imageSeed; - - useAsInputBtn.addEventListener('click', () => { - initImageSelector.value = null; - initImagePreview.src = imageData; - - initImagePreviewContainer.style.display = 'block'; - inpaintingEditorContainer.style.display = 'none'; - promptStrengthContainer.style.display = 'block'; - maskSetting.checked = false; - - // maskSetting.style.display = 'block'; - - randomSeedField.checked = false; - seedField.value = imageSeed; - seedField.disabled = false; - }); - - saveImageBtn.addEventListener('click', () => { - const imgDownload = document.createElement('a'); - imgDownload.download = createFileName(imageSeed); - imgDownload.href = imageData; - imgDownload.click(); - }); - - imagesContainer.appendChild(imageItemElem); + imageSeedLabel.innerText = livePreview + ? '(Live Preview)' + : 'Seed: ' + imageSeed; }); } @@ -381,14 +391,7 @@ async function doMakeImage(reqBody, batchCount) { progressBar.style.display = 'block' if (stepUpdate.output !== undefined) { - makeImageContainers(numOutputs) - - for (idx in stepUpdate.output) { - let imgItem = images[idx] - let img = imgItem.firstChild - let tmpImageData = stepUpdate.output[idx] - img.src = tmpImageData['path'] + '?t=' + new Date().getTime() - } + showImages(reqBody, stepUpdate, true); } } } catch (e) { @@ -461,7 +464,7 @@ async function doMakeImage(reqBody, batchCount) { lastPromptUsed = reqBody['prompt']; - showImages(res, reqBody); + showImages(reqBody, res, false); return true; } From 10c4bee1e501322b679c8db5251d7c8b6bcffc2e Mon Sep 17 00:00:00 2001 From: Haka <76921756+Hakorr@users.noreply.github.com> Date: Wed, 28 Sep 2022 00:05:34 +0300 Subject: [PATCH 04/20] Fix for show all images --- ui/media/main.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/ui/media/main.js b/ui/media/main.js index 334947c0..fe5652f1 100644 --- a/ui/media/main.js +++ b/ui/media/main.js @@ -255,13 +255,13 @@ function showImages(req, res, livePreview) { res.output.forEach((result, index) => { if(typeof res != 'object') return; - const imageData = result?.data || result?.path, - imageSeed = req.seed + index, + const imageData = result?.data || result?.path + '?t=' + new Date().getTime(), + imageSeed = req.seed, imageWidth = req.width, imageHeight = req.height, - imageIdentifier = 'IMG_' + (imageSeed + '').replace(/\d/g, c => 'SUOMIPERKL'[c]); + imageIdentifier = 'IMG_ID_' + (imageSeed + '').replace(/\d/g, c => 'SUOMIPERKL'[c]) + 'X'.repeat(index); - if (!imageData) { + if (!imageData.includes('/')) { // res contained no data for the image, stop execution setStatus('request', 'invalid image', 'error'); @@ -285,12 +285,14 @@ function showImages(req, res, livePreview) {
`; - const useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'); - const saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); + const useAsInputBtn = imageItemElem.querySelector('.imgUseBtn'), + saveImageBtn = imageItemElem.querySelector('.imgSaveBtn'); + + useAsInputBtn.addEventListener('click', e => { + const imgData = e.path.find(x => x == imageItemElem).querySelector('img').src; - useAsInputBtn.addEventListener('click', () => { initImageSelector.value = null; - initImagePreview.src = imageData; + initImagePreview.src = imgData; initImagePreviewContainer.style.display = 'block'; inpaintingEditorContainer.style.display = 'none'; @@ -303,23 +305,23 @@ function showImages(req, res, livePreview) { seedField.value = imageSeed; seedField.disabled = false; }); - - saveImageBtn.addEventListener('click', () => { + + saveImageBtn.addEventListener('click', e => { + const imgData = e.path.find(x => x == imageItemElem).querySelector('img').src; + const imgDownload = document.createElement('a'); imgDownload.download = createFileName(imageSeed); - imgDownload.href = imageData; + imgDownload.href = imgData; imgDownload.click(); }); imagesContainer.appendChild(imageItemElem); } - const imageElem = imageItemElem.querySelector('img'); - const imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'); + const imageElem = imageItemElem.querySelector('img'), + imageSeedLabel = imageItemElem.querySelector('.imgSeedLabel'); - imageElem.src = livePreview - ? imageData + '?t=' + new Date().getTime() - : imageData; + imageElem.src = imageData; imageElem.width = parseInt(imageWidth); imageElem.height = parseInt(imageHeight); From a28f1294e28faef98f54bfdff9f16339a9f6433c Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 29 Sep 2022 13:01:18 +0530 Subject: [PATCH 05/20] Integrate with beta; Use the outputContainer for the task; Don't show the info while a live preview is generating; Use the local task container reference instead of a seed-based identifier (will fail if the seed is same across two tasks) --- ui/index.html | 4 +-- ui/media/main.css | 6 ++-- ui/media/main.js | 87 +++++++++++++++++++++++++++-------------------- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/ui/index.html b/ui/index.html index ed35db3c..5e2d94dc 100644 --- a/ui/index.html +++ b/ui/index.html @@ -4,7 +4,7 @@ - + @@ -213,7 +213,7 @@
- + + + + +