From f701b8dc29ca17989b7af5a5dd7b674387d0ae87 Mon Sep 17 00:00:00 2001 From: Marc-Andre Ferland Date: Mon, 5 Dec 2022 00:16:10 -0500 Subject: [PATCH] Simplify onUpscaleClick (#602) * Simplified onUpscaleClick code. * Updated fix with comment as to what it's fixing. * Move the fix to enqueueImageVariationTask --- ui/media/js/main.js | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/ui/media/js/main.js b/ui/media/js/main.js index bac12087..687e0251 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -375,11 +375,21 @@ function onMakeSimilarClick(req, img) { function enqueueImageVariationTask(req, img, reqDiff) { const imageSeed = img.getAttribute('data-seed') - const newTaskRequest = modifyCurrentRequest(req, reqDiff, { + const newRequestBody = { 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) newTaskRequest.numOutputsTotal = 1 // this can be user-configurable in the future newTaskRequest.batchCount = 1 @@ -387,28 +397,9 @@ function enqueueImageVariationTask(req, img, reqDiff) { } function onUpscaleClick(req, img) { - if (IMAGE_REGEX.test(req.init_image) && IMAGE_REGEX.test(req.mask)) { - enqueueImageVariationTask(req, img, { - use_upscale: upscaleModelField.value, - init_image: req.init_image, - mask: req.mask - }) - } - else if (IMAGE_REGEX.test(req.init_image)) { - enqueueImageVariationTask(req, img, { - use_upscale: upscaleModelField.value, - init_image: req.init_image, - mask: undefined - }) - } - else - { - enqueueImageVariationTask(req, img, { - use_upscale: upscaleModelField.value, - init_image: undefined, - mask: undefined - }) - } + enqueueImageVariationTask(req, img, { + use_upscale: upscaleModelField.value + }) } function onFixFacesClick(req, img) {