b0121c83147577eb9727fe7ff6d755f7783afc96fc1f4bc321fe4afa32077ef2
Browse files
javascript/token-counters.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let promptTokenCountDebounceTime = 800;
|
| 2 |
+
let promptTokenCountTimeouts = {};
|
| 3 |
+
var promptTokenCountUpdateFunctions = {};
|
| 4 |
+
|
| 5 |
+
function update_txt2img_tokens(...args) {
|
| 6 |
+
// Called from Gradio
|
| 7 |
+
update_token_counter("txt2img_token_button");
|
| 8 |
+
if (args.length == 2) {
|
| 9 |
+
return args[0];
|
| 10 |
+
}
|
| 11 |
+
return args;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
function update_img2img_tokens(...args) {
|
| 15 |
+
// Called from Gradio
|
| 16 |
+
update_token_counter("img2img_token_button");
|
| 17 |
+
if (args.length == 2) {
|
| 18 |
+
return args[0];
|
| 19 |
+
}
|
| 20 |
+
return args;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function update_token_counter(button_id) {
|
| 24 |
+
if (opts.disable_token_counters) {
|
| 25 |
+
return;
|
| 26 |
+
}
|
| 27 |
+
if (promptTokenCountTimeouts[button_id]) {
|
| 28 |
+
clearTimeout(promptTokenCountTimeouts[button_id]);
|
| 29 |
+
}
|
| 30 |
+
promptTokenCountTimeouts[button_id] = setTimeout(
|
| 31 |
+
() => gradioApp().getElementById(button_id)?.click(),
|
| 32 |
+
promptTokenCountDebounceTime,
|
| 33 |
+
);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
function recalculatePromptTokens(name) {
|
| 38 |
+
promptTokenCountUpdateFunctions[name]?.();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function recalculate_prompts_txt2img() {
|
| 42 |
+
// Called from Gradio
|
| 43 |
+
recalculatePromptTokens('txt2img_prompt');
|
| 44 |
+
recalculatePromptTokens('txt2img_neg_prompt');
|
| 45 |
+
return Array.from(arguments);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function recalculate_prompts_img2img() {
|
| 49 |
+
// Called from Gradio
|
| 50 |
+
recalculatePromptTokens('img2img_prompt');
|
| 51 |
+
recalculatePromptTokens('img2img_neg_prompt');
|
| 52 |
+
return Array.from(arguments);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function setupTokenCounting(id, id_counter, id_button) {
|
| 56 |
+
var prompt = gradioApp().getElementById(id);
|
| 57 |
+
var counter = gradioApp().getElementById(id_counter);
|
| 58 |
+
var textarea = gradioApp().querySelector(`#${id} > label > textarea`);
|
| 59 |
+
|
| 60 |
+
if (opts.disable_token_counters) {
|
| 61 |
+
counter.style.display = "none";
|
| 62 |
+
return;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
if (counter.parentElement == prompt.parentElement) {
|
| 66 |
+
return;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
prompt.parentElement.insertBefore(counter, prompt);
|
| 70 |
+
prompt.parentElement.style.position = "relative";
|
| 71 |
+
|
| 72 |
+
promptTokenCountUpdateFunctions[id] = function() {
|
| 73 |
+
update_token_counter(id_button);
|
| 74 |
+
};
|
| 75 |
+
textarea.addEventListener("input", promptTokenCountUpdateFunctions[id]);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function setupTokenCounters() {
|
| 79 |
+
setupTokenCounting('txt2img_prompt', 'txt2img_token_counter', 'txt2img_token_button');
|
| 80 |
+
setupTokenCounting('txt2img_neg_prompt', 'txt2img_negative_token_counter', 'txt2img_negative_token_button');
|
| 81 |
+
setupTokenCounting('img2img_prompt', 'img2img_token_counter', 'img2img_token_button');
|
| 82 |
+
setupTokenCounting('img2img_neg_prompt', 'img2img_negative_token_counter', 'img2img_negative_token_button');
|
| 83 |
+
}
|
javascript/ui.js
ADDED
|
@@ -0,0 +1,2041 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function set_theme(theme) {
|
| 2 |
+
/*
|
| 3 |
+
var gradioURL = window.location.href;
|
| 4 |
+
if (!gradioURL.includes('?__theme=')) {
|
| 5 |
+
window.location.replace(gradioURL + '?__theme=' + theme);
|
| 6 |
+
}
|
| 7 |
+
*/
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
var selectedTabItemId = "tab_txt2img";
|
| 11 |
+
|
| 12 |
+
function all_gallery_buttons() {
|
| 13 |
+
var allGalleryButtons = gradioApp().querySelectorAll('[style="display: block;"].tabitem div[id$=_gallery].gradio-gallery .thumbnails > .thumbnail-item.thumbnail-small');
|
| 14 |
+
var visibleGalleryButtons = [];
|
| 15 |
+
allGalleryButtons.forEach(function(elem) {
|
| 16 |
+
if (elem.parentElement.offsetParent) {
|
| 17 |
+
visibleGalleryButtons.push(elem);
|
| 18 |
+
}
|
| 19 |
+
});
|
| 20 |
+
return visibleGalleryButtons;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function selected_gallery_button() {
|
| 24 |
+
var allCurrentButtons = gradioApp().querySelectorAll('[style="display: block;"].tabitem div[id$=_gallery].gradio-gallery .thumbnail-item.thumbnail-small.selected');
|
| 25 |
+
var visibleCurrentButton = null;
|
| 26 |
+
allCurrentButtons.forEach(function(elem) {
|
| 27 |
+
if (elem.parentElement.offsetParent) {
|
| 28 |
+
visibleCurrentButton = elem;
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
return visibleCurrentButton;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function selected_gallery_index() {
|
| 35 |
+
var buttons = all_gallery_buttons();
|
| 36 |
+
var button = selected_gallery_button();
|
| 37 |
+
|
| 38 |
+
var result = -1;
|
| 39 |
+
buttons.forEach(function(v, i) {
|
| 40 |
+
if (v == button) {
|
| 41 |
+
result = i;
|
| 42 |
+
}
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
return result;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function extract_image_from_gallery(gallery) {
|
| 49 |
+
if (gallery.length == 0) {
|
| 50 |
+
return [null];
|
| 51 |
+
}
|
| 52 |
+
if (gallery.length == 1) {
|
| 53 |
+
return [gallery[0]];
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
var index = selected_gallery_index();
|
| 57 |
+
|
| 58 |
+
if (index < 0 || index >= gallery.length) {
|
| 59 |
+
// Use the first image in the gallery as the default
|
| 60 |
+
index = 0;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
return [gallery[index]];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around
|
| 67 |
+
|
| 68 |
+
function switch_to_txt2img() {
|
| 69 |
+
gradioApp().querySelector('#tabs').querySelectorAll('button')[0].click();
|
| 70 |
+
|
| 71 |
+
return Array.from(arguments);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function switch_to_img2img_tab(no) {
|
| 75 |
+
gradioApp().querySelector('#tabs').querySelectorAll('button')[1].click();
|
| 76 |
+
gradioApp().getElementById('mode_img2img').querySelectorAll('button')[no].click();
|
| 77 |
+
}
|
| 78 |
+
function switch_to_img2img() {
|
| 79 |
+
switch_to_img2img_tab(0);
|
| 80 |
+
return Array.from(arguments);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function switch_to_sketch() {
|
| 84 |
+
switch_to_img2img_tab(1);
|
| 85 |
+
return Array.from(arguments);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
function switch_to_inpaint() {
|
| 89 |
+
switch_to_img2img_tab(2);
|
| 90 |
+
return Array.from(arguments);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
function switch_to_inpaint_sketch() {
|
| 94 |
+
switch_to_img2img_tab(3);
|
| 95 |
+
return Array.from(arguments);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function switch_to_extras() {
|
| 99 |
+
gradioApp().querySelector('#tabs').querySelectorAll('button')[2].click();
|
| 100 |
+
|
| 101 |
+
return Array.from(arguments);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
function get_tab_index(tabId) {
|
| 105 |
+
let buttons = gradioApp().getElementById(tabId).querySelector('div').querySelectorAll('button');
|
| 106 |
+
for (let i = 0; i < buttons.length; i++) {
|
| 107 |
+
if (buttons[i].classList.contains('selected')) {
|
| 108 |
+
return i;
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
return 0;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
function create_tab_index_args(tabId, args) {
|
| 115 |
+
var res = Array.from(args);
|
| 116 |
+
res[0] = get_tab_index(tabId);
|
| 117 |
+
return res;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function get_img2img_tab_index() {
|
| 121 |
+
let res = Array.from(arguments);
|
| 122 |
+
res.splice(-2);
|
| 123 |
+
res[0] = get_tab_index('mode_img2img');
|
| 124 |
+
return res;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function create_submit_args(args) {
|
| 128 |
+
var res = Array.from(args);
|
| 129 |
+
|
| 130 |
+
// As it is currently, txt2img and img2img send back the previous output args (txt2img_gallery, generation_info, html_info) whenever you generate a new image.
|
| 131 |
+
// This can lead to uploading a huge gallery of previously generated images, which leads to an unnecessary delay between submitting and beginning to generate.
|
| 132 |
+
// I don't know why gradio is sending outputs along with inputs, but we can prevent sending the image gallery here, which seems to be an issue for some.
|
| 133 |
+
// If gradio at some point stops sending outputs, this may break something
|
| 134 |
+
if (Array.isArray(res[res.length - 3])) {
|
| 135 |
+
res[res.length - 3] = null;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
return res;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
function showSubmitButtons(tabname, show) {
|
| 142 |
+
gradioApp().getElementById(tabname + "_interrupt").style.display = show ? "none" : "flex";
|
| 143 |
+
gradioApp().getElementById(tabname + "_skip").style.display = show ? "none" : "flex";
|
| 144 |
+
gradioApp().getElementById(tabname + "_generate").style.display = !show ? "none" : "flex";
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
function showRestoreProgressButton(tabname, show) {
|
| 148 |
+
var button = gradioApp().getElementById(tabname + "_restore_progress");
|
| 149 |
+
if (!button) return;
|
| 150 |
+
|
| 151 |
+
button.style.display = show ? "flex" : "none";
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
function submit() {
|
| 156 |
+
showSubmitButtons('txt2img', false);
|
| 157 |
+
|
| 158 |
+
var id = randomId();
|
| 159 |
+
localStorage.setItem("txt2img_task_id", id);
|
| 160 |
+
|
| 161 |
+
requestProgress(id, gradioApp().getElementById('txt2img_gallery_container'), gradioApp().getElementById('txt2img_gallery'), function() {
|
| 162 |
+
showSubmitButtons('txt2img', true);
|
| 163 |
+
localStorage.removeItem("txt2img_task_id");
|
| 164 |
+
showRestoreProgressButton('txt2img', false);
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
var res = create_submit_args(arguments);
|
| 168 |
+
|
| 169 |
+
res[0] = id;
|
| 170 |
+
|
| 171 |
+
return res;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function submit_img2img() {
|
| 175 |
+
showSubmitButtons('img2img', false);
|
| 176 |
+
|
| 177 |
+
var id = randomId();
|
| 178 |
+
localStorage.setItem("img2img_task_id", id);
|
| 179 |
+
|
| 180 |
+
requestProgress(id, gradioApp().getElementById('img2img_gallery_container'), gradioApp().getElementById('img2img_gallery'), function() {
|
| 181 |
+
showSubmitButtons('img2img', true);
|
| 182 |
+
localStorage.removeItem("img2img_task_id");
|
| 183 |
+
showRestoreProgressButton('img2img', false);
|
| 184 |
+
});
|
| 185 |
+
|
| 186 |
+
var res = create_submit_args(arguments);
|
| 187 |
+
|
| 188 |
+
res[0] = id;
|
| 189 |
+
res[1] = get_tab_index('mode_img2img');
|
| 190 |
+
|
| 191 |
+
return res;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function restoreProgressTxt2img() {
|
| 195 |
+
showRestoreProgressButton("txt2img", false);
|
| 196 |
+
var id = localStorage.getItem("txt2img_task_id");
|
| 197 |
+
|
| 198 |
+
id = localStorage.getItem("txt2img_task_id");
|
| 199 |
+
|
| 200 |
+
if (id) {
|
| 201 |
+
requestProgress(id, gradioApp().getElementById('txt2img_gallery_container'), gradioApp().getElementById('txt2img_gallery'), function() {
|
| 202 |
+
showSubmitButtons('txt2img', true);
|
| 203 |
+
}, null, 0);
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
return id;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
function restoreProgressImg2img() {
|
| 210 |
+
showRestoreProgressButton("img2img", false);
|
| 211 |
+
|
| 212 |
+
var id = localStorage.getItem("img2img_task_id");
|
| 213 |
+
|
| 214 |
+
if (id) {
|
| 215 |
+
requestProgress(id, gradioApp().getElementById('img2img_gallery_container'), gradioApp().getElementById('img2img_gallery'), function() {
|
| 216 |
+
showSubmitButtons('img2img', true);
|
| 217 |
+
}, null, 0);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
return id;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
onUiLoaded(function() {
|
| 224 |
+
showRestoreProgressButton('txt2img', localStorage.getItem("txt2img_task_id"));
|
| 225 |
+
showRestoreProgressButton('img2img', localStorage.getItem("img2img_task_id"));
|
| 226 |
+
});
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
function modelmerger() {
|
| 230 |
+
var id = randomId();
|
| 231 |
+
requestProgress(id, gradioApp().getElementById('modelmerger_results_panel'), null, function() {});
|
| 232 |
+
|
| 233 |
+
var res = create_submit_args(arguments);
|
| 234 |
+
res[0] = id;
|
| 235 |
+
return res;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
function ask_for_style_name(_, prompt_text, negative_prompt_text) {
|
| 240 |
+
var name_ = prompt('Style name:');
|
| 241 |
+
return [name_, prompt_text, negative_prompt_text];
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
function confirm_clear_prompt(prompt, negative_prompt) {
|
| 245 |
+
if (confirm("Delete prompt?")) {
|
| 246 |
+
prompt = "";
|
| 247 |
+
negative_prompt = "";
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
return [prompt, negative_prompt];
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
var promptTokecountUpdateFuncs = {};
|
| 255 |
+
|
| 256 |
+
function recalculatePromptTokens(name) {
|
| 257 |
+
if (promptTokecountUpdateFuncs[name]) {
|
| 258 |
+
promptTokecountUpdateFuncs[name]();
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
function recalculate_prompts_txt2img() {
|
| 263 |
+
recalculatePromptTokens('txt2img_prompt');
|
| 264 |
+
recalculatePromptTokens('txt2img_neg_prompt');
|
| 265 |
+
return Array.from(arguments);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
function recalculate_prompts_img2img() {
|
| 269 |
+
recalculatePromptTokens('img2img_prompt');
|
| 270 |
+
recalculatePromptTokens('img2img_neg_prompt');
|
| 271 |
+
return Array.from(arguments);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
var opts = {};
|
| 276 |
+
onUiUpdate(function() {
|
| 277 |
+
|
| 278 |
+
if (Object.keys(opts).length != 0) return;
|
| 279 |
+
|
| 280 |
+
var json_elem = gradioApp().getElementById("settings_json");
|
| 281 |
+
if (json_elem == null) return;
|
| 282 |
+
|
| 283 |
+
var textarea = json_elem.querySelector("textarea");
|
| 284 |
+
var jsdata = textarea.value;
|
| 285 |
+
opts = JSON.parse(jsdata);
|
| 286 |
+
executeCallbacks(optionsChangedCallbacks);
|
| 287 |
+
|
| 288 |
+
Object.defineProperty(textarea, "value", {
|
| 289 |
+
set: function (newValue) {
|
| 290 |
+
var valueProp = Object.getOwnPropertyDescriptor(
|
| 291 |
+
HTMLTextAreaElement.prototype,
|
| 292 |
+
"value"
|
| 293 |
+
);
|
| 294 |
+
var oldValue = valueProp.get.call(textarea);
|
| 295 |
+
valueProp.set.call(textarea, newValue);
|
| 296 |
+
|
| 297 |
+
if (oldValue != newValue) {
|
| 298 |
+
opts = JSON.parse(textarea.value);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
executeCallbacks(optionsChangedCallbacks);
|
| 302 |
+
},
|
| 303 |
+
get: function () {
|
| 304 |
+
var valueProp = Object.getOwnPropertyDescriptor(
|
| 305 |
+
HTMLTextAreaElement.prototype,
|
| 306 |
+
"value"
|
| 307 |
+
);
|
| 308 |
+
return valueProp.get.call(textarea);
|
| 309 |
+
},
|
| 310 |
+
});
|
| 311 |
+
|
| 312 |
+
//console.log(opts);
|
| 313 |
+
|
| 314 |
+
json_elem.parentElement.style.display = "none";
|
| 315 |
+
|
| 316 |
+
function registerTextarea(id, id_counter, id_button) {
|
| 317 |
+
var prompt = gradioApp().getElementById(id);
|
| 318 |
+
var counter = gradioApp().getElementById(id_counter);
|
| 319 |
+
var textarea = gradioApp().querySelector("#" + id + " > label > textarea");
|
| 320 |
+
|
| 321 |
+
if (counter.parentElement == prompt.parentElement) {
|
| 322 |
+
return;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
prompt.parentElement.insertBefore(counter, prompt);
|
| 326 |
+
counter.classList.add("token-counter");
|
| 327 |
+
prompt.parentElement.style.position = "relative";
|
| 328 |
+
|
| 329 |
+
promptTokecountUpdateFuncs[id] = function () {
|
| 330 |
+
update_token_counter(id_button);
|
| 331 |
+
};
|
| 332 |
+
textarea.addEventListener("input", promptTokecountUpdateFuncs[id]);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
registerTextarea(
|
| 336 |
+
"txt2img_prompt",
|
| 337 |
+
"txt2img_token_counter",
|
| 338 |
+
"txt2img_token_button"
|
| 339 |
+
);
|
| 340 |
+
registerTextarea(
|
| 341 |
+
"txt2img_neg_prompt",
|
| 342 |
+
"txt2img_negative_token_counter",
|
| 343 |
+
"txt2img_negative_token_button"
|
| 344 |
+
);
|
| 345 |
+
registerTextarea(
|
| 346 |
+
"img2img_prompt",
|
| 347 |
+
"img2img_token_counter",
|
| 348 |
+
"img2img_token_button"
|
| 349 |
+
);
|
| 350 |
+
registerTextarea(
|
| 351 |
+
"img2img_neg_prompt",
|
| 352 |
+
"img2img_negative_token_counter",
|
| 353 |
+
"img2img_negative_token_button"
|
| 354 |
+
);
|
| 355 |
+
|
| 356 |
+
var show_all_pages = gradioApp().getElementById("settings_show_all_pages");
|
| 357 |
+
var settings_tabs = gradioApp().querySelector("#settings div");
|
| 358 |
+
if (show_all_pages && settings_tabs) {
|
| 359 |
+
settings_tabs.appendChild(show_all_pages);
|
| 360 |
+
show_all_pages.onclick = function () {
|
| 361 |
+
gradioApp()
|
| 362 |
+
.querySelectorAll("#settings > div")
|
| 363 |
+
.forEach(function (elem) {
|
| 364 |
+
elem.style.display = "block";
|
| 365 |
+
});
|
| 366 |
+
gradioApp()
|
| 367 |
+
.querySelectorAll("#settings > div > div > div")
|
| 368 |
+
.forEach(function (elem) {
|
| 369 |
+
elem.style.maxHeight = "none";
|
| 370 |
+
});
|
| 371 |
+
};
|
| 372 |
+
}
|
| 373 |
+
/*
|
| 374 |
+
^ matches the start
|
| 375 |
+
* matches any position
|
| 376 |
+
$ matches the end
|
| 377 |
+
*/
|
| 378 |
+
/* anapnoe ui start */
|
| 379 |
+
|
| 380 |
+
/* auto grow textarea */
|
| 381 |
+
function autoGrowPromptTextarea() {
|
| 382 |
+
gradioApp()
|
| 383 |
+
.querySelectorAll('[id$="_prompt"] textarea')
|
| 384 |
+
.forEach(function (elem) {
|
| 385 |
+
elem.parentElement.click();
|
| 386 |
+
});
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
gradioApp()
|
| 390 |
+
.querySelectorAll(
|
| 391 |
+
'[id$="_prompt"] textarea, [id^="setting_"] textarea, textarea'
|
| 392 |
+
)
|
| 393 |
+
.forEach(function (elem) {
|
| 394 |
+
elem.style.boxSizing = "border-box";
|
| 395 |
+
var offset = elem.offsetHeight - elem.clientHeight;
|
| 396 |
+
elem.addEventListener("input", function (e) {
|
| 397 |
+
e.target.style.minHeight = "auto";
|
| 398 |
+
e.target.style.minHeight = e.target.scrollHeight + offset + 2 + "px";
|
| 399 |
+
});
|
| 400 |
+
|
| 401 |
+
elem.parentElement.addEventListener("click", function (e) {
|
| 402 |
+
let textarea = e.currentTarget.querySelector("textarea");
|
| 403 |
+
textarea.style.minHeight = "auto";
|
| 404 |
+
textarea.style.minHeight = textarea.scrollHeight + offset + 2 + "px";
|
| 405 |
+
});
|
| 406 |
+
});
|
| 407 |
+
|
| 408 |
+
/* resizable split view */
|
| 409 |
+
const resizeEvent = window.document.createEvent("UIEvents");
|
| 410 |
+
resizeEvent.initUIEvent("resize", true, false, window, 0);
|
| 411 |
+
|
| 412 |
+
gradioApp()
|
| 413 |
+
.querySelectorAll('[id $="2img_splitter"]')
|
| 414 |
+
.forEach((elem) => {
|
| 415 |
+
elem.addEventListener("mousedown", function (e) {
|
| 416 |
+
e.preventDefault();
|
| 417 |
+
|
| 418 |
+
let resizer = e.currentTarget;
|
| 419 |
+
let container = resizer.parentElement;
|
| 420 |
+
|
| 421 |
+
let flexDir = window
|
| 422 |
+
.getComputedStyle(container)
|
| 423 |
+
.getPropertyValue("flex-direction");
|
| 424 |
+
|
| 425 |
+
let leftSide = resizer.previousElementSibling;
|
| 426 |
+
let rightSide = resizer.nextElementSibling;
|
| 427 |
+
|
| 428 |
+
let dir = flexDir == "row-reverse" ? -1.0 : 1.0;
|
| 429 |
+
|
| 430 |
+
let x = e.clientX;
|
| 431 |
+
let y = e.clientY;
|
| 432 |
+
let leftWidth = leftSide.getBoundingClientRect().width;
|
| 433 |
+
|
| 434 |
+
function mouseMoveHandler(e) {
|
| 435 |
+
resizer.style.cursor = "col-resize";
|
| 436 |
+
container.style.cursor = "col-resize";
|
| 437 |
+
|
| 438 |
+
const dx = (e.clientX - x) * dir;
|
| 439 |
+
const dy = (e.clientY - y) * dir;
|
| 440 |
+
|
| 441 |
+
const newLeftWidth =
|
| 442 |
+
((leftWidth + dx) * 100) / container.getBoundingClientRect().width;
|
| 443 |
+
leftSide.style.flexBasis = `${newLeftWidth}%`;
|
| 444 |
+
leftSide.style.userSelect = "none";
|
| 445 |
+
leftSide.style.pointerEvents = "none";
|
| 446 |
+
rightSide.style.userSelect = "none";
|
| 447 |
+
rightSide.style.pointerEvents = "none";
|
| 448 |
+
//window.dispatchEvent(resizeEvent);
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
function mouseUpHandler() {
|
| 452 |
+
resizer.style.removeProperty("cursor");
|
| 453 |
+
container.style.removeProperty("cursor");
|
| 454 |
+
leftSide.style.removeProperty("user-select");
|
| 455 |
+
leftSide.style.removeProperty("pointer-events");
|
| 456 |
+
rightSide.style.removeProperty("user-select");
|
| 457 |
+
rightSide.style.removeProperty("pointer-events");
|
| 458 |
+
container.removeEventListener("mousemove", mouseMoveHandler);
|
| 459 |
+
container.removeEventListener("mouseup", mouseUpHandler);
|
| 460 |
+
//window.dispatchEvent(resizeEvent);
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
container.addEventListener("mousemove", mouseMoveHandler);
|
| 464 |
+
container.addEventListener("mouseup", mouseUpHandler);
|
| 465 |
+
});
|
| 466 |
+
|
| 467 |
+
let flex_reverse = false;
|
| 468 |
+
elem.addEventListener("dblclick", function (e) {
|
| 469 |
+
flex_reverse = !flex_reverse;
|
| 470 |
+
e.preventDefault();
|
| 471 |
+
|
| 472 |
+
let resizer = e.currentTarget;
|
| 473 |
+
let container = resizer.parentElement;
|
| 474 |
+
//let flexDir = window.getComputedStyle(container).getPropertyValue('flex-direction');
|
| 475 |
+
|
| 476 |
+
if (flex_reverse) {
|
| 477 |
+
container.style.flexDirection = "row-reverse";
|
| 478 |
+
} else {
|
| 479 |
+
container.style.flexDirection = "row";
|
| 480 |
+
}
|
| 481 |
+
});
|
| 482 |
+
});
|
| 483 |
+
|
| 484 |
+
// set this globally
|
| 485 |
+
//let selectedTabItemId = "tab_txt2img";
|
| 486 |
+
/* switch tab item from instance button, this is the only method that works i havent found a workaround yet */
|
| 487 |
+
const Observe = (sel, opt, cb) => {
|
| 488 |
+
const Obs = new MutationObserver((m) => [...m].forEach(cb));
|
| 489 |
+
gradioApp()
|
| 490 |
+
.querySelectorAll(sel)
|
| 491 |
+
.forEach((el) => Obs.observe(el, opt));
|
| 492 |
+
};
|
| 493 |
+
Observe(
|
| 494 |
+
"#tabs > div.tabitem",
|
| 495 |
+
{
|
| 496 |
+
attributesList: ["style"],
|
| 497 |
+
attributeOldValue: true,
|
| 498 |
+
},
|
| 499 |
+
(m) => {
|
| 500 |
+
if (m.target.style.display === "block") {
|
| 501 |
+
let idx = parseInt(m.target.getAttribute("tab-item"));
|
| 502 |
+
selectedTabItemId = m.target.id;
|
| 503 |
+
tabItemChanged(idx);
|
| 504 |
+
}
|
| 505 |
+
}
|
| 506 |
+
);
|
| 507 |
+
|
| 508 |
+
function tabItemChanged(idx) {
|
| 509 |
+
gradioApp()
|
| 510 |
+
.querySelectorAll(
|
| 511 |
+
"#tabs > div > button.selected, #nav_menu_header_tabs > button.selected"
|
| 512 |
+
)
|
| 513 |
+
.forEach(function (tab) {
|
| 514 |
+
tab.classList.remove("selected");
|
| 515 |
+
});
|
| 516 |
+
|
| 517 |
+
gradioApp()
|
| 518 |
+
.querySelectorAll(
|
| 519 |
+
"#tabs > div > button:nth-child(" +
|
| 520 |
+
(idx + 1) +
|
| 521 |
+
"), #nav_menu_header_tabs > button:nth-child(" +
|
| 522 |
+
(idx + 1) +
|
| 523 |
+
")"
|
| 524 |
+
)
|
| 525 |
+
.forEach(function (tab) {
|
| 526 |
+
tab.classList.add("selected");
|
| 527 |
+
});
|
| 528 |
+
//gardio removes listeners and attributes from tab buttons we add them again here
|
| 529 |
+
gradioApp()
|
| 530 |
+
.querySelectorAll("#tabs > div > button")
|
| 531 |
+
.forEach(function (tab, index) {
|
| 532 |
+
tab.setAttribute("tab-id", index);
|
| 533 |
+
tab.removeEventListener("mouseup", navTabClicked);
|
| 534 |
+
tab.addEventListener("mouseup", navTabClicked);
|
| 535 |
+
if (tab.innerHTML.indexOf("Theme") != -1) tab.style.display = "none";
|
| 536 |
+
});
|
| 537 |
+
|
| 538 |
+
/* gradioApp().querySelectorAll('[id^="image_buttons_"] button').forEach(function (elem){
|
| 539 |
+
|
| 540 |
+
if(elem.id == "txt2img_tab"){
|
| 541 |
+
elem.setAttribute("tab-id", 0);
|
| 542 |
+
elem.removeEventListener('click', navTabClicked);
|
| 543 |
+
elem.addEventListener('click', navTabClicked);
|
| 544 |
+
}else if(elem.id == "img2img_tab" || elem.id == "inpaint_tab"){
|
| 545 |
+
elem.setAttribute("tab-id", 1);
|
| 546 |
+
elem.removeEventListener('click', navTabClicked);
|
| 547 |
+
elem.addEventListener('click', navTabClicked);
|
| 548 |
+
}if(elem.id == "extras_tab"){
|
| 549 |
+
elem.setAttribute("tab-id", 2);
|
| 550 |
+
elem.removeEventListener('click', navTabClicked);
|
| 551 |
+
elem.addEventListener('click', navTabClicked);
|
| 552 |
+
}
|
| 553 |
+
}) */
|
| 554 |
+
|
| 555 |
+
/* const pdiv = gradioApp().querySelector("#"+selectedTabItemId+" .progressDiv");
|
| 556 |
+
if(!pdiv && selectedTabItemId == "tab_txt2img"){
|
| 557 |
+
showSubmitButtons('txt2img', true);
|
| 558 |
+
}else if(!pdiv && selectedTabItemId == "tab_img2img"){
|
| 559 |
+
showSubmitButtons('img2img', true);
|
| 560 |
+
} */
|
| 561 |
+
|
| 562 |
+
//window.onUiHeaderTabUpdate();
|
| 563 |
+
// also here the same issue
|
| 564 |
+
/*
|
| 565 |
+
gradioApp().querySelectorAll('[id^="image_buttons"] [id$="_tab"]').forEach(function (button, index){
|
| 566 |
+
if(button.id == ("img2img_tab" || "inpaint_tab") ){
|
| 567 |
+
button.setAttribute("tab-id", 1 );
|
| 568 |
+
}else if(button.id == "extras_tab"){
|
| 569 |
+
button.setAttribute("tab-id", 2 );
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
button.removeEventListener('mouseup', navTabClicked);
|
| 573 |
+
button.addEventListener('mouseup', navTabClicked);
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
})
|
| 577 |
+
*/
|
| 578 |
+
|
| 579 |
+
netMenuVisibility();
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
// menu
|
| 583 |
+
function disableScroll() {
|
| 584 |
+
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
| 585 |
+
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
| 586 |
+
window.scrollTo(scrollLeft, scrollTop);
|
| 587 |
+
|
| 588 |
+
window.onscroll = function () {
|
| 589 |
+
window.scrollTo(scrollLeft, scrollTop);
|
| 590 |
+
};
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
function enableScroll() {
|
| 594 |
+
window.onscroll = function () {};
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
function getPos(el) {
|
| 598 |
+
let rect = el.getBoundingClientRect();
|
| 599 |
+
return { x: rect.left, y: rect.top };
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
function toggleMenu(isopen, icon, panel, func) {
|
| 603 |
+
if (isopen) {
|
| 604 |
+
panel.classList.add("open");
|
| 605 |
+
icon.classList.add("fixed");
|
| 606 |
+
gradioApp().addEventListener("click", func);
|
| 607 |
+
disableScroll();
|
| 608 |
+
} else {
|
| 609 |
+
panel.classList.remove("open");
|
| 610 |
+
icon.classList.remove("fixed");
|
| 611 |
+
gradioApp().removeEventListener("click", func);
|
| 612 |
+
enableScroll();
|
| 613 |
+
}
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
// close aside views
|
| 617 |
+
function closeAsideViews(menu) {
|
| 618 |
+
if (quick_menu != menu && quick_menu_open) quick_menu.click();
|
| 619 |
+
if (net_menu != menu && net_menu_open) net_menu.click();
|
| 620 |
+
if (theme_menu != menu && theme_menu_open) theme_menu.click();
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
// if we change to other view other than 2img and if aside mode is selected close extra networks aside and hide the net menu icon
|
| 624 |
+
let net_container = gradioApp().querySelector("#txt2img_extra_networks_row");
|
| 625 |
+
let net_menu_open = false;
|
| 626 |
+
const net_menu = gradioApp().querySelector("#extra_networks_menu");
|
| 627 |
+
function netMenuVisibility() {
|
| 628 |
+
if (selectedTabItemId.indexOf("2img") != -1) {
|
| 629 |
+
net_menu.style.display = "block";
|
| 630 |
+
let nid = selectedTabItemId.split("_")[1];
|
| 631 |
+
net_container = gradioApp().querySelector(
|
| 632 |
+
"#" + nid + "_extra_networks_row"
|
| 633 |
+
);
|
| 634 |
+
if (net_container.classList.contains("aside")) {
|
| 635 |
+
net_menu.style.display = "block";
|
| 636 |
+
toggleMenu(net_menu_open, net_menu, net_container, null);
|
| 637 |
+
} else {
|
| 638 |
+
net_menu.style.display = "none";
|
| 639 |
+
}
|
| 640 |
+
} else {
|
| 641 |
+
net_menu.style.display = "none";
|
| 642 |
+
}
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
// mobile nav menu
|
| 646 |
+
const tabs_menu = gradioApp().querySelector("#tabs > div:first-child");
|
| 647 |
+
const nav_menu = gradioApp().querySelector("#nav_menu");
|
| 648 |
+
const header = gradioApp().querySelector("#header-top");
|
| 649 |
+
let menu_open = false;
|
| 650 |
+
const z_menu = nav_menu.cloneNode(true);
|
| 651 |
+
z_menu.id = "clone_nav_menu";
|
| 652 |
+
header.parentElement.append(z_menu);
|
| 653 |
+
function toggleNavMenu(e) {
|
| 654 |
+
e.stopPropagation();
|
| 655 |
+
menu_open = !menu_open;
|
| 656 |
+
toggleMenu(menu_open, nav_menu, tabs_menu, toggleNavMenu);
|
| 657 |
+
}
|
| 658 |
+
z_menu.addEventListener("click", toggleNavMenu);
|
| 659 |
+
|
| 660 |
+
// quicksettings nav menu
|
| 661 |
+
let quick_menu_open = false;
|
| 662 |
+
const quicksettings_overflow = gradioApp().querySelector(
|
| 663 |
+
"#quicksettings_overflow"
|
| 664 |
+
);
|
| 665 |
+
const quick_menu = gradioApp().querySelector("#quick_menu");
|
| 666 |
+
function toggleQuickMenu(e) {
|
| 667 |
+
closeAsideViews(quick_menu);
|
| 668 |
+
quick_menu_open = !quick_menu_open;
|
| 669 |
+
const withinBoundaries = e.composedPath().includes(quicksettings_overflow);
|
| 670 |
+
if (!quick_menu_open && withinBoundaries) {
|
| 671 |
+
quick_menu_open = true;
|
| 672 |
+
} else {
|
| 673 |
+
e.preventDefault();
|
| 674 |
+
e.stopPropagation();
|
| 675 |
+
toggleMenu(
|
| 676 |
+
quick_menu_open,
|
| 677 |
+
quick_menu,
|
| 678 |
+
quicksettings_overflow,
|
| 679 |
+
toggleQuickMenu
|
| 680 |
+
);
|
| 681 |
+
}
|
| 682 |
+
}
|
| 683 |
+
quick_menu.addEventListener("click", toggleQuickMenu);
|
| 684 |
+
|
| 685 |
+
// extra networks nav menu
|
| 686 |
+
function clickedOutside(e) {
|
| 687 |
+
//console.log(e.target.getAttribute('data-testid'));
|
| 688 |
+
if (
|
| 689 |
+
e.target.getAttribute("data-testid") != "textbox" &&
|
| 690 |
+
e.target.getAttribute("data-testid")
|
| 691 |
+
) {
|
| 692 |
+
if (net_menu_open && e.target.closest('[id$="2img_settings_scroll"]'))
|
| 693 |
+
net_menu.click();
|
| 694 |
+
}
|
| 695 |
+
}
|
| 696 |
+
function toggleNetMenu(e) {
|
| 697 |
+
closeAsideViews(net_menu);
|
| 698 |
+
net_menu_open = !net_menu_open;
|
| 699 |
+
e.preventDefault();
|
| 700 |
+
e.stopPropagation();
|
| 701 |
+
toggleMenu(net_menu_open, net_menu, net_container, clickedOutside);
|
| 702 |
+
}
|
| 703 |
+
net_menu.addEventListener("click", toggleNetMenu);
|
| 704 |
+
gradioApp()
|
| 705 |
+
.querySelectorAll('button[id*="2img_extra_networks"]')
|
| 706 |
+
.forEach((elem) => {
|
| 707 |
+
elem.addEventListener("click", toggleNetMenu);
|
| 708 |
+
});
|
| 709 |
+
|
| 710 |
+
// theme nav menu
|
| 711 |
+
let theme_container = gradioApp().querySelector("#tab_ui_theme");
|
| 712 |
+
let theme_menu_open = false;
|
| 713 |
+
const theme_menu = gradioApp().querySelector("#theme_menu");
|
| 714 |
+
function toggleThemeMenu(e) {
|
| 715 |
+
closeAsideViews(theme_menu);
|
| 716 |
+
theme_menu_open = !theme_menu_open;
|
| 717 |
+
e.preventDefault();
|
| 718 |
+
e.stopPropagation();
|
| 719 |
+
toggleMenu(theme_menu_open, theme_menu, theme_container, null);
|
| 720 |
+
}
|
| 721 |
+
theme_menu.addEventListener("click", toggleThemeMenu);
|
| 722 |
+
|
| 723 |
+
const theme_tab = gradioApp().querySelector("#tab_ui_theme");
|
| 724 |
+
function theme_aside(value) {
|
| 725 |
+
if (value) {
|
| 726 |
+
theme_tab.classList.add("aside");
|
| 727 |
+
} else {
|
| 728 |
+
theme_tab.classList.remove("aside");
|
| 729 |
+
}
|
| 730 |
+
}
|
| 731 |
+
if (theme_tab) theme_aside(true);
|
| 732 |
+
|
| 733 |
+
function generateOnRepeat(elem, isforever) {
|
| 734 |
+
if (elem.generateOnRepeatInterval != null)
|
| 735 |
+
clearInterval(elem.generateOnRepeatInterval);
|
| 736 |
+
if (isforever) {
|
| 737 |
+
const generate_button = elem.previousElementSibling;
|
| 738 |
+
elem.generateOnRepeatInterval = setInterval(function () {
|
| 739 |
+
if (window.getComputedStyle(generate_button).display !== "none") {
|
| 740 |
+
generate_button.click();
|
| 741 |
+
}
|
| 742 |
+
}, 500);
|
| 743 |
+
}
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
function toggleGenerateForever(e) {
|
| 747 |
+
e.target.classList.toggle("active");
|
| 748 |
+
if (e.target.className.indexOf("active") != -1) {
|
| 749 |
+
generateOnRepeat(e.target, true);
|
| 750 |
+
} else {
|
| 751 |
+
generateOnRepeat(e.target, false);
|
| 752 |
+
}
|
| 753 |
+
e.preventDefault();
|
| 754 |
+
e.stopPropagation();
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
gradioApp()
|
| 758 |
+
.querySelectorAll('button[id*="2img_generate_forever"]')
|
| 759 |
+
.forEach((elem) => {
|
| 760 |
+
elem.addEventListener("click", toggleGenerateForever);
|
| 761 |
+
});
|
| 762 |
+
|
| 763 |
+
/* let generateOnRepeat = function (genbuttonid, interruptbuttonid) {
|
| 764 |
+
let genbutton = gradioApp().querySelector(genbuttonid);
|
| 765 |
+
let interruptbutton = gradioApp().querySelector(interruptbuttonid);
|
| 766 |
+
if (!interruptbutton.offsetParent) {
|
| 767 |
+
genbutton.click();
|
| 768 |
+
}
|
| 769 |
+
clearInterval(window.generateOnRepeatInterval);
|
| 770 |
+
window.generateOnRepeatInterval = setInterval(function () {
|
| 771 |
+
if (!interruptbutton.offsetParent) {
|
| 772 |
+
genbutton.click();
|
| 773 |
+
}
|
| 774 |
+
}, 500);
|
| 775 |
+
};
|
| 776 |
+
|
| 777 |
+
appendContextMenuOption("#txt2img_generate", "Generate forever", function () {
|
| 778 |
+
generateOnRepeat("#txt2img_generate", "#txt2img_interrupt");
|
| 779 |
+
});
|
| 780 |
+
appendContextMenuOption("#img2img_generate", "Generate forever", function () {
|
| 781 |
+
generateOnRepeat("#img2img_generate", "#img2img_interrupt");
|
| 782 |
+
});
|
| 783 |
+
|
| 784 |
+
let cancelGenerateForever = function () {
|
| 785 |
+
clearInterval(window.generateOnRepeatInterval);
|
| 786 |
+
}; */
|
| 787 |
+
|
| 788 |
+
//
|
| 789 |
+
/*
|
| 790 |
+
function attachAccordionListeners(elem) {
|
| 791 |
+
elem.querySelectorAll(".gradio-accordion > div.wrap").forEach((elem) => {
|
| 792 |
+
elem.addEventListener("click", toggleAccordion);
|
| 793 |
+
});
|
| 794 |
+
}
|
| 795 |
+
function toggleAccordion(e) {
|
| 796 |
+
//e.preventDefault();
|
| 797 |
+
//e.stopPropagation();
|
| 798 |
+
//e.stopImmediatePropagation();
|
| 799 |
+
let accordion_content =
|
| 800 |
+
e.currentTarget.parentElement.querySelector(".gap.svelte-vt1mxs");
|
| 801 |
+
|
| 802 |
+
if (accordion_content) {
|
| 803 |
+
e.preventDefault();
|
| 804 |
+
e.stopPropagation();
|
| 805 |
+
let accordion_icon = e.currentTarget.parentElement.querySelector(
|
| 806 |
+
".label-wrap > .icon"
|
| 807 |
+
);
|
| 808 |
+
if (accordion_content.className.indexOf("hidden") != -1) {
|
| 809 |
+
accordion_content.classList.remove("hidden");
|
| 810 |
+
accordion_icon.style.setProperty("transform", "rotate(0deg)");
|
| 811 |
+
e.currentTarget.classList.add("hide");
|
| 812 |
+
} else {
|
| 813 |
+
accordion_content.classList.add("hidden");
|
| 814 |
+
accordion_icon.style.setProperty("transform", "rotate(90deg)");
|
| 815 |
+
e.currentTarget.classList.remove("hide");
|
| 816 |
+
}
|
| 817 |
+
} else {
|
| 818 |
+
let accordion_btn =
|
| 819 |
+
e.currentTarget.parentElement.querySelector(".label-wrap");
|
| 820 |
+
e.currentTarget.classList.add("hide");
|
| 821 |
+
accordion_btn.click();
|
| 822 |
+
//maybe here we need to setInterval until the content is available
|
| 823 |
+
setTimeout(function () {
|
| 824 |
+
accordion_content = accordion_btn.parentElement;
|
| 825 |
+
//console.log(accordion_content);
|
| 826 |
+
attachAccordionListeners(accordion_content);
|
| 827 |
+
}, 1000);
|
| 828 |
+
}
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
attachAccordionListeners(gradioApp());
|
| 832 |
+
*/
|
| 833 |
+
// additional ui styles
|
| 834 |
+
let styleobj = {};
|
| 835 |
+
const r = gradioApp();
|
| 836 |
+
const style = document.createElement("style");
|
| 837 |
+
style.id = "ui-styles";
|
| 838 |
+
r.appendChild(style);
|
| 839 |
+
|
| 840 |
+
function updateOpStyles() {
|
| 841 |
+
let ops_styles = "";
|
| 842 |
+
for (const key in styleobj) {
|
| 843 |
+
ops_styles += styleobj[key];
|
| 844 |
+
}
|
| 845 |
+
const ui_styles = gradioApp().getElementById("ui-styles");
|
| 846 |
+
ui_styles.innerHTML = ops_styles;
|
| 847 |
+
//console.log(ui_styles);
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
// generated image fit contain - scale
|
| 851 |
+
function imageGeneratedFitMethod(value) {
|
| 852 |
+
styleobj.ui_view_fit =
|
| 853 |
+
"[id$='2img_gallery'] div>img {object-fit:" + value + "!important;}";
|
| 854 |
+
}
|
| 855 |
+
gradioApp()
|
| 856 |
+
.querySelector("#setting_ui_output_image_fit")
|
| 857 |
+
.addEventListener("click", function (e) {
|
| 858 |
+
if (e.target && e.target.matches("input[type='radio']")) {
|
| 859 |
+
imageGeneratedFitMethod(e.target.value.toLowerCase());
|
| 860 |
+
updateOpStyles();
|
| 861 |
+
}
|
| 862 |
+
});
|
| 863 |
+
imageGeneratedFitMethod(opts.ui_output_image_fit.toLowerCase());
|
| 864 |
+
|
| 865 |
+
// livePreview fit contain - scale
|
| 866 |
+
function imagePreviewFitMethod(value) {
|
| 867 |
+
styleobj.ui_fit = ".livePreview img {object-fit:" + value + "!important;}";
|
| 868 |
+
}
|
| 869 |
+
gradioApp()
|
| 870 |
+
.querySelector("#setting_live_preview_image_fit")
|
| 871 |
+
.addEventListener("click", function (e) {
|
| 872 |
+
if (e.target && e.target.matches("input[type='radio']")) {
|
| 873 |
+
imagePreviewFitMethod(e.target.value.toLowerCase());
|
| 874 |
+
updateOpStyles();
|
| 875 |
+
}
|
| 876 |
+
});
|
| 877 |
+
imagePreviewFitMethod(opts.live_preview_image_fit.toLowerCase());
|
| 878 |
+
|
| 879 |
+
// viewports order left - right
|
| 880 |
+
function viewportOrder(value) {
|
| 881 |
+
styleobj.ui_views_order =
|
| 882 |
+
"[id$=_prompt_image] + div {flex-direction:" + value + ";}";
|
| 883 |
+
}
|
| 884 |
+
gradioApp()
|
| 885 |
+
.querySelector("#setting_ui_views_order")
|
| 886 |
+
.addEventListener("click", function (e) {
|
| 887 |
+
if (e.target && e.target.matches("input[type='radio']")) {
|
| 888 |
+
viewportOrder(e.target.value.toLowerCase());
|
| 889 |
+
updateOpStyles();
|
| 890 |
+
}
|
| 891 |
+
});
|
| 892 |
+
viewportOrder(opts.ui_views_order.toLowerCase());
|
| 893 |
+
|
| 894 |
+
// sd max resolution output
|
| 895 |
+
function sdMaxOutputResolution(value) {
|
| 896 |
+
gradioApp()
|
| 897 |
+
.querySelectorAll('[id$="2img_width"] input,[id$="2img_height"] input')
|
| 898 |
+
.forEach((elem) => {
|
| 899 |
+
elem.max = value;
|
| 900 |
+
});
|
| 901 |
+
}
|
| 902 |
+
gradioApp()
|
| 903 |
+
.querySelector("#setting_sd_max_resolution")
|
| 904 |
+
.addEventListener("input", function (e) {
|
| 905 |
+
let intvalue = parseInt(e.target.value);
|
| 906 |
+
intvalue = Math.min(Math.max(intvalue, 512), 16384);
|
| 907 |
+
sdMaxOutputResolution(intvalue);
|
| 908 |
+
});
|
| 909 |
+
sdMaxOutputResolution(opts.sd_max_resolution);
|
| 910 |
+
|
| 911 |
+
function extra_networks_visibility(value) {
|
| 912 |
+
gradioApp()
|
| 913 |
+
.querySelectorAll('[id$="2img_extra_networks_row"]')
|
| 914 |
+
.forEach((elem) => {
|
| 915 |
+
if (value) {
|
| 916 |
+
elem.classList.remove("!hidden");
|
| 917 |
+
} else {
|
| 918 |
+
elem.classList.add("!hidden");
|
| 919 |
+
}
|
| 920 |
+
});
|
| 921 |
+
}
|
| 922 |
+
gradioApp()
|
| 923 |
+
.querySelector("#setting_extra_networks_default_visibility input")
|
| 924 |
+
.addEventListener("click", function (e) {
|
| 925 |
+
extra_networks_visibility(e.target.checked);
|
| 926 |
+
});
|
| 927 |
+
extra_networks_visibility(opts.extra_networks_default_visibility);
|
| 928 |
+
|
| 929 |
+
function extra_networks_card_size(value) {
|
| 930 |
+
styleobj.extra_networks_card_size =
|
| 931 |
+
":root{--ae-extra-networks-card-size:" + value + ";}";
|
| 932 |
+
}
|
| 933 |
+
gradioApp()
|
| 934 |
+
.querySelectorAll("#setting_extra_networks_cards_size input")
|
| 935 |
+
.forEach(function (elem) {
|
| 936 |
+
elem.addEventListener("input", function (e) {
|
| 937 |
+
extra_networks_card_size(e.target.value);
|
| 938 |
+
updateOpStyles();
|
| 939 |
+
});
|
| 940 |
+
});
|
| 941 |
+
extra_networks_card_size(opts.extra_networks_cards_size);
|
| 942 |
+
|
| 943 |
+
function extra_networks_cards_visible_rows(value) {
|
| 944 |
+
styleobj.extra_networks_cards_visible_rows =
|
| 945 |
+
":root{--ae-extra-networks-visible-rows:" + value + ";}";
|
| 946 |
+
}
|
| 947 |
+
gradioApp()
|
| 948 |
+
.querySelectorAll("#setting_extra_networks_cards_visible_rows input")
|
| 949 |
+
.forEach(function (elem) {
|
| 950 |
+
elem.addEventListener("input", function (e) {
|
| 951 |
+
extra_networks_cards_visible_rows(e.target.value);
|
| 952 |
+
updateOpStyles();
|
| 953 |
+
});
|
| 954 |
+
});
|
| 955 |
+
extra_networks_cards_visible_rows(opts.extra_networks_cards_visible_rows);
|
| 956 |
+
|
| 957 |
+
function extra_networks_aside(value) {
|
| 958 |
+
gradioApp()
|
| 959 |
+
.querySelectorAll('[id$="2img_extra_networks_row"]')
|
| 960 |
+
.forEach((elem) => {
|
| 961 |
+
if (value) {
|
| 962 |
+
elem.classList.add("aside");
|
| 963 |
+
} else {
|
| 964 |
+
elem.classList.remove("aside");
|
| 965 |
+
}
|
| 966 |
+
netMenuVisibility();
|
| 967 |
+
});
|
| 968 |
+
}
|
| 969 |
+
gradioApp()
|
| 970 |
+
.querySelector("#setting_extra_networks_aside input")
|
| 971 |
+
.addEventListener("click", function (e) {
|
| 972 |
+
extra_networks_aside(e.target.checked);
|
| 973 |
+
});
|
| 974 |
+
extra_networks_aside(opts.extra_networks_aside);
|
| 975 |
+
|
| 976 |
+
// hidden - header ui tabs
|
| 977 |
+
let radio_hidden_html = "";
|
| 978 |
+
let radio_header_html = "";
|
| 979 |
+
let hiddentabs = {};
|
| 980 |
+
let headertabs = {};
|
| 981 |
+
const setting_ui_hidden_tabs = gradioApp().querySelector(
|
| 982 |
+
"#setting_ui_hidden_tabs textarea"
|
| 983 |
+
);
|
| 984 |
+
const setting_ui_header_tabs = gradioApp().querySelector(
|
| 985 |
+
"#setting_ui_header_tabs textarea"
|
| 986 |
+
);
|
| 987 |
+
const parent_header_tabs = gradioApp().querySelector("#nav_menu_header_tabs");
|
| 988 |
+
setting_ui_hidden_tabs.style.display = "none";
|
| 989 |
+
setting_ui_header_tabs.style.display = "none";
|
| 990 |
+
|
| 991 |
+
const maintabs = gradioApp().querySelectorAll(
|
| 992 |
+
"#tabs > div:first-child > button"
|
| 993 |
+
);
|
| 994 |
+
const tabitems = gradioApp().querySelectorAll("#tabs > div.tabitem");
|
| 995 |
+
|
| 996 |
+
function tabOpsSave(setting) {
|
| 997 |
+
updateInput(setting);
|
| 998 |
+
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
function tabsHiddenChange() {
|
| 1002 |
+
const keys = Object.keys(hiddentabs);
|
| 1003 |
+
setting_ui_hidden_tabs.value = "";
|
| 1004 |
+
keys.forEach((key, index) => {
|
| 1005 |
+
//console.log(`${key}: ${hiddentabs[key]} ${index}`);
|
| 1006 |
+
if (hiddentabs[key] == true) {
|
| 1007 |
+
styleobj[key] =
|
| 1008 |
+
"#tabs > div:first-child > button:nth-child(" +
|
| 1009 |
+
(index + 1) +
|
| 1010 |
+
"){display:none;}";
|
| 1011 |
+
setting_ui_hidden_tabs.value += key + ",";
|
| 1012 |
+
} else {
|
| 1013 |
+
styleobj[key] =
|
| 1014 |
+
"#tabs > div:first-child > button:nth-child(" +
|
| 1015 |
+
(index + 1) +
|
| 1016 |
+
"){display:block;}";
|
| 1017 |
+
}
|
| 1018 |
+
});
|
| 1019 |
+
|
| 1020 |
+
tabOpsSave(setting_ui_hidden_tabs);
|
| 1021 |
+
tabsHeaderChange();
|
| 1022 |
+
}
|
| 1023 |
+
function tabsHeaderChange() {
|
| 1024 |
+
const keys = Object.keys(headertabs);
|
| 1025 |
+
setting_ui_header_tabs.value = "";
|
| 1026 |
+
keys.forEach((key, index) => {
|
| 1027 |
+
//console.log(`${key}: ${hiddentabs[key]} ${index}`);
|
| 1028 |
+
let nkey = key + "_hr";
|
| 1029 |
+
if (headertabs[key] == true && hiddentabs[key] == false) {
|
| 1030 |
+
styleobj[nkey] =
|
| 1031 |
+
"#nav_menu_header_tabs > button:nth-child(" +
|
| 1032 |
+
(index + 1) +
|
| 1033 |
+
"){display:block;}";
|
| 1034 |
+
setting_ui_header_tabs.value += key + ",";
|
| 1035 |
+
} else {
|
| 1036 |
+
styleobj[nkey] =
|
| 1037 |
+
"#nav_menu_header_tabs > button:nth-child(" +
|
| 1038 |
+
(index + 1) +
|
| 1039 |
+
"){display:none;}";
|
| 1040 |
+
}
|
| 1041 |
+
});
|
| 1042 |
+
|
| 1043 |
+
tabOpsSave(setting_ui_header_tabs);
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
function navigate2TabItem(idx) {
|
| 1047 |
+
gradioApp()
|
| 1048 |
+
.querySelectorAll("#tabs > div.tabitem")
|
| 1049 |
+
.forEach(function (tabitem, index) {
|
| 1050 |
+
if (idx == index) {
|
| 1051 |
+
tabitem.style.display = "block";
|
| 1052 |
+
} else {
|
| 1053 |
+
tabitem.style.display = "none";
|
| 1054 |
+
}
|
| 1055 |
+
});
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
function navTabClicked(e) {
|
| 1059 |
+
const idx = parseInt(e.currentTarget.getAttribute("tab-id"));
|
| 1060 |
+
navigate2TabItem(idx);
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
maintabs.forEach(function (elem, index) {
|
| 1064 |
+
let tabvalue = elem.innerText.replaceAll(" ", "");
|
| 1065 |
+
hiddentabs[tabvalue] = false;
|
| 1066 |
+
headertabs[tabvalue] = false;
|
| 1067 |
+
let checked_hidden = "";
|
| 1068 |
+
let checked_header = "";
|
| 1069 |
+
if (setting_ui_hidden_tabs.value.indexOf(tabvalue) != -1) {
|
| 1070 |
+
hiddentabs[tabvalue] = true;
|
| 1071 |
+
checked_hidden = "checked";
|
| 1072 |
+
}
|
| 1073 |
+
if (setting_ui_header_tabs.value.indexOf(tabvalue) != -1) {
|
| 1074 |
+
headertabs[tabvalue] = true;
|
| 1075 |
+
checked_header = "checked";
|
| 1076 |
+
}
|
| 1077 |
+
radio_hidden_html +=
|
| 1078 |
+
'<label class="_' +
|
| 1079 |
+
tabvalue.toLowerCase() +
|
| 1080 |
+
' svelte-1qxcj04"><input type="checkbox" name="uiha" class="svelte-1qxcj04" ' +
|
| 1081 |
+
checked_hidden +
|
| 1082 |
+
' value="' +
|
| 1083 |
+
elem.innerText +
|
| 1084 |
+
'"><span class="ml-2 svelte-1qxcj04">' +
|
| 1085 |
+
elem.innerText +
|
| 1086 |
+
"</span></label>";
|
| 1087 |
+
|
| 1088 |
+
radio_header_html +=
|
| 1089 |
+
'<label class="_' +
|
| 1090 |
+
tabvalue.toLowerCase() +
|
| 1091 |
+
' svelte-1qxcj04"><input type="checkbox" name="uiha" class="svelte-1qxcj04" ' +
|
| 1092 |
+
checked_header +
|
| 1093 |
+
' value="' +
|
| 1094 |
+
elem.innerText +
|
| 1095 |
+
'"><span class="ml-2 svelte-1qxcj04">' +
|
| 1096 |
+
elem.innerText +
|
| 1097 |
+
"</span></label>";
|
| 1098 |
+
|
| 1099 |
+
tabitems[index].setAttribute("tab-item", index);
|
| 1100 |
+
elem.setAttribute("tab-id", index);
|
| 1101 |
+
|
| 1102 |
+
let clonetab = elem.cloneNode(true);
|
| 1103 |
+
clonetab.id = tabvalue + "_clone";
|
| 1104 |
+
parent_header_tabs.append(clonetab);
|
| 1105 |
+
clonetab.addEventListener("click", navTabClicked);
|
| 1106 |
+
});
|
| 1107 |
+
|
| 1108 |
+
let div = document.createElement("div");
|
| 1109 |
+
div.id = "hidden_radio_tabs_container";
|
| 1110 |
+
div.classList.add("flex", "flex-wrap", "gap-2", "wrap", "svelte-1qxcj04");
|
| 1111 |
+
div.innerHTML = radio_hidden_html;
|
| 1112 |
+
setting_ui_hidden_tabs.parentElement.appendChild(div);
|
| 1113 |
+
|
| 1114 |
+
div = document.createElement("div");
|
| 1115 |
+
div.id = "header_radio_tabs_container";
|
| 1116 |
+
div.classList.add("flex", "flex-wrap", "gap-2", "wrap", "svelte-1qxcj04");
|
| 1117 |
+
div.innerHTML = radio_header_html;
|
| 1118 |
+
setting_ui_header_tabs.parentElement.appendChild(div);
|
| 1119 |
+
|
| 1120 |
+
// hidden tabs
|
| 1121 |
+
gradioApp()
|
| 1122 |
+
.querySelector("#hidden_radio_tabs_container")
|
| 1123 |
+
.addEventListener("click", function (e) {
|
| 1124 |
+
if (e.target && e.target.matches("input[type='checkbox']")) {
|
| 1125 |
+
let tabvalue = e.target.value.replaceAll(" ", "");
|
| 1126 |
+
hiddentabs[tabvalue] = e.target.checked;
|
| 1127 |
+
tabsHiddenChange();
|
| 1128 |
+
updateOpStyles();
|
| 1129 |
+
}
|
| 1130 |
+
});
|
| 1131 |
+
// header tabs
|
| 1132 |
+
gradioApp()
|
| 1133 |
+
.querySelector("#header_radio_tabs_container")
|
| 1134 |
+
.addEventListener("click", function (e) {
|
| 1135 |
+
if (e.target && e.target.matches("input[type='checkbox']")) {
|
| 1136 |
+
let tabvalue = e.target.value.replaceAll(" ", "");
|
| 1137 |
+
headertabs[tabvalue] = e.target.checked;
|
| 1138 |
+
tabsHeaderChange();
|
| 1139 |
+
updateOpStyles();
|
| 1140 |
+
}
|
| 1141 |
+
});
|
| 1142 |
+
|
| 1143 |
+
tabsHiddenChange();
|
| 1144 |
+
|
| 1145 |
+
gradioApp()
|
| 1146 |
+
.querySelectorAll('[id^="image_buttons_"] button, #png_2img_results button')
|
| 1147 |
+
.forEach(function (elem) {
|
| 1148 |
+
//console.log(opts.send_seed);
|
| 1149 |
+
if (elem.id == "txt2img_tab") {
|
| 1150 |
+
elem.setAttribute("tab-id", 0);
|
| 1151 |
+
elem.addEventListener("click", navTabClicked);
|
| 1152 |
+
} else if (elem.id == "img2img_tab" || elem.id == "inpaint_tab") {
|
| 1153 |
+
elem.setAttribute("tab-id", 1);
|
| 1154 |
+
elem.addEventListener("click", navTabClicked);
|
| 1155 |
+
}
|
| 1156 |
+
if (elem.id == "extras_tab") {
|
| 1157 |
+
elem.setAttribute("tab-id", 2);
|
| 1158 |
+
elem.addEventListener("click", navTabClicked);
|
| 1159 |
+
}
|
| 1160 |
+
});
|
| 1161 |
+
|
| 1162 |
+
gradioApp()
|
| 1163 |
+
.querySelectorAll('[id$="2img_extra_tabs"] .search')
|
| 1164 |
+
.forEach(function (elem) {
|
| 1165 |
+
elem.addEventListener("keyup", function (e) {
|
| 1166 |
+
if (e.defaultPrevented) {
|
| 1167 |
+
return; // Do nothing if event already handled
|
| 1168 |
+
}
|
| 1169 |
+
switch (e.code) {
|
| 1170 |
+
case "Escape":
|
| 1171 |
+
if (e.target.value == "") {
|
| 1172 |
+
net_menu.click();
|
| 1173 |
+
} else {
|
| 1174 |
+
e.target.value = "";
|
| 1175 |
+
updateInput(e.target);
|
| 1176 |
+
}
|
| 1177 |
+
break;
|
| 1178 |
+
}
|
| 1179 |
+
});
|
| 1180 |
+
});
|
| 1181 |
+
|
| 1182 |
+
// add - remove quicksettings
|
| 1183 |
+
const settings_submit = gradioApp().querySelector("#settings_submit");
|
| 1184 |
+
const quick_parent = gradioApp().querySelector(
|
| 1185 |
+
"#quicksettings_overflow_container"
|
| 1186 |
+
);
|
| 1187 |
+
const setting_quicksettings = gradioApp().querySelector(
|
| 1188 |
+
"#setting_quicksettings textarea"
|
| 1189 |
+
);
|
| 1190 |
+
function saveQuickSettings() {
|
| 1191 |
+
updateInput(setting_quicksettings);
|
| 1192 |
+
const cEvent = new Event("click"); //submit
|
| 1193 |
+
Object.defineProperty(cEvent, "target", { value: settings_submit });
|
| 1194 |
+
settings_submit.dispatchEvent(cEvent);
|
| 1195 |
+
console.log(setting_quicksettings.value);
|
| 1196 |
+
}
|
| 1197 |
+
|
| 1198 |
+
/*
|
| 1199 |
+
function addModelCheckpoint(){
|
| 1200 |
+
if(setting_quicksettings.value.indexOf("sd_model_checkpoint") === -1){
|
| 1201 |
+
setting_quicksettings.value += ",sd_model_checkpoint";
|
| 1202 |
+
}
|
| 1203 |
+
saveQuickSettings();
|
| 1204 |
+
}
|
| 1205 |
+
*/
|
| 1206 |
+
|
| 1207 |
+
function add2quickSettings(id, section, checked) {
|
| 1208 |
+
let field_settings = setting_quicksettings.value.replace(" ", "");
|
| 1209 |
+
if (checked) {
|
| 1210 |
+
field_settings += "," + id;
|
| 1211 |
+
let setting_row = gradioApp().querySelector("#row_setting_" + id);
|
| 1212 |
+
quick_parent.append(setting_row);
|
| 1213 |
+
setting_row.classList.add("warning");
|
| 1214 |
+
} else {
|
| 1215 |
+
field_settings = field_settings.replaceAll(id, ",");
|
| 1216 |
+
const setting_parent = gradioApp().querySelector(
|
| 1217 |
+
"#" + section + "_settings_2img_settings"
|
| 1218 |
+
);
|
| 1219 |
+
let quick_row = gradioApp().querySelector("#row_setting_" + id);
|
| 1220 |
+
setting_parent.append(quick_row);
|
| 1221 |
+
quick_row.classList.remove("warning");
|
| 1222 |
+
}
|
| 1223 |
+
field_settings = field_settings.replace(/,{2,}/g, ",");
|
| 1224 |
+
setting_quicksettings.value = field_settings;
|
| 1225 |
+
//addModelCheckpoint();
|
| 1226 |
+
saveQuickSettings();
|
| 1227 |
+
//console.log(section + " - " + id + " - " + checked);
|
| 1228 |
+
}
|
| 1229 |
+
gradioApp()
|
| 1230 |
+
.querySelectorAll('[id*="add2quick_"]')
|
| 1231 |
+
.forEach(function (elem) {
|
| 1232 |
+
let trg = elem.id.split("_add2quick_setting_");
|
| 1233 |
+
let sid = trg[0];
|
| 1234 |
+
let tid = trg[1];
|
| 1235 |
+
let elem_input = gradioApp().querySelector("#" + elem.id + " input");
|
| 1236 |
+
if (elem_input) {
|
| 1237 |
+
elem_input.addEventListener("click", function (e) {
|
| 1238 |
+
add2quickSettings(tid, sid, e.target.checked);
|
| 1239 |
+
});
|
| 1240 |
+
}
|
| 1241 |
+
});
|
| 1242 |
+
//addModelCheckpoint();
|
| 1243 |
+
|
| 1244 |
+
// input release component dispatcher
|
| 1245 |
+
let cached_clone_range;
|
| 1246 |
+
let cached_clone_num;
|
| 1247 |
+
let active_clone_input = [];
|
| 1248 |
+
let focus_input;
|
| 1249 |
+
|
| 1250 |
+
function ui_input_release_component(elem) {
|
| 1251 |
+
//console.log("ok");
|
| 1252 |
+
if (active_clone_input.length > 0) return;
|
| 1253 |
+
|
| 1254 |
+
//img2img_width
|
| 1255 |
+
let parent = elem.parentElement;
|
| 1256 |
+
let comp_parent = parent.parentElement.parentElement;
|
| 1257 |
+
|
| 1258 |
+
if (
|
| 1259 |
+
comp_parent.id == "img2img_width" ||
|
| 1260 |
+
comp_parent.id == "img2img_height" ||
|
| 1261 |
+
comp_parent.id == "img2img_scale" ||
|
| 1262 |
+
comp_parent.id.indexOf("--ae-") != -1 ||
|
| 1263 |
+
comp_parent.id.indexOf("theme") != -1 ||
|
| 1264 |
+
comp_parent.className.indexOf("posex") != -1
|
| 1265 |
+
)
|
| 1266 |
+
return;
|
| 1267 |
+
|
| 1268 |
+
let clone_num = elem.cloneNode();
|
| 1269 |
+
active_clone_input.push(clone_num);
|
| 1270 |
+
|
| 1271 |
+
let label = parent.querySelector("label");
|
| 1272 |
+
|
| 1273 |
+
clone_num.id = "num_clone";
|
| 1274 |
+
clone_num.value = elem.value;
|
| 1275 |
+
parent.append(clone_num);
|
| 1276 |
+
elem.classList.add("hidden");
|
| 1277 |
+
|
| 1278 |
+
clone_num.addEventListener("change", function (e) {
|
| 1279 |
+
elem.value = clone_num.value;
|
| 1280 |
+
updateInput(elem);
|
| 1281 |
+
});
|
| 1282 |
+
|
| 1283 |
+
clone_num.addEventListener("focus", function (e) {
|
| 1284 |
+
focus_input = clone_num;
|
| 1285 |
+
});
|
| 1286 |
+
|
| 1287 |
+
cached_clone_num = clone_num;
|
| 1288 |
+
cached_clone_range = false;
|
| 1289 |
+
|
| 1290 |
+
if (label) {
|
| 1291 |
+
let comp_range = comp_parent.querySelector("input[type='range']");
|
| 1292 |
+
let clone_range = comp_range.cloneNode();
|
| 1293 |
+
active_clone_input.push(clone_range);
|
| 1294 |
+
|
| 1295 |
+
clone_range.id = comp_range.id + "_clone";
|
| 1296 |
+
clone_range.value = comp_range.value;
|
| 1297 |
+
comp_range.parentElement.append(clone_range);
|
| 1298 |
+
comp_range.classList.add("hidden");
|
| 1299 |
+
|
| 1300 |
+
clone_range.addEventListener("input", function (e) {
|
| 1301 |
+
clone_num.value = e.target.value;
|
| 1302 |
+
});
|
| 1303 |
+
clone_range.addEventListener("change", function (e) {
|
| 1304 |
+
elem.value = clone_range.value;
|
| 1305 |
+
updateInput(elem);
|
| 1306 |
+
});
|
| 1307 |
+
clone_num.addEventListener("input", function (e) {
|
| 1308 |
+
clone_range.value = e.target.value;
|
| 1309 |
+
});
|
| 1310 |
+
|
| 1311 |
+
cached_clone_range = clone_range;
|
| 1312 |
+
}
|
| 1313 |
+
}
|
| 1314 |
+
/* function ui_input_focus_handler(e) {
|
| 1315 |
+
if (e.target != focus_input) {
|
| 1316 |
+
focus_input = false;
|
| 1317 |
+
ui_input_release_handler(e);
|
| 1318 |
+
}
|
| 1319 |
+
} */
|
| 1320 |
+
|
| 1321 |
+
function ui_input_release_handler(e) {
|
| 1322 |
+
const len = active_clone_input.length;
|
| 1323 |
+
if (focus_input) {
|
| 1324 |
+
return;
|
| 1325 |
+
}
|
| 1326 |
+
if (len > 0) {
|
| 1327 |
+
if (e.target.id.indexOf("_clone") == -1) {
|
| 1328 |
+
for (var i = len - 1; i >= 0; i--) {
|
| 1329 |
+
let relem = active_clone_input[i];
|
| 1330 |
+
relem.previousElementSibling.classList.remove("hidden");
|
| 1331 |
+
relem.remove();
|
| 1332 |
+
active_clone_input.pop();
|
| 1333 |
+
}
|
| 1334 |
+
}
|
| 1335 |
+
}
|
| 1336 |
+
|
| 1337 |
+
let elem_type = e.target.tagName;
|
| 1338 |
+
if (elem_type == "INPUT") {
|
| 1339 |
+
let elem = e.target;
|
| 1340 |
+
if (elem.type == "number") {
|
| 1341 |
+
ui_input_release_component(elem);
|
| 1342 |
+
} else if (elem.type == "range") {
|
| 1343 |
+
elem = e.target.parentElement.querySelector("input[type='number']");
|
| 1344 |
+
if (elem) {
|
| 1345 |
+
ui_input_release_component(elem);
|
| 1346 |
+
}
|
| 1347 |
+
}
|
| 1348 |
+
}
|
| 1349 |
+
}
|
| 1350 |
+
let timeoutId;
|
| 1351 |
+
|
| 1352 |
+
function ui_input_touchmove_handler(e) {
|
| 1353 |
+
if (cached_clone_range && cached_clone_num) {
|
| 1354 |
+
if (e.touches) {
|
| 1355 |
+
const rect = cached_clone_range.getBoundingClientRect();
|
| 1356 |
+
const xoffset_min = rect.left + window.scrollX;
|
| 1357 |
+
//const xoffset_max = (rect.right + window.scrollX);
|
| 1358 |
+
//const yoffset_min = (rect.top + window.scrollY);
|
| 1359 |
+
//const yoffset_max = (rect.bottom + window.scrollY);
|
| 1360 |
+
//if( e.touches[0].pageY > yoffset_min && e.touches[0].pageY < yoffset_max && e.touches[0].pageX > xoffset_min && e.touches[0].pageX < xoffset_max){
|
| 1361 |
+
e.preventDefault();
|
| 1362 |
+
const percent =
|
| 1363 |
+
parseInt(((e.touches[0].pageX - xoffset_min) / rect.width) * 10000) /
|
| 1364 |
+
10000;
|
| 1365 |
+
cached_clone_range.value =
|
| 1366 |
+
percent * (cached_clone_range.max - cached_clone_range.min) +
|
| 1367 |
+
parseFloat(cached_clone_range.min);
|
| 1368 |
+
cached_clone_num.value = cached_clone_range.value;
|
| 1369 |
+
//}
|
| 1370 |
+
}
|
| 1371 |
+
}
|
| 1372 |
+
}
|
| 1373 |
+
function ui_input_touchend_handler(e) {
|
| 1374 |
+
if (cached_clone_range && cached_clone_num) {
|
| 1375 |
+
const elem = cached_clone_range.previousElementSibling;
|
| 1376 |
+
elem.value = cached_clone_range.value;
|
| 1377 |
+
updateInput(elem);
|
| 1378 |
+
}
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
function slider_contextmenu(e) {
|
| 1382 |
+
e.preventDefault();
|
| 1383 |
+
}
|
| 1384 |
+
function slider_touchend(e) {
|
| 1385 |
+
if (timeoutId) clearTimeout(timeoutId);
|
| 1386 |
+
}
|
| 1387 |
+
function slider_touchmove(e) {
|
| 1388 |
+
if (timeoutId) clearTimeout(timeoutId);
|
| 1389 |
+
}
|
| 1390 |
+
function slider_touchstart(e) {
|
| 1391 |
+
const gcontainer = e.target;
|
| 1392 |
+
//gcontainer.removeEventListener('contextmenu', slider_contextmenu);
|
| 1393 |
+
gcontainer.removeEventListener("touchend", slider_touchend);
|
| 1394 |
+
gcontainer.removeEventListener("touchmove", slider_touchmove);
|
| 1395 |
+
gcontainer.removeEventListener("touchend", ui_input_touchend_handler);
|
| 1396 |
+
gcontainer.removeEventListener("touchmove", ui_input_touchmove_handler);
|
| 1397 |
+
|
| 1398 |
+
timeoutId = setTimeout(function () {
|
| 1399 |
+
timeoutId = null;
|
| 1400 |
+
focus_input = false;
|
| 1401 |
+
e.stopPropagation();
|
| 1402 |
+
ui_input_release_handler(e);
|
| 1403 |
+
ui_input_touchmove_handler(e);
|
| 1404 |
+
gcontainer.addEventListener("touchmove", ui_input_touchmove_handler, {
|
| 1405 |
+
passive: false,
|
| 1406 |
+
});
|
| 1407 |
+
gcontainer.addEventListener("touchend", ui_input_touchend_handler);
|
| 1408 |
+
}, 500);
|
| 1409 |
+
|
| 1410 |
+
//gcontainer.addEventListener('contextmenu', slider_contextmenu);
|
| 1411 |
+
gcontainer.addEventListener("touchend", slider_touchend);
|
| 1412 |
+
gcontainer.addEventListener("touchmove", slider_touchmove, {
|
| 1413 |
+
passive: false,
|
| 1414 |
+
});
|
| 1415 |
+
}
|
| 1416 |
+
|
| 1417 |
+
function ui_dispatch_input_release(value) {
|
| 1418 |
+
const gcontainer = gradioApp().querySelector(".gradio-container");
|
| 1419 |
+
if (value) {
|
| 1420 |
+
gcontainer.addEventListener("mouseover", ui_input_release_handler);
|
| 1421 |
+
gcontainer.addEventListener("touchstart", slider_touchstart, {
|
| 1422 |
+
passive: false,
|
| 1423 |
+
});
|
| 1424 |
+
} else {
|
| 1425 |
+
gcontainer.removeEventListener("mouseover", ui_input_release_handler);
|
| 1426 |
+
gcontainer.removeEventListener("touchstart", slider_touchstart);
|
| 1427 |
+
//gcontainer.removeEventListener('contextmenu', slider_contextmenu);
|
| 1428 |
+
gcontainer.removeEventListener("touchend", slider_touchend);
|
| 1429 |
+
gcontainer.removeEventListener("touchmove", slider_touchmove);
|
| 1430 |
+
gcontainer.removeEventListener("touchend", ui_input_touchend_handler);
|
| 1431 |
+
gcontainer.removeEventListener("touchmove", ui_input_touchmove_handler);
|
| 1432 |
+
}
|
| 1433 |
+
}
|
| 1434 |
+
gradioApp()
|
| 1435 |
+
.querySelector("#setting_ui_dispatch_input_release input")
|
| 1436 |
+
.addEventListener("click", function (e) {
|
| 1437 |
+
ui_dispatch_input_release(e.target.checked);
|
| 1438 |
+
});
|
| 1439 |
+
ui_dispatch_input_release(opts.ui_dispatch_input_release);
|
| 1440 |
+
|
| 1441 |
+
// step ticks for performant input range
|
| 1442 |
+
function ui_show_range_ticks(value, interactive) {
|
| 1443 |
+
if (value) {
|
| 1444 |
+
const range_selectors = "input[type='range']";
|
| 1445 |
+
//const range_selectors = "[id$='_clone']:is(input[type='range'])";
|
| 1446 |
+
gradioApp()
|
| 1447 |
+
.querySelectorAll(range_selectors)
|
| 1448 |
+
.forEach(function (elem) {
|
| 1449 |
+
let spacing = (elem.step / (elem.max - elem.min)) * 100.0;
|
| 1450 |
+
let tsp = "max(3px, calc(" + spacing + "% - 1px))";
|
| 1451 |
+
let fsp = "max(4px, calc(" + spacing + "% + 0px))";
|
| 1452 |
+
var style = elem.style;
|
| 1453 |
+
style.setProperty(
|
| 1454 |
+
"--ae-slider-bg-overlay",
|
| 1455 |
+
"repeating-linear-gradient( 90deg, transparent, transparent " +
|
| 1456 |
+
tsp +
|
| 1457 |
+
", var(--ae-input-border-color) " +
|
| 1458 |
+
tsp +
|
| 1459 |
+
", var(--ae-input-border-color) " +
|
| 1460 |
+
fsp +
|
| 1461 |
+
" )"
|
| 1462 |
+
);
|
| 1463 |
+
});
|
| 1464 |
+
} else if (interactive) {
|
| 1465 |
+
gradioApp()
|
| 1466 |
+
.querySelectorAll("input[type='range']")
|
| 1467 |
+
.forEach(function (elem) {
|
| 1468 |
+
var style = elem.style;
|
| 1469 |
+
style.setProperty("--ae-slider-bg-overlay", "transparent");
|
| 1470 |
+
});
|
| 1471 |
+
}
|
| 1472 |
+
}
|
| 1473 |
+
gradioApp()
|
| 1474 |
+
.querySelector("#setting_ui_show_range_ticks input")
|
| 1475 |
+
.addEventListener("click", function (e) {
|
| 1476 |
+
ui_show_range_ticks(e.target.checked, true);
|
| 1477 |
+
});
|
| 1478 |
+
ui_show_range_ticks(opts.ui_show_range_ticks);
|
| 1479 |
+
|
| 1480 |
+
const gradio_main = gradioApp().querySelector(".gradio-container > div.main");
|
| 1481 |
+
function ui_no_slider_layout(value) {
|
| 1482 |
+
if (value) {
|
| 1483 |
+
gradio_main.classList.add("no-slider-layout");
|
| 1484 |
+
} else {
|
| 1485 |
+
gradio_main.classList.remove("no-slider-layout");
|
| 1486 |
+
}
|
| 1487 |
+
}
|
| 1488 |
+
gradioApp()
|
| 1489 |
+
.querySelector("#setting_ui_no_slider_layout input")
|
| 1490 |
+
.addEventListener("click", function (e) {
|
| 1491 |
+
ui_no_slider_layout(e.target.checked, true);
|
| 1492 |
+
});
|
| 1493 |
+
ui_no_slider_layout(opts.ui_no_slider_layout);
|
| 1494 |
+
|
| 1495 |
+
// draggable reordable quicksettings
|
| 1496 |
+
const container = gradioApp().querySelector(
|
| 1497 |
+
"#quicksettings_overflow_container"
|
| 1498 |
+
);
|
| 1499 |
+
let draggables;
|
| 1500 |
+
let lastElemAfter;
|
| 1501 |
+
let islastChild;
|
| 1502 |
+
let timeout;
|
| 1503 |
+
|
| 1504 |
+
function preventBehavior(e) {
|
| 1505 |
+
e.stopPropagation();
|
| 1506 |
+
e.preventDefault();
|
| 1507 |
+
return false;
|
| 1508 |
+
}
|
| 1509 |
+
let sdCheckpointModels = [];
|
| 1510 |
+
function getSdCheckpointModels() {
|
| 1511 |
+
gradioApp()
|
| 1512 |
+
.querySelectorAll("#txt2img_checkpoints_cards .card")
|
| 1513 |
+
.forEach(function (elem, i) {
|
| 1514 |
+
sdCheckpointModels[i] = elem.getAttribute("onclick").split('"')[1];
|
| 1515 |
+
});
|
| 1516 |
+
}
|
| 1517 |
+
getSdCheckpointModels();
|
| 1518 |
+
|
| 1519 |
+
function remove_overrides() {
|
| 1520 |
+
let checked_overrides = [];
|
| 1521 |
+
gradioApp()
|
| 1522 |
+
.querySelectorAll("#setting_ignore_overrides input")
|
| 1523 |
+
.forEach(function (elem, i) {
|
| 1524 |
+
if (elem.checked) {
|
| 1525 |
+
checked_overrides[i] = elem.nextElementSibling.innerHTML;
|
| 1526 |
+
}
|
| 1527 |
+
});
|
| 1528 |
+
//console.log(checked_overrides);
|
| 1529 |
+
gradioApp()
|
| 1530 |
+
.querySelectorAll("[id$='2img_override_settings'] .token")
|
| 1531 |
+
.forEach(function (token) {
|
| 1532 |
+
let token_arr = token.querySelector("span").innerHTML.split(":");
|
| 1533 |
+
let token_name = token_arr[0];
|
| 1534 |
+
let token_value = token_arr[1];
|
| 1535 |
+
token_value = token_value.replaceAll(" ", "");
|
| 1536 |
+
|
| 1537 |
+
if (token_name.indexOf("Model hash") != -1) {
|
| 1538 |
+
const info_label = gradioApp().querySelector(
|
| 1539 |
+
"[id$='2img_override_settings'] label span"
|
| 1540 |
+
);
|
| 1541 |
+
info_label.innerHTML = "Override settings MDL: unknown";
|
| 1542 |
+
for (let m = 0; m < sdCheckpointModels.length; m++) {
|
| 1543 |
+
let m_str = sdCheckpointModels[m];
|
| 1544 |
+
if (m_str.indexOf(token_value) != -1) {
|
| 1545 |
+
info_label.innerHTML =
|
| 1546 |
+
"Override settings <i>MDL: " + m_str.split("[")[0] + "</i>";
|
| 1547 |
+
break;
|
| 1548 |
+
}
|
| 1549 |
+
}
|
| 1550 |
+
}
|
| 1551 |
+
if (checked_overrides.indexOf(token_name) != -1) {
|
| 1552 |
+
token.querySelector(".token-remove").click();
|
| 1553 |
+
gradioApp()
|
| 1554 |
+
.querySelector(
|
| 1555 |
+
"#" + selectedTabItemId + " [id$='2img_override_settings']"
|
| 1556 |
+
)
|
| 1557 |
+
.parentElement.classList.add("show");
|
| 1558 |
+
} else {
|
| 1559 |
+
// maybe we add them again, for now we can select and add the removed tokens manually from the drop down
|
| 1560 |
+
}
|
| 1561 |
+
});
|
| 1562 |
+
}
|
| 1563 |
+
gradioApp()
|
| 1564 |
+
.querySelector("#setting_ignore_overrides")
|
| 1565 |
+
.addEventListener("click", function (e) {
|
| 1566 |
+
setTimeout(function () {
|
| 1567 |
+
remove_overrides();
|
| 1568 |
+
}, 100);
|
| 1569 |
+
});
|
| 1570 |
+
|
| 1571 |
+
function update_input_fields(tab) {
|
| 1572 |
+
/*
|
| 1573 |
+
let input_selectors = "#tab_"+ tab + " [id^='num_clone']:is(input[type='number'])";
|
| 1574 |
+
gradioApp().querySelectorAll(input_selectors).forEach(function (elem){
|
| 1575 |
+
let elem_source = elem.previousElementSibling;
|
| 1576 |
+
elem.value = elem_source.value;
|
| 1577 |
+
updateInput(elem);
|
| 1578 |
+
})
|
| 1579 |
+
*/
|
| 1580 |
+
remove_overrides();
|
| 1581 |
+
autoGrowPromptTextarea();
|
| 1582 |
+
}
|
| 1583 |
+
|
| 1584 |
+
gradioApp()
|
| 1585 |
+
.querySelectorAll(
|
| 1586 |
+
"#tab_pnginfo #png_2img_results button, [id$='2img_actions_column'] #paste"
|
| 1587 |
+
)
|
| 1588 |
+
.forEach(function (elem) {
|
| 1589 |
+
elem.addEventListener("click", function (e) {
|
| 1590 |
+
let button_id;
|
| 1591 |
+
if (e.target.id == "paste") {
|
| 1592 |
+
button_id = e.target.nextElementSibling.id.split("_")[0];
|
| 1593 |
+
} else {
|
| 1594 |
+
button_id = e.target.id.split("_")[0];
|
| 1595 |
+
}
|
| 1596 |
+
setTimeout(function () {
|
| 1597 |
+
update_input_fields(button_id);
|
| 1598 |
+
}, 500);
|
| 1599 |
+
});
|
| 1600 |
+
});
|
| 1601 |
+
|
| 1602 |
+
const pnginfo = gradioApp().querySelector("#tab_pnginfo");
|
| 1603 |
+
function forwardFromPngInfo() {
|
| 1604 |
+
if (selectedTabItemId == "tab_txt2img") {
|
| 1605 |
+
pnginfo.querySelector("#txt2img_tab").click();
|
| 1606 |
+
//close generation info
|
| 1607 |
+
gradioApp()
|
| 1608 |
+
.querySelector(
|
| 1609 |
+
"#txt2img_results > div:last-child > div.gradio-accordion > div.hide"
|
| 1610 |
+
)
|
| 1611 |
+
?.click();
|
| 1612 |
+
|
| 1613 |
+
const img_src = pnginfo.querySelector("img");
|
| 1614 |
+
const gallery_parent = gradioApp().querySelector(
|
| 1615 |
+
"#txt2img_gallery_container"
|
| 1616 |
+
);
|
| 1617 |
+
const live_preview = gallery_parent.querySelector(".livePreview");
|
| 1618 |
+
if (live_preview) {
|
| 1619 |
+
live_preview.innerHTML =
|
| 1620 |
+
'<img width="' +
|
| 1621 |
+
img_src.width +
|
| 1622 |
+
'" height="' +
|
| 1623 |
+
img_src.height +
|
| 1624 |
+
'" src="' +
|
| 1625 |
+
img_src.src +
|
| 1626 |
+
'">';
|
| 1627 |
+
} else {
|
| 1628 |
+
const div = document.createElement("div");
|
| 1629 |
+
div.classList.add("livePreview", "dropPreview");
|
| 1630 |
+
div.innerHTML =
|
| 1631 |
+
'<img width="' +
|
| 1632 |
+
img_src.width +
|
| 1633 |
+
'" height="' +
|
| 1634 |
+
img_src.height +
|
| 1635 |
+
'" src="' +
|
| 1636 |
+
img_src.src +
|
| 1637 |
+
'">';
|
| 1638 |
+
gallery_parent.prepend(div);
|
| 1639 |
+
}
|
| 1640 |
+
} else if (selectedTabItemId == "tab_img2img") {
|
| 1641 |
+
pnginfo.querySelector("#img2img_tab").click();
|
| 1642 |
+
//close generation info
|
| 1643 |
+
gradioApp()
|
| 1644 |
+
.querySelector(
|
| 1645 |
+
"#img2img_results > div:last-child > div.gradio-accordion > div.hide"
|
| 1646 |
+
)
|
| 1647 |
+
?.click();
|
| 1648 |
+
}
|
| 1649 |
+
}
|
| 1650 |
+
|
| 1651 |
+
function fetchPngInfoData(files) {
|
| 1652 |
+
/* const oldFetch = window.fetch;
|
| 1653 |
+
|
| 1654 |
+
window.fetch = async (input, options) => {
|
| 1655 |
+
const response = await oldFetch(input, options);
|
| 1656 |
+
if( 'run/predict/' === input ) {
|
| 1657 |
+
if(response.ok){
|
| 1658 |
+
window.fetch = oldFetch;
|
| 1659 |
+
}
|
| 1660 |
+
}
|
| 1661 |
+
return response;
|
| 1662 |
+
}; */
|
| 1663 |
+
|
| 1664 |
+
const fileInput = gradioApp().querySelector(
|
| 1665 |
+
'#pnginfo_image input[type="file"]'
|
| 1666 |
+
);
|
| 1667 |
+
if (fileInput.files != files) {
|
| 1668 |
+
fileInput.files = files;
|
| 1669 |
+
fileInput.dispatchEvent(new Event("change"));
|
| 1670 |
+
}
|
| 1671 |
+
|
| 1672 |
+
setTimeout(function () {
|
| 1673 |
+
forwardFromPngInfo();
|
| 1674 |
+
}, 500);
|
| 1675 |
+
}
|
| 1676 |
+
|
| 1677 |
+
function drop2View(e) {
|
| 1678 |
+
e.stopPropagation();
|
| 1679 |
+
e.preventDefault();
|
| 1680 |
+
const files = e.dataTransfer.files;
|
| 1681 |
+
|
| 1682 |
+
if (!isValidImageList(files)) {
|
| 1683 |
+
return;
|
| 1684 |
+
}
|
| 1685 |
+
const data_image = gradioApp().querySelector(
|
| 1686 |
+
'#pnginfo_image [data-testid="image"]'
|
| 1687 |
+
);
|
| 1688 |
+
data_image.querySelector('[aria-label="Clear"]')?.click();
|
| 1689 |
+
setTimeout(function () {
|
| 1690 |
+
fetchPngInfoData(files);
|
| 1691 |
+
}, 1000);
|
| 1692 |
+
}
|
| 1693 |
+
|
| 1694 |
+
gradioApp()
|
| 1695 |
+
.querySelectorAll('[id$="2img_results"]')
|
| 1696 |
+
.forEach((elem) => {
|
| 1697 |
+
elem.addEventListener("drop", drop2View);
|
| 1698 |
+
});
|
| 1699 |
+
|
| 1700 |
+
// function that gets the element next of cursor/touch
|
| 1701 |
+
function getElementAfter(container, y) {
|
| 1702 |
+
return draggables.reduce(
|
| 1703 |
+
(closest, child) => {
|
| 1704 |
+
const box = child.getBoundingClientRect();
|
| 1705 |
+
const offset = y - box.top - box.height / 2;
|
| 1706 |
+
if (offset < 0 && offset > closest.offset) {
|
| 1707 |
+
return { offset: offset, element: child };
|
| 1708 |
+
} else {
|
| 1709 |
+
return closest;
|
| 1710 |
+
}
|
| 1711 |
+
},
|
| 1712 |
+
{ offset: Number.NEGATIVE_INFINITY }
|
| 1713 |
+
).element;
|
| 1714 |
+
}
|
| 1715 |
+
|
| 1716 |
+
function dragOrderChange(elementAfter, isComplete, delem) {
|
| 1717 |
+
if (lastElemAfter !== elementAfter || islastChild) {
|
| 1718 |
+
if (lastElemAfter != null) {
|
| 1719 |
+
lastElemAfter.classList.remove("marker-top", "marker-bottom");
|
| 1720 |
+
}
|
| 1721 |
+
|
| 1722 |
+
if (elementAfter == null) {
|
| 1723 |
+
islastChild = true;
|
| 1724 |
+
lastElemAfter.classList.add("marker-bottom");
|
| 1725 |
+
} else {
|
| 1726 |
+
islastChild = false;
|
| 1727 |
+
elementAfter.classList.add("marker-top");
|
| 1728 |
+
lastElemAfter = elementAfter;
|
| 1729 |
+
}
|
| 1730 |
+
}
|
| 1731 |
+
|
| 1732 |
+
if (isComplete) {
|
| 1733 |
+
if (elementAfter == null) {
|
| 1734 |
+
container.append(delem);
|
| 1735 |
+
} else {
|
| 1736 |
+
container.insertBefore(delem, elementAfter);
|
| 1737 |
+
}
|
| 1738 |
+
|
| 1739 |
+
let order_settings = "";
|
| 1740 |
+
|
| 1741 |
+
gradioApp()
|
| 1742 |
+
.querySelectorAll("#quicksettings_overflow_container > div")
|
| 1743 |
+
.forEach(function (el) {
|
| 1744 |
+
el.classList.remove("marker-top", "marker-bottom", "dragging");
|
| 1745 |
+
order_settings += el.id.split("row_setting_")[1] + ",";
|
| 1746 |
+
});
|
| 1747 |
+
//console.log(order_settings);
|
| 1748 |
+
const setting_quicksettings = gradioApp().querySelector(
|
| 1749 |
+
"#setting_quicksettings textarea"
|
| 1750 |
+
);
|
| 1751 |
+
setting_quicksettings.value = order_settings;
|
| 1752 |
+
updateInput(setting_quicksettings);
|
| 1753 |
+
|
| 1754 |
+
const cEvent = new Event("click"); //submit
|
| 1755 |
+
Object.defineProperty(cEvent, "target", { value: settings_submit });
|
| 1756 |
+
settings_submit.dispatchEvent(cEvent);
|
| 1757 |
+
|
| 1758 |
+
container.classList.remove("no-scroll");
|
| 1759 |
+
}
|
| 1760 |
+
}
|
| 1761 |
+
|
| 1762 |
+
function touchmove(e) {
|
| 1763 |
+
let y = e.touches[0].clientY;
|
| 1764 |
+
let elementAfter = getElementAfter(container, y);
|
| 1765 |
+
dragOrderChange(elementAfter);
|
| 1766 |
+
}
|
| 1767 |
+
function touchstart(e) {
|
| 1768 |
+
e.currentTarget.draggable = "false";
|
| 1769 |
+
let target = e.currentTarget;
|
| 1770 |
+
// touch should be hold for 1 second
|
| 1771 |
+
timeout = setTimeout(function () {
|
| 1772 |
+
target.classList.add("dragging");
|
| 1773 |
+
container.classList.add("no-scroll");
|
| 1774 |
+
target.addEventListener("touchmove", touchmove);
|
| 1775 |
+
container.addEventListener("touchmove", preventBehavior, {
|
| 1776 |
+
passive: false,
|
| 1777 |
+
});
|
| 1778 |
+
}, 1000);
|
| 1779 |
+
|
| 1780 |
+
target.addEventListener("touchend", touchend);
|
| 1781 |
+
target.addEventListener("touchcancel", touchcancel);
|
| 1782 |
+
}
|
| 1783 |
+
function touchend(e) {
|
| 1784 |
+
e.currentTarget.draggable = "true";
|
| 1785 |
+
clearTimeout(timeout);
|
| 1786 |
+
e.currentTarget.removeEventListener("touchmove", touchmove);
|
| 1787 |
+
container.removeEventListener("touchmove", preventBehavior);
|
| 1788 |
+
let y = e.changedTouches[0].clientY;
|
| 1789 |
+
let elementAfter = getElementAfter(container, y);
|
| 1790 |
+
dragOrderChange(elementAfter, true, e.currentTarget);
|
| 1791 |
+
}
|
| 1792 |
+
function touchcancel(e) {
|
| 1793 |
+
e.currentTarget.draggable = "true";
|
| 1794 |
+
clearTimeout(timeout);
|
| 1795 |
+
e.currentTarget.classList.remove("dragging");
|
| 1796 |
+
e.currentTarget.removeEventListener("touchmove", touchmove);
|
| 1797 |
+
container.removeEventListener("touchmove", preventBehavior);
|
| 1798 |
+
}
|
| 1799 |
+
|
| 1800 |
+
function dragstart(e) {
|
| 1801 |
+
e.currentTarget.draggable = "false";
|
| 1802 |
+
e.currentTarget.classList.add("dragging");
|
| 1803 |
+
}
|
| 1804 |
+
function dragend(e) {
|
| 1805 |
+
e.stopPropagation();
|
| 1806 |
+
e.preventDefault();
|
| 1807 |
+
e.currentTarget.draggable = "true";
|
| 1808 |
+
let y = e.clientY;
|
| 1809 |
+
let elementAfter = getElementAfter(container, y);
|
| 1810 |
+
dragOrderChange(elementAfter, true, e.currentTarget);
|
| 1811 |
+
}
|
| 1812 |
+
function dragOver(e) {
|
| 1813 |
+
e.preventDefault();
|
| 1814 |
+
let y = e.clientY;
|
| 1815 |
+
let elementAfter = getElementAfter(container, y);
|
| 1816 |
+
dragOrderChange(elementAfter);
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
function actionQuickSettingsDraggable(checked) {
|
| 1820 |
+
if (checked) {
|
| 1821 |
+
draggables = Array.from(
|
| 1822 |
+
gradioApp().querySelectorAll(
|
| 1823 |
+
"#quicksettings_overflow_container > div:not(.dragging)"
|
| 1824 |
+
)
|
| 1825 |
+
);
|
| 1826 |
+
gradioApp().addEventListener("drop", preventBehavior);
|
| 1827 |
+
} else {
|
| 1828 |
+
gradioApp().removeEventListener("drop", preventBehavior);
|
| 1829 |
+
}
|
| 1830 |
+
|
| 1831 |
+
gradioApp()
|
| 1832 |
+
.querySelectorAll("#quicksettings_overflow_container > div")
|
| 1833 |
+
.forEach(function (elem) {
|
| 1834 |
+
elem.draggable = checked;
|
| 1835 |
+
if (checked) {
|
| 1836 |
+
elem.addEventListener("touchstart", touchstart);
|
| 1837 |
+
elem.addEventListener("dragstart", dragstart);
|
| 1838 |
+
elem.addEventListener("dragend", dragend);
|
| 1839 |
+
elem.addEventListener("dragover", dragOver);
|
| 1840 |
+
} else {
|
| 1841 |
+
elem.removeEventListener("touchstart", touchstart, false);
|
| 1842 |
+
elem.removeEventListener("touchend", touchend, false);
|
| 1843 |
+
elem.removeEventListener("touchcancel", touchcancel, false);
|
| 1844 |
+
elem.removeEventListener("touchmove", touchmove, false);
|
| 1845 |
+
elem.removeEventListener("dragstart", dragstart, false);
|
| 1846 |
+
elem.removeEventListener("dragend", dragend, false);
|
| 1847 |
+
elem.removeEventListener("dragover", dragOver, false);
|
| 1848 |
+
}
|
| 1849 |
+
});
|
| 1850 |
+
}
|
| 1851 |
+
|
| 1852 |
+
gradioApp()
|
| 1853 |
+
.querySelector("#quicksettings_draggable")
|
| 1854 |
+
.addEventListener("click", function (e) {
|
| 1855 |
+
if (e.target && e.target.matches("input[type='checkbox']")) {
|
| 1856 |
+
actionQuickSettingsDraggable(e.target.checked);
|
| 1857 |
+
}
|
| 1858 |
+
});
|
| 1859 |
+
|
| 1860 |
+
updateOpStyles();
|
| 1861 |
+
|
| 1862 |
+
/* anapnoe ui end */
|
| 1863 |
+
});
|
| 1864 |
+
|
| 1865 |
+
onOptionsChanged(function() {
|
| 1866 |
+
var elem = gradioApp().getElementById('sd_checkpoint_hash');
|
| 1867 |
+
var sd_checkpoint_hash = opts.sd_checkpoint_hash || "";
|
| 1868 |
+
var shorthash = sd_checkpoint_hash.substring(0, 10);
|
| 1869 |
+
|
| 1870 |
+
if (elem && elem.textContent != shorthash) {
|
| 1871 |
+
elem.textContent = shorthash;
|
| 1872 |
+
elem.title = sd_checkpoint_hash;
|
| 1873 |
+
elem.href = "https://google.com/search?q=" + sd_checkpoint_hash;
|
| 1874 |
+
}
|
| 1875 |
+
});
|
| 1876 |
+
|
| 1877 |
+
let txt2img_textarea, img2img_textarea = undefined;
|
| 1878 |
+
let wait_time = 800;
|
| 1879 |
+
let token_timeouts = {};
|
| 1880 |
+
|
| 1881 |
+
function update_txt2img_tokens(...args) {
|
| 1882 |
+
update_token_counter("txt2img_token_button");
|
| 1883 |
+
if (args.length == 2) {
|
| 1884 |
+
return args[0];
|
| 1885 |
+
}
|
| 1886 |
+
return args;
|
| 1887 |
+
}
|
| 1888 |
+
|
| 1889 |
+
function update_img2img_tokens(...args) {
|
| 1890 |
+
update_token_counter(
|
| 1891 |
+
"img2img_token_button"
|
| 1892 |
+
);
|
| 1893 |
+
if (args.length == 2) {
|
| 1894 |
+
return args[0];
|
| 1895 |
+
}
|
| 1896 |
+
return args;
|
| 1897 |
+
}
|
| 1898 |
+
|
| 1899 |
+
function update_token_counter(button_id) {
|
| 1900 |
+
if (token_timeouts[button_id]) {
|
| 1901 |
+
clearTimeout(token_timeouts[button_id]);
|
| 1902 |
+
}
|
| 1903 |
+
token_timeouts[button_id] = setTimeout(() => gradioApp().getElementById(button_id)?.click(), wait_time);
|
| 1904 |
+
}
|
| 1905 |
+
|
| 1906 |
+
|
| 1907 |
+
|
| 1908 |
+
function restart_reload() {
|
| 1909 |
+
let bg_color = window
|
| 1910 |
+
.getComputedStyle(gradioApp().querySelector("#header-top"))
|
| 1911 |
+
.getPropertyValue("--ae-main-bg-color");
|
| 1912 |
+
let primary_color = window
|
| 1913 |
+
.getComputedStyle(gradioApp().querySelector(".icon-info"))
|
| 1914 |
+
.getPropertyValue("--ae-primary-color");
|
| 1915 |
+
let panel_color = window
|
| 1916 |
+
.getComputedStyle(gradioApp().querySelector(".gradio-box"))
|
| 1917 |
+
.getPropertyValue("--ae-panel-bg-color");
|
| 1918 |
+
|
| 1919 |
+
localStorage.setItem("bg_color", bg_color);
|
| 1920 |
+
localStorage.setItem("primary_color", primary_color);
|
| 1921 |
+
localStorage.setItem("panel_color", panel_color);
|
| 1922 |
+
|
| 1923 |
+
if (localStorage.hasOwnProperty("bg_color")) {
|
| 1924 |
+
bg_color = localStorage.getItem("bg_color");
|
| 1925 |
+
primary_color = localStorage.getItem("primary_color");
|
| 1926 |
+
panel_color = localStorage.getItem("panel_color");
|
| 1927 |
+
}
|
| 1928 |
+
|
| 1929 |
+
document.body.style.backgroundColor = bg_color;
|
| 1930 |
+
|
| 1931 |
+
let style = document.createElement("style");
|
| 1932 |
+
style.type = "text/css";
|
| 1933 |
+
style.innerHTML =
|
| 1934 |
+
".loader{position:absolute;top:50vh;left:50vw;height:60px;width:160px;margin:0;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)} .circles{position:absolute;left:-5px;top:0;height:60px;width:180px} .circles span{position:absolute;top:25px;height:12px;width:12px;border-radius:12px;background-color:" +
|
| 1935 |
+
panel_color +
|
| 1936 |
+
"} .circles span.one{right:80px} .circles span.two{right:40px} .circles span.three{right:0px} .circles{-webkit-animation:animcircles 0.5s infinite linear;animation:animcircles 0.5s infinite linear} @-webkit-keyframes animcircles{0%{-webkit-transform:translate(0px,0px);transform:translate(0px,0px)}100%{-webkit-transform:translate(-40px,0px);transform:translate(-40px,0px)}} @keyframes animcircles{0%{-webkit-transform:translate(0px,0px);transform:translate(0px,0px)}100%{-webkit-transform:translate(-40px,0px);transform:translate(-40px,0px)}} .pacman{position:absolute;left:0;top:0;height:60px;width:60px} .pacman .eye{position:absolute;top:10px;left:30px;height:7px;width:7px;border-radius:7px;background-color:" +
|
| 1937 |
+
bg_color +
|
| 1938 |
+
'} .pacman span{position:absolute;top:0;left:0;height:60px;width:60px} .pacman span::before{content:"";position:absolute;left:0;height:30px;width:60px;background-color:' +
|
| 1939 |
+
primary_color +
|
| 1940 |
+
"} .pacman .top::before{top:0;border-radius:60px 60px 0px 0px} .pacman .bottom::before{bottom:0;border-radius:0px 0px 60px 60px} .pacman .left::before{bottom:0;height:60px;width:30px;border-radius:60px 0px 0px 60px} .pacman .top{-webkit-animation:animtop 0.5s infinite;animation:animtop 0.5s infinite} @-webkit-keyframes animtop{0%,100%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}} @keyframes animtop{0%,100%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}} .pacman .bottom{-webkit-animation:animbottom 0.5s infinite;animation:animbottom 0.5s infinite} @-webkit-keyframes animbottom{0%,100%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(45deg);transform:rotate(45deg)}} @keyframes animbottom{0%,100%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}50%{-webkit-transform:rotate(45deg);transform:rotate(45deg)}}";
|
| 1941 |
+
|
| 1942 |
+
document.getElementsByTagName("head")[0].appendChild(style);
|
| 1943 |
+
document.body.innerHTML =
|
| 1944 |
+
'<div class="loader"><div class="circles"><span class="one"></span><span class="two"></span><span class="three"></span></div><div class="pacman"><span class="top"></span><span class="bottom"></span><span class="left"></span><div class="eye"></div></div></div>';
|
| 1945 |
+
|
| 1946 |
+
var requestPing = function () {
|
| 1947 |
+
requestGet(
|
| 1948 |
+
"./internal/ping",
|
| 1949 |
+
{},
|
| 1950 |
+
function (data) {
|
| 1951 |
+
location.reload();
|
| 1952 |
+
},
|
| 1953 |
+
function () {
|
| 1954 |
+
setTimeout(requestPing, 500);
|
| 1955 |
+
}
|
| 1956 |
+
);
|
| 1957 |
+
};
|
| 1958 |
+
|
| 1959 |
+
setTimeout(requestPing, 2000);
|
| 1960 |
+
|
| 1961 |
+
return [];
|
| 1962 |
+
}
|
| 1963 |
+
|
| 1964 |
+
// Simulate an `input` DOM event for Gradio Textbox component. Needed after you edit its contents in javascript, otherwise your edits
|
| 1965 |
+
// will only visible on web page and not sent to python.
|
| 1966 |
+
function updateInput(target) {
|
| 1967 |
+
const e = new Event("input", { bubbles: true });
|
| 1968 |
+
Object.defineProperty(e, "target", { value: target });
|
| 1969 |
+
target.dispatchEvent(e);
|
| 1970 |
+
const eb = new Event("blur");
|
| 1971 |
+
Object.defineProperty(eb, "target", { value: target });
|
| 1972 |
+
target.dispatchEvent(eb);
|
| 1973 |
+
}
|
| 1974 |
+
|
| 1975 |
+
document.addEventListener("readystatechange", function (e) {
|
| 1976 |
+
document.body.style.display = "none";
|
| 1977 |
+
if (localStorage.hasOwnProperty("bg_color")) {
|
| 1978 |
+
document.getElementsByTagName("html")[0].style.backgroundColor =
|
| 1979 |
+
localStorage.getItem("bg_color");
|
| 1980 |
+
document.body.style.backgroundColor = localStorage.getItem("bg_color");
|
| 1981 |
+
}
|
| 1982 |
+
});
|
| 1983 |
+
|
| 1984 |
+
window.onload = function () {
|
| 1985 |
+
document.getElementsByTagName("html")[0].style.backgroundColor =
|
| 1986 |
+
localStorage.getItem("bg_color");
|
| 1987 |
+
document.body.style.backgroundColor = localStorage.getItem("bg_color");
|
| 1988 |
+
document.body.style.display = "none";
|
| 1989 |
+
document.body.classList.add("dark");
|
| 1990 |
+
setTimeout(function () {
|
| 1991 |
+
document.body.style.display = "block";
|
| 1992 |
+
}, 1000);
|
| 1993 |
+
};
|
| 1994 |
+
|
| 1995 |
+
var desiredCheckpointName = null;
|
| 1996 |
+
function selectCheckpoint(name) {
|
| 1997 |
+
desiredCheckpointName = name;
|
| 1998 |
+
gradioApp().getElementById('change_checkpoint').click();
|
| 1999 |
+
}
|
| 2000 |
+
|
| 2001 |
+
function currentImg2imgSourceResolution(w, h, scaleBy) {
|
| 2002 |
+
var img = gradioApp().querySelector('#mode_img2img > div[style="display: block;"] img');
|
| 2003 |
+
return img ? [img.naturalWidth, img.naturalHeight, scaleBy] : [0, 0, scaleBy];
|
| 2004 |
+
}
|
| 2005 |
+
|
| 2006 |
+
function updateImg2imgResizeToTextAfterChangingImage() {
|
| 2007 |
+
// At the time this is called from gradio, the image has no yet been replaced.
|
| 2008 |
+
// There may be a better solution, but this is simple and straightforward so I'm going with it.
|
| 2009 |
+
|
| 2010 |
+
setTimeout(function() {
|
| 2011 |
+
gradioApp().getElementById('img2img_update_resize_to').click();
|
| 2012 |
+
}, 500);
|
| 2013 |
+
|
| 2014 |
+
return [];
|
| 2015 |
+
|
| 2016 |
+
}
|
| 2017 |
+
|
| 2018 |
+
|
| 2019 |
+
|
| 2020 |
+
function setRandomSeed(elem_id) {
|
| 2021 |
+
var input = gradioApp().querySelector("#" + elem_id + " input");
|
| 2022 |
+
if (!input) return [];
|
| 2023 |
+
|
| 2024 |
+
input.value = "-1";
|
| 2025 |
+
updateInput(input);
|
| 2026 |
+
return [];
|
| 2027 |
+
}
|
| 2028 |
+
|
| 2029 |
+
function switchWidthHeight(tabname) {
|
| 2030 |
+
var width = gradioApp().querySelector("#" + tabname + "_width input[type=number]");
|
| 2031 |
+
var height = gradioApp().querySelector("#" + tabname + "_height input[type=number]");
|
| 2032 |
+
if (!width || !height) return [];
|
| 2033 |
+
|
| 2034 |
+
var tmp = width.value;
|
| 2035 |
+
width.value = height.value;
|
| 2036 |
+
height.value = tmp;
|
| 2037 |
+
|
| 2038 |
+
updateInput(width);
|
| 2039 |
+
updateInput(height);
|
| 2040 |
+
return [];
|
| 2041 |
+
}
|
javascript/ui_settings_hints.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var settingsHintsSetup = false;
|
| 2 |
+
|
| 3 |
+
onOptionsChanged(function() {
|
| 4 |
+
if (settingsHintsSetup) return;
|
| 5 |
+
settingsHintsSetup = true;
|
| 6 |
+
|
| 7 |
+
gradioApp().querySelectorAll('#settings [id^=setting_]').forEach(function(div) {
|
| 8 |
+
var name = div.id.substr(8);
|
| 9 |
+
var commentBefore = opts._comments_before[name];
|
| 10 |
+
var commentAfter = opts._comments_after[name];
|
| 11 |
+
|
| 12 |
+
if (!commentBefore && !commentAfter) return;
|
| 13 |
+
|
| 14 |
+
var span = null;
|
| 15 |
+
if (div.classList.contains('gradio-checkbox')) span = div.querySelector('label span');
|
| 16 |
+
else if (div.classList.contains('gradio-checkboxgroup')) span = div.querySelector('span').firstChild;
|
| 17 |
+
else if (div.classList.contains('gradio-radio')) span = div.querySelector('span').firstChild;
|
| 18 |
+
else span = div.querySelector('label span').firstChild;
|
| 19 |
+
|
| 20 |
+
if (!span) return;
|
| 21 |
+
|
| 22 |
+
if (commentBefore) {
|
| 23 |
+
var comment = document.createElement('DIV');
|
| 24 |
+
comment.className = 'settings-comment';
|
| 25 |
+
comment.innerHTML = commentBefore;
|
| 26 |
+
span.parentElement.insertBefore(document.createTextNode('\xa0'), span);
|
| 27 |
+
span.parentElement.insertBefore(comment, span);
|
| 28 |
+
span.parentElement.insertBefore(document.createTextNode('\xa0'), span);
|
| 29 |
+
}
|
| 30 |
+
if (commentAfter) {
|
| 31 |
+
comment = document.createElement('DIV');
|
| 32 |
+
comment.className = 'settings-comment';
|
| 33 |
+
comment.innerHTML = commentAfter;
|
| 34 |
+
span.parentElement.insertBefore(comment, span.nextSibling);
|
| 35 |
+
span.parentElement.insertBefore(document.createTextNode('\xa0'), span.nextSibling);
|
| 36 |
+
}
|
| 37 |
+
});
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
function settingsHintsShowQuicksettings() {
|
| 41 |
+
requestGet("./internal/quicksettings-hint", {}, function(data) {
|
| 42 |
+
var table = document.createElement('table');
|
| 43 |
+
table.className = 'popup-table';
|
| 44 |
+
|
| 45 |
+
data.forEach(function(obj) {
|
| 46 |
+
var tr = document.createElement('tr');
|
| 47 |
+
var td = document.createElement('td');
|
| 48 |
+
td.textContent = obj.name;
|
| 49 |
+
tr.appendChild(td);
|
| 50 |
+
|
| 51 |
+
td = document.createElement('td');
|
| 52 |
+
td.textContent = obj.label;
|
| 53 |
+
tr.appendChild(td);
|
| 54 |
+
|
| 55 |
+
table.appendChild(tr);
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
popup(table);
|
| 59 |
+
});
|
| 60 |
+
}
|
launch.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from modules import launch_utils
|
| 2 |
+
|
| 3 |
+
args = launch_utils.args
|
| 4 |
+
python = launch_utils.python
|
| 5 |
+
git = launch_utils.git
|
| 6 |
+
index_url = launch_utils.index_url
|
| 7 |
+
dir_repos = launch_utils.dir_repos
|
| 8 |
+
|
| 9 |
+
commit_hash = launch_utils.commit_hash
|
| 10 |
+
git_tag = launch_utils.git_tag
|
| 11 |
+
|
| 12 |
+
run = launch_utils.run
|
| 13 |
+
is_installed = launch_utils.is_installed
|
| 14 |
+
repo_dir = launch_utils.repo_dir
|
| 15 |
+
|
| 16 |
+
run_pip = launch_utils.run_pip
|
| 17 |
+
check_run_python = launch_utils.check_run_python
|
| 18 |
+
git_clone = launch_utils.git_clone
|
| 19 |
+
git_pull_recursive = launch_utils.git_pull_recursive
|
| 20 |
+
list_extensions = launch_utils.list_extensions
|
| 21 |
+
run_extension_installer = launch_utils.run_extension_installer
|
| 22 |
+
prepare_environment = launch_utils.prepare_environment
|
| 23 |
+
configure_for_tests = launch_utils.configure_for_tests
|
| 24 |
+
start = launch_utils.start
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def main():
|
| 28 |
+
launch_utils.startup_timer.record("initial startup")
|
| 29 |
+
|
| 30 |
+
with launch_utils.startup_timer.subcategory("prepare environment"):
|
| 31 |
+
if not args.skip_prepare_environment:
|
| 32 |
+
prepare_environment()
|
| 33 |
+
|
| 34 |
+
if args.test_server:
|
| 35 |
+
configure_for_tests()
|
| 36 |
+
|
| 37 |
+
start()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
main()
|
localizations/Put localization files here.txt
ADDED
|
File without changes
|
models/Stable-diffusion/3dredux.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40d4f9d626a992a41c6fd354d987bb74ef3667420d92068f2e75a267322d5766
|
| 3 |
+
size 1965287410
|
models/Stable-diffusion/Put Stable Diffusion checkpoints here.txt
ADDED
|
File without changes
|