Move the current implementation of upscale/redo/double size into a custom plugin

This commit is contained in:
cmdr2 2022-10-19 20:27:06 +05:30
parent af05d94198
commit 602686a5d2
2 changed files with 51 additions and 5 deletions

View File

@ -369,13 +369,8 @@ function showImages(reqBody, res, outputContainer, livePreview) {
const buttons = { const buttons = {
'imgUseBtn': { text: 'Use as Input', on_click: onUseAsInputClick }, 'imgUseBtn': { text: 'Use as Input', on_click: onUseAsInputClick },
'imgSaveBtn': { text: 'Download', on_click: onDownloadImageClick }, 'imgSaveBtn': { text: 'Download', on_click: onDownloadImageClick },
'imgX2Btn': { text: 'Double Size', on_click: getStartNewTaskHandler('img2img_X2') },
'imgRedoBtn': { text: 'Redo', on_click: getStartNewTaskHandler('img2img') },
'makeSimilarBtn': { text: 'Make Similar Images', on_click: onMakeSimilarClick }, 'makeSimilarBtn': { text: 'Make Similar Images', on_click: onMakeSimilarClick },
} }
if (!req.use_upscale) {
buttons.upscaleBtn = { text: 'Upscale', on_click: getStartNewTaskHandler('upscale') }
}
// include the plugins // include the plugins
Object.assign(buttons, PLUGINS['IMAGE_INFO_BUTTONS']) Object.assign(buttons, PLUGINS['IMAGE_INFO_BUTTONS'])

View File

@ -26,3 +26,54 @@ const PLUGINS = {
*/ */
IMAGE_INFO_BUTTONS: {} IMAGE_INFO_BUTTONS: {}
} }
PLUGINS['IMAGE_INFO_BUTTONS']['custom_imgX2Btn'] = { text: 'Double Size', on_click: getStartNewTaskHandler('img2img_X2') }
PLUGINS['IMAGE_INFO_BUTTONS']['custom_imgRedoBtn'] = { text: 'Redo', on_click: getStartNewTaskHandler('img2img') }
PLUGINS['IMAGE_INFO_BUTTONS']['custom_upscaleBtn'] = { text: 'Upscale', on_click: getStartNewTaskHandler('upscale'), filter: (req, img) => !req.use_upscale }
function getStartNewTaskHandler(mode) {
return function(reqBody, img) {
const newTaskRequest = getCurrentUserRequest()
switch (mode) {
case 'img2img':
case 'img2img_X2':
newTaskRequest.reqBody = Object.assign({}, reqBody, {
num_outputs: 1,
use_cpu: useCPUField.checked,
})
if (!newTaskRequest.reqBody.init_image || mode === 'img2img_X2') {
newTaskRequest.reqBody.sampler = 'ddim'
newTaskRequest.reqBody.prompt_strength = '0.5'
newTaskRequest.reqBody.init_image = img.src
delete newTaskRequest.reqBody.mask
} else {
newTaskRequest.reqBody.seed = 1 + newTaskRequest.reqBody.seed
}
if (mode === 'img2img_X2') {
newTaskRequest.reqBody.width = reqBody.width * 2
newTaskRequest.reqBody.height = reqBody.height * 2
newTaskRequest.reqBody.num_inference_steps = Math.min(100, reqBody.num_inference_steps * 2)
if (useUpscalingField.checked) {
newTaskRequest.reqBody.use_upscale = upscaleModelField.value
} else {
delete newTaskRequest.reqBody.use_upscale
}
}
break
case 'upscale':
newTaskRequest.reqBody = Object.assign({}, reqBody, {
num_outputs: 1,
//use_face_correction: 'GFPGANv1.3',
use_upscale: upscaleModelField.value,
})
break
default:
throw new Error("Unknown upscale mode: " + mode)
}
newTaskRequest.seed = newTaskRequest.reqBody.seed
newTaskRequest.numOutputsTotal = 1
newTaskRequest.batchCount = 1
createTask(newTaskRequest)
}
}