well all the dynamic prompts garbage was a waste of time because it seems to REALLY be "alwayson_" script

This commit is contained in:
tim h 2023-07-08 10:49:56 -05:00
parent 07f0539c2e
commit c8252299f9
6 changed files with 252 additions and 20 deletions

View file

@ -128,6 +128,12 @@
mask-image: url("../res/icons/slice.svg");
}
.ui.inline-icon.icon-joystick::after,
.ui.icon > .icon-joystick {
-webkit-mask-image: url("../res/icons/joystick.svg");
mask-image: url("../res/icons/joystick.svg");
}
.ui.inline-icon.icon-save::after,
.ui.icon > .icon-save {
-webkit-mask-image: url("../res/icons/save.svg");

View file

@ -143,7 +143,7 @@
id="seed"
onchange="changeSeed()"
min="-1"
max="9999999999"
max="99999999999999999999"
value="-1"
step="1" />
<br />
@ -195,7 +195,31 @@
step="1"
onchange="changeMaskBlur()" />
</div>
<!-- Extensions section -->
<button type="button" class="collapsible">Extensions</button>
<div class="content">
<!-- <input
type="checkbox"
id="cbxDynPrompts"
onchange="changeDynamicPromptsExtension()"
disabled="disabled" />
<label for="cbxDynPrompts">Dynamic Prompts</label>
<br /> -->
<input
type="checkbox"
id="cbxControlNet"
onchange="changeControlNetExtension()"
disabled="disabled" />
<label for="cbxControlNet">ControlNet In/Outpainting</label>
<br class="controlnetElement" />
<label id="cnModuleLabel" class="controlnetElement">
CN Preprocessor
</label>
<div id="controlNetModule" class="controlnetElement"></div>
<label id="cnModelLabel" class="controlnetElement">CN Model</label>
<div id="controlNetModel" class="controlnetElement"></div>
<!-- <div id="referenceStyleFidelity" class="controlnetElement"></div> -->
</div>
<!-- Save/load image section -->
<button type="button" class="collapsible">Save/Upscaling</button>
<div class="content">
@ -441,6 +465,7 @@
<!-- Basics -->
<script src="js/global.js?v=ac30d16" type="text/javascript"></script>
<script src="js/defaults.js?v=5b06818" type="text/javascript"></script>
<script src="js/extensions.js" type="text/javascript"></script>
<!-- Base Libs -->
<script src="js/lib/util.js?v=379aef7" type="text/javascript"></script>

124
js/extensions.js Normal file
View file

@ -0,0 +1,124 @@
/**
* Extensions helper thing or class or whatever
*/
const extensions = {
// alwaysOnScriptsData: {},
alwaysOnScripts: false,
controlNetEnabled: false,
controlNetActive: false,
dynamicPromptsEnabled: false,
dynamicPromptsActive: false,
dynamicPromptsAlwaysonScriptName: null, //GRUMBLE GRUMBLE
enabledExtensions: [],
controlNetModels: null,
controlNetModules: null,
async getExtensions() {
const allowedExtensions = [
"controlnet",
// "none",
// "adetailer", // no API, can't verify available models
"dynamic prompts", //seriously >:( why put version in the name, now i have to fuzzy match it - just simply enabled or not? no API but so so good
//"segment anything", // ... API lets me get model but not processor?!?!?!
//"self attention guidance", // no API but useful, just enabled button, scale and threshold sliders?
];
// check http://127.0.0.1:7860/sdapi/v1/scripts for extensions
// if any of the allowed extensions are found, add them to the list
var url = document.getElementById("host").value + "/sdapi/v1/scripts";
try {
const response = await fetch(url);
const data = await response.json();
// enable checkboxes for extensions based on existence in data
data.img2img
.filter((extension) => {
return allowedExtensions.some((allowedExtension) => {
return extension.toLowerCase().includes(allowedExtension);
});
})
.forEach((extension) => {
this.enabledExtensions.push(extension);
});
} catch (e) {
console.warn("[index] Failed to fetch extensions");
console.warn(e);
}
this.checkForDynamicPrompts();
this.checkForControlNet();
//checkForSAM(); //or inpaintAnything or something i dunno
//checkForADetailer(); //? this one seems iffy
//checkForSAG(); //??
},
async checkForDynamicPrompts() {
// if (
// this.enabledExtensions.filter((e) => e.includes("dynamic prompts"))
// .length > 0
// ) {
// // Dynamic Prompts found, enable checkbox
// this.alwaysOnScripts = true;
// this.dynamicPromptsAlwaysonScriptName =
// this.enabledExtensions[
// this.enabledExtensions.findIndex((e) => e.includes("dynamic prompts"))
// ];
// // this.alwaysOnScriptsData[this.dynamicPromptsAlwaysonScriptName] = {};
// this.dynamicPromptsEnabled = true;
// document.getElementById("cbxDynPrompts").disabled = false;
// }
// basically param 0 is true for on, false for off, that's it
},
async checkForControlNet() {
var url = document.getElementById("host").value + "/controlnet/version";
try {
const response = await fetch(url);
const data = await response.json();
if (
data.version > 0 &&
this.enabledExtensions.filter((e) => e.includes("controlnet")).length >
0
) {
// ControlNet found
this.alwaysOnScripts = true;
this.controlNetEnabled = true;
document.getElementById("cbxControlNet").disabled = false;
// ok cool so now we can get the models and modules
this.getModels();
this.getModules();
}
} catch (e) {
// ??
global.controlnetAPI = false;
}
},
async getModels() {
// only worry about inpaint models for now
var url = document.getElementById("host").value + "/controlnet/model_list";
try {
const response = await fetch(url);
const data = await response.json();
this.controlNetModels = data.model_list;
} catch (e) {
console.warn("[extensions] Failed to fetch controlnet models");
console.warn(e);
}
},
async getModules() {
const allowedModules = ["reference", "inpaint"];
var url = document.getElementById("host").value + "/controlnet/module_list";
try {
const response = await fetch(url);
const data = await response.json();
this.controlNetModules = data;
} catch (e) {
console.warn("[extensions] Failed to fetch controlnet modules");
console.warn(e);
}
},
};

View file

@ -171,6 +171,7 @@ function startup() {
changeHiResSquare();
changeRestoreFaces();
changeSyncCursorSize();
changeControlNetExtension();
checkFocus();
refreshScripts();
}
@ -421,6 +422,10 @@ async function testHostConnection() {
getSamplers();
getUpscalers();
getModels();
extensions.getExtensions();
// getLoras();
// getTIEmbeddings();
// getHypernets();
firstTimeOnline = false;
}
break;
@ -659,6 +664,11 @@ const hrFixUpscalerAutoComplete = createAutoComplete(
document.getElementById("hrFixUpscaler")
);
// const extensionsAutoComplete = createAutoComplete(
// "Extension",
// document.getElementById("extension-ac-select")
// );
hrFixUpscalerAutoComplete.onchange.on(({value}) => {
stableDiffusionData.hr_upscaler = value;
localStorage.setItem(`openoutpaint/hr_upscaler`, value);
@ -798,6 +808,25 @@ function changeHRFY() {
document.getElementById("hr_resize_y").value;
}
function changeDynamicPromptsExtension() {
// extensions.dynamicPromptsActive =
// document.getElementById("cbxDynPrompts").checked;
}
function changeControlNetExtension() {
extensions.controlNetActive =
document.getElementById("cbxControlNet").checked;
if (extensions.controlNetActive) {
document
.querySelectorAll(".controlnetElement")
.forEach((el) => el.classList.remove("invisible"));
} else {
document
.querySelectorAll(".controlnetElement")
.forEach((el) => el.classList.add("invisible"));
}
}
function changeHiResFix() {
stableDiffusionData.enable_hr = Boolean(
document.getElementById("cbxHRFix").checked
@ -1247,6 +1276,7 @@ async function getSamplers() {
console.warn(e);
}
}
async function upscaleAndDownload() {
// Future improvements: some upscalers take a while to upscale, so we should show a loading bar or something, also a slider for the upscale amount

View file

@ -1013,9 +1013,15 @@ const dream_generate_callback = async (bb, resolution, state) => {
// Get visible pixels
const visibleCanvas = uil.getVisible(bb);
if (extensions.alwaysOnScripts) {
buildAlwaysOnScripts(state);
}
// Use txt2img if canvas is blank
if (isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas) || state.controlNet) {
//TODO 20230630 - controlnet literally broken right before i implement it??? https://github.com/Mikubill/sd-webui-controlnet/issues/1719
if (
isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas) ||
(state.controlNet && global.controlnetAPI)
) {
//TODO why doesn't smooth rendering toggle persist/localstorage? why am i putting this here? because i'm lazy
//TODO this logic seems crappy, fix it
@ -1118,20 +1124,6 @@ const dream_generate_callback = async (bb, resolution, state) => {
request.width,
request.height
);
if (state.controlNet) {
state.alwayson_scripts = {};
state.alwayson_scripts.controlnet = {};
state.alwayson_scripts.controlnet.args = [
{
input_image: initCanvas.toDataURL(),
mask: maskCanvas.toDataURL(),
module: "inpaint_only+lama", //TODO make this a variable with API supplied options
model: "control_v11p_sd15_inpaint [ebff9138]", //TODO make this a variable with API supplied options
},
];
request.alwayson_scripts = state.alwayson_scripts;
}
}
// request.alwayson_scripts = state.alwayson_scripts;
@ -1204,6 +1196,17 @@ const dream_generate_callback = async (bb, resolution, state) => {
? stableDiffusionData.hr_denoising_strength
: 1;
// add dynamic prompts stuff if it's enabled
if (extensions.dynamicPromptsActive) {
addDynamicPromptsToAlwaysOnScripts(state);
}
if (extensions.controlNetActive) {
addControlNetToAlwaysOnScripts(state);
}
if (extensions.alwaysOnScripts) {
// check again just to be sure because i'm an idiot?
request.alwayson_scripts = state.alwayson_scripts;
}
// Dream
_generate("txt2img", request, bb);
} else {
@ -2015,7 +2018,7 @@ const dreamTool = () =>
"openoutpaint/dream-controlnet",
"controlNet",
"Toggle ControlNet In/Outpainting",
"icon-question"
"icon-joystick"
).checkbox;
// Overmasking Slider
@ -2085,7 +2088,10 @@ const dreamTool = () =>
//menu.appendChild(document.createElement("br"));
array.appendChild(state.ctxmenu.keepUnmaskedLabel);
array.appendChild(state.ctxmenu.removeBackgroundLabel);
array.appendChild(state.ctxmenu.controlNetLabel);
//TODO: if (global.controlnetAPI) { //but figure out how to update the UI after doing so
// never mind i think i'm using an extension menu instead
// array.appendChild(state.ctxmenu.controlNetLabel);
//}
menu.appendChild(array);
menu.appendChild(state.ctxmenu.keepUnmaskedBlurSlider);
menu.appendChild(state.ctxmenu.carveBlurSlider);
@ -2768,3 +2774,43 @@ const img2imgTool = () =>
const sendSeed = (seed) => {
stableDiffusionData.seed = document.getElementById("seed").value = seed;
};
function buildAlwaysOnScripts(state) {
if (extensions.alwaysOnScripts) {
state.alwayson_scripts = {};
}
//TODO find way to remove alwayson_scripts if not active?
}
function addDynamicPromptsToAlwaysOnScripts(state) {
//TODO ok seriously does this even NEED TO BE HERE?!?!?! it's like dynamic scripts is always on no matter what i fucking say...
// if (extensions.dynamicPromptsActive) {
// state.alwayson_scripts[extensions.dynamicPromptsAlwaysonScriptName] = {};
// var dynval = document.getElementById("cbxDynPrompts").checked;
// state.alwayson_scripts[extensions.dynamicPromptsAlwaysonScriptName].args = [
// {
// 0: dynval,
// },
// ];
// }
}
function addControlNetToAlwaysOnScripts(state) {
// if (state.controlNet) {
// state.alwayson_scripts = {};
// state.alwayson_scripts.controlnet = {};
// state.alwayson_scripts.controlnet.args = [
// {
// input_image: initCanvas.toDataURL(),
// mask: maskCanvas.toDataURL(),
// module: "inpaint_only+lama", //TODO make this a variable with API supplied options - inpaint_global_harmonious good for img2img for POC?
// model: "control_v11p_sd15_inpaint [ebff9138]", //TODO make this a variable with API supplied options
// // control mode?
// // resize mode?
// // weights / steps?
// },
// ];
// request.alwayson_scripts = state.alwayson_scripts;
// }
}

1
res/icons/joystick.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-joystick"><path d="M21 17a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-2Z"/><path d="M6 15v-2"/><path d="M12 15V9"/><circle cx="12" cy="6" r="3"/></svg>

After

Width:  |  Height:  |  Size: 373 B