sdkit 1.0.151 - An option to use strict mask borders

This commit is contained in:
cmdr2 2023-07-30 13:51:19 +05:30
parent 2e849827d1
commit 1d6742f463
5 changed files with 45 additions and 32 deletions

View File

@ -18,7 +18,7 @@ os_name = platform.system()
modules_to_check = { modules_to_check = {
"torch": ("1.11.0", "1.13.1", "2.0.0"), "torch": ("1.11.0", "1.13.1", "2.0.0"),
"torchvision": ("0.12.0", "0.14.1", "0.15.1"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"),
"sdkit": "1.0.148", "sdkit": "1.0.151",
"stable-diffusion-sdkit": "2.1.4", "stable-diffusion-sdkit": "2.1.4",
"rich": "12.6.0", "rich": "12.6.0",
"uvicorn": "0.19.0", "uvicorn": "0.19.0",

View File

@ -21,6 +21,7 @@ class GenerateImageRequest(BaseModel):
control_alpha: Union[float, List[float]] = None control_alpha: Union[float, List[float]] = None
prompt_strength: float = 0.8 prompt_strength: float = 0.8
preserve_init_image_color_profile = False preserve_init_image_color_profile = False
strict_mask_border = False
sampler_name: str = None # "ddim", "plms", "heun", "euler", "euler_a", "dpm2", "dpm2_a", "lms" sampler_name: str = None # "ddim", "plms", "heun", "euler", "euler_a", "dpm2", "dpm2_a", "lms"
hypernetwork_strength: float = 0 hypernetwork_strength: float = 0

View File

@ -109,6 +109,7 @@
</div> </div>
<div id="apply_color_correction_setting" class="pl-5"><input id="apply_color_correction" name="apply_color_correction" type="checkbox"> <label for="apply_color_correction">Preserve color profile <small>(helps during inpainting)</small></label></div> <div id="apply_color_correction_setting" class="pl-5"><input id="apply_color_correction" name="apply_color_correction" type="checkbox"> <label for="apply_color_correction">Preserve color profile <small>(helps during inpainting)</small></label></div>
<div id="strict_mask_border_setting" class="pl-5"><input id="strict_mask_border" name="strict_mask_border" type="checkbox"> <label for="strict_mask_border">Strict Mask Border <small>(won't modify outside the mask, but the mask border might be visible)</small></label></div>
</div> </div>

View File

@ -626,6 +626,7 @@ class ImageEditor {
.getImageData(0, 0, this.width, this.height) .getImageData(0, 0, this.width, this.height)
.data.some((channel) => channel !== 0) .data.some((channel) => channel !== 0)
maskSetting.checked = !is_blank maskSetting.checked = !is_blank
maskSetting.dispatchEvent(new Event("change"))
} }
this.hide() this.hide()
} }

View File

@ -49,6 +49,7 @@ const taskConfigSetup = {
use_lora_model: { label: "Lora Model", visible: ({ reqBody }) => !!reqBody?.use_lora_model }, use_lora_model: { label: "Lora Model", visible: ({ reqBody }) => !!reqBody?.use_lora_model },
lora_alpha: { label: "Lora Strength", visible: ({ reqBody }) => !!reqBody?.use_lora_model }, lora_alpha: { label: "Lora Strength", visible: ({ reqBody }) => !!reqBody?.use_lora_model },
preserve_init_image_color_profile: "Preserve Color Profile", preserve_init_image_color_profile: "Preserve Color Profile",
strict_mask_border: "Strict Mask Border",
}, },
pluginTaskConfig: {}, pluginTaskConfig: {},
getCSSKey: (key) => getCSSKey: (key) =>
@ -93,7 +94,9 @@ let initImageSizeBox = document.querySelector("#init_image_size_box")
let maskImageSelector = document.querySelector("#mask") let maskImageSelector = document.querySelector("#mask")
let maskImagePreview = document.querySelector("#mask_preview") let maskImagePreview = document.querySelector("#mask_preview")
let applyColorCorrectionField = document.querySelector("#apply_color_correction") let applyColorCorrectionField = document.querySelector("#apply_color_correction")
let strictMaskBorderField = document.querySelector("#strict_mask_border")
let colorCorrectionSetting = document.querySelector("#apply_color_correction_setting") let colorCorrectionSetting = document.querySelector("#apply_color_correction_setting")
let strictMaskBorderSetting = document.querySelector("#strict_mask_border_setting")
let promptStrengthSlider = document.querySelector("#prompt_strength_slider") let promptStrengthSlider = document.querySelector("#prompt_strength_slider")
let promptStrengthField = document.querySelector("#prompt_strength") let promptStrengthField = document.querySelector("#prompt_strength")
let samplerField = document.querySelector("#sampler_name") let samplerField = document.querySelector("#sampler_name")
@ -1386,6 +1389,7 @@ function getCurrentUserRequest() {
// } // }
if (maskSetting.checked) { if (maskSetting.checked) {
newTask.reqBody.mask = imageInpainter.getImg() newTask.reqBody.mask = imageInpainter.getImg()
newTask.reqBody.strict_mask_border = strictMaskBorderField.checked
} }
newTask.reqBody.preserve_init_image_color_profile = applyColorCorrectionField.checked newTask.reqBody.preserve_init_image_color_profile = applyColorCorrectionField.checked
if (!testDiffusers.checked) { if (!testDiffusers.checked) {
@ -2091,6 +2095,7 @@ function img2imgLoad() {
} }
initImagePreviewContainer.classList.add("has-image") initImagePreviewContainer.classList.add("has-image")
colorCorrectionSetting.style.display = "" colorCorrectionSetting.style.display = ""
strictMaskBorderSetting.style.display = maskSetting.checked ? "" : "none"
initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight initImageSizeBox.textContent = initImagePreview.naturalWidth + " x " + initImagePreview.naturalHeight
imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight) imageEditor.setImage(this.src, initImagePreview.naturalWidth, initImagePreview.naturalHeight)
@ -2108,6 +2113,7 @@ function img2imgUnload() {
} }
initImagePreviewContainer.classList.remove("has-image") initImagePreviewContainer.classList.remove("has-image")
colorCorrectionSetting.style.display = "none" colorCorrectionSetting.style.display = "none"
strictMaskBorderSetting.style.display = "none"
imageEditor.setImage(null, parseInt(widthField.value), parseInt(heightField.value)) imageEditor.setImage(null, parseInt(widthField.value), parseInt(heightField.value))
} }
initImagePreview.addEventListener("load", img2imgLoad) initImagePreview.addEventListener("load", img2imgLoad)
@ -2116,6 +2122,9 @@ initImageClearBtn.addEventListener("click", img2imgUnload)
maskSetting.addEventListener("click", function() { maskSetting.addEventListener("click", function() {
onDimensionChange() onDimensionChange()
}) })
maskSetting.addEventListener("change", function() {
strictMaskBorderSetting.style.display = this.checked ? "" : "none"
})
promptsFromFileBtn.addEventListener("click", function() { promptsFromFileBtn.addEventListener("click", function() {
promptsFromFileSelector.click() promptsFromFileSelector.click()
@ -2583,12 +2592,14 @@ createLoraEntries()
////////////////////////////// Image Size Widget ////////////////////////////////////////// ////////////////////////////// Image Size Widget //////////////////////////////////////////
function roundToMultiple(number, n) { function roundToMultiple(number, n) {
if (n=="") { n=1 } if (n == "") {
return Math.round(number / n) * n; n = 1
}
return Math.round(number / n) * n
} }
function addImageSizeOption(size) { function addImageSizeOption(size) {
let sizes = Object.values(widthField.options).map(o => o.value) let sizes = Object.values(widthField.options).map((o) => o.value)
if (!sizes.includes(String(size))) { if (!sizes.includes(String(size))) {
sizes.push(String(size)) sizes.push(String(size))
sizes.sort((a, b) => Number(a) - Number(b)) sizes.sort((a, b) => Number(a) - Number(b))
@ -2600,7 +2611,6 @@ function addImageSizeOption(size) {
widthField.add(option, sizes.indexOf(String(size))) widthField.add(option, sizes.indexOf(String(size)))
heightField.add(option.cloneNode(true), sizes.indexOf(String(size))) heightField.add(option.cloneNode(true), sizes.indexOf(String(size)))
} }
} }
function setImageWidthHeight(w, h) { function setImageWidthHeight(w, h) {
@ -2628,10 +2638,11 @@ function enlargeImageSize(factor) {
let recentResolutionsValues = [] let recentResolutionsValues = []
;(function() { ///// Init resolutions dropdown ;(function() {
///// Init resolutions dropdown
function makeResolutionButtons() { function makeResolutionButtons() {
recentResolutionList.innerHTML = "" recentResolutionList.innerHTML = ""
recentResolutionsValues.forEach( el => { recentResolutionsValues.forEach((el) => {
let button = document.createElement("button") let button = document.createElement("button")
button.classList.add("tertiaryButton") button.classList.add("tertiaryButton")
button.style.width = "8em" button.style.width = "8em"
@ -2682,7 +2693,7 @@ let recentResolutionsValues = []
let w = widthField.value let w = widthField.value
let h = heightField.value let h = heightField.value
recentResolutionsValues = recentResolutionsValues.filter(el => (el.w!=w || el.h!=h)) recentResolutionsValues = recentResolutionsValues.filter((el) => el.w != w || el.h != h)
recentResolutionsValues.unshift({ w: w, h: h }) recentResolutionsValues.unshift({ w: w, h: h })
recentResolutionsValues = recentResolutionsValues.slice(0, 8) recentResolutionsValues = recentResolutionsValues.slice(0, 8)
@ -2707,7 +2718,7 @@ let recentResolutionsValues = []
} }
makeResolutionButtons() makeResolutionButtons()
recentResolutionsValues.forEach( val => { recentResolutionsValues.forEach((val) => {
addImageSizeOption(val.w) addImageSizeOption(val.w)
addImageSizeOption(val.h) addImageSizeOption(val.h)
}) })
@ -2746,4 +2757,3 @@ let recentResolutionsValues = []
heightField.value = temp heightField.value = temp
}) })
})() })()