Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60efbc4618 | |||
| a56190cdb1 | |||
| 04903af798 | |||
| e8c3b1f2a0 | |||
| 8bf30e3c42 | |||
| fbc51fa210 | |||
| 7025a2c4a5 | |||
| 0120768f63 | |||
| b425b97ad6 | |||
| 539ea3982d | |||
| 65bd61e87c | |||
| 023454b49e | |||
| cd869bb7a3 | |||
| 95686227bd | |||
| df74c3c638 |
@@ -1,36 +1,69 @@
|
||||
// Stable Diffusion WebUI - Bracket checker
|
||||
// By Hingashi no Florin/Bwin4L & @akx
|
||||
// Stable Diffusion WebUI - Bracket Checker
|
||||
// By @Bwin4L, @akx, @w-e-w, @Haoming02
|
||||
// Counts open and closed brackets (round, square, curly) in the prompt and negative prompt text boxes in the txt2img and img2img tabs.
|
||||
// If there's a mismatch, the keyword counter turns red and if you hover on it, a tooltip tells you what's wrong.
|
||||
// If there's a mismatch, the keyword counter turns red, and if you hover on it, a tooltip tells you what's wrong.
|
||||
|
||||
function checkBrackets(textArea, counterElt) {
|
||||
var counts = {};
|
||||
(textArea.value.match(/[(){}[\]]/g) || []).forEach(bracket => {
|
||||
counts[bracket] = (counts[bracket] || 0) + 1;
|
||||
});
|
||||
var errors = [];
|
||||
function checkBrackets(textArea, counterElem) {
|
||||
const pairs = [
|
||||
['(', ')', 'round brackets'],
|
||||
['[', ']', 'square brackets'],
|
||||
['{', '}', 'curly brackets']
|
||||
];
|
||||
|
||||
function checkPair(open, close, kind) {
|
||||
if (counts[open] !== counts[close]) {
|
||||
errors.push(
|
||||
`${open}...${close} - Detected ${counts[open] || 0} opening and ${counts[close] || 0} closing ${kind}.`
|
||||
);
|
||||
const counts = {};
|
||||
const errors = new Set();
|
||||
let i = 0;
|
||||
|
||||
while (i < textArea.value.length) {
|
||||
let char = textArea.value[i];
|
||||
let escaped = false;
|
||||
while (char === '\\' && i + 1 < textArea.value.length) {
|
||||
escaped = !escaped;
|
||||
i++;
|
||||
char = textArea.value[i];
|
||||
}
|
||||
|
||||
if (escaped) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const [open, close, label] of pairs) {
|
||||
if (char === open) {
|
||||
counts[label] = (counts[label] || 0) + 1;
|
||||
} else if (char === close) {
|
||||
counts[label] = (counts[label] || 0) - 1;
|
||||
if (counts[label] < 0) {
|
||||
errors.add(`Incorrect order of ${label}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
for (const [open, close, label] of pairs) {
|
||||
if (counts[label] == undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (counts[label] > 0) {
|
||||
errors.add(`${open} ... ${close} - Detected ${counts[label]} more opening than closing ${label}.`);
|
||||
} else if (counts[label] < 0) {
|
||||
errors.add(`${open} ... ${close} - Detected ${-counts[label]} more closing than opening ${label}.`);
|
||||
}
|
||||
}
|
||||
|
||||
checkPair('(', ')', 'round brackets');
|
||||
checkPair('[', ']', 'square brackets');
|
||||
checkPair('{', '}', 'curly brackets');
|
||||
counterElt.title = errors.join('\n');
|
||||
counterElt.classList.toggle('error', errors.length !== 0);
|
||||
counterElem.title = [...errors].join('\n');
|
||||
counterElem.classList.toggle('error', errors.size !== 0);
|
||||
}
|
||||
|
||||
function setupBracketChecking(id_prompt, id_counter) {
|
||||
var textarea = gradioApp().querySelector("#" + id_prompt + " > label > textarea");
|
||||
var counter = gradioApp().getElementById(id_counter);
|
||||
const textarea = gradioApp().querySelector(`#${id_prompt} > label > textarea`);
|
||||
const counter = gradioApp().getElementById(id_counter);
|
||||
|
||||
if (textarea && counter) {
|
||||
textarea.addEventListener("input", () => checkBrackets(textarea, counter));
|
||||
onEdit(`${id_prompt}_BracketChecking`, textarea, 400, () => checkBrackets(textarea, counter));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +249,8 @@ class Api:
|
||||
self.add_api_route("/sdapi/v1/server-kill", self.kill_webui, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/server-restart", self.restart_webui, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/server-stop", self.stop_webui, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/server-reload-ui", self.reload_webui, methods=["POST"])
|
||||
self.add_api_route("/sdapi/v1/server-reload-script-bodies", self.reload_script_bodies, methods=["POST"])
|
||||
|
||||
self.default_script_arg_txt2img = []
|
||||
self.default_script_arg_img2img = []
|
||||
@@ -926,3 +928,10 @@ class Api:
|
||||
shared.state.server_command = "stop"
|
||||
return Response("Stopping.")
|
||||
|
||||
def reload_webui(self):
|
||||
shared.state.request_restart()
|
||||
return Response("Reloading.")
|
||||
|
||||
def reload_script_bodies(self):
|
||||
scripts.reload_script_body_only()
|
||||
return Response("Reload script bodies.")
|
||||
|
||||
@@ -33,12 +33,12 @@ categories.register_category("training", "Training")
|
||||
|
||||
options_templates.update(options_section(('saving-images', "Saving images/grids", "saving"), {
|
||||
"samples_save": OptionInfo(True, "Always save all generated images"),
|
||||
"samples_format": OptionInfo('png', 'File format for images'),
|
||||
"samples_format": OptionInfo('png', 'File format for images', ui_components.DropdownEditable, {"choices": ("png", "jpg", "jpeg", "webp", "avif")}).info("manual input of <a href='https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html' target='_blank'>other formats</a> is possible, but compatibility is not guaranteed"),
|
||||
"samples_filename_pattern": OptionInfo("", "Images filename pattern", component_args=hide_dirs).link("wiki", "https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Images-Filename-Name-and-Subdirectory"),
|
||||
"save_images_add_number": OptionInfo(True, "Add number to filename when saving", component_args=hide_dirs),
|
||||
"save_images_replace_action": OptionInfo("Replace", "Saving the image to an existing file", gr.Radio, {"choices": ["Replace", "Add number suffix"], **hide_dirs}),
|
||||
"grid_save": OptionInfo(True, "Always save all generated image grids"),
|
||||
"grid_format": OptionInfo('png', 'File format for grids'),
|
||||
"grid_format": OptionInfo('png', 'File format for grids', ui_components.DropdownEditable, {"choices": ("png", "jpg", "jpeg", "webp", "avif")}).info("manual input of <a href='https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html' target='_blank'>other formats</a> is possible, but compatibility is not guaranteed"),
|
||||
"grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"),
|
||||
"grid_only_if_multiple": OptionInfo(True, "Do not save grids consisting of one picture"),
|
||||
"grid_prevent_empty_spots": OptionInfo(False, "Prevent empty spots in grid (when set to autodetect)"),
|
||||
@@ -128,6 +128,7 @@ options_templates.update(options_section(('system', "System", "system"), {
|
||||
"disable_mmap_load_safetensors": OptionInfo(False, "Disable memmapping for loading .safetensors files.").info("fixes very slow loading speed in some cases"),
|
||||
"hide_ldm_prints": OptionInfo(True, "Prevent Stability-AI's ldm/sgm modules from printing noise to console."),
|
||||
"dump_stacks_on_signal": OptionInfo(False, "Print stack traces before exiting the program with ctrl+c."),
|
||||
"concurrent_git_fetch_limit": OptionInfo(16, "Number of simultaneous extension update checks ", gr.Slider, {"step": 1, "minimum": 1, "maximum": 100}).info("reduce extension update check time"),
|
||||
}))
|
||||
|
||||
options_templates.update(options_section(('profiler', "Profiler", "system"), {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
@@ -106,18 +107,24 @@ def check_updates(id_task, disable_list):
|
||||
exts = [ext for ext in extensions.extensions if ext.remote is not None and ext.name not in disabled]
|
||||
shared.state.job_count = len(exts)
|
||||
|
||||
for ext in exts:
|
||||
shared.state.textinfo = ext.name
|
||||
lock = threading.Lock()
|
||||
|
||||
def _check_update(ext):
|
||||
try:
|
||||
ext.check_updates()
|
||||
except FileNotFoundError as e:
|
||||
if 'FETCH_HEAD' not in str(e):
|
||||
raise
|
||||
except Exception:
|
||||
errors.report(f"Error checking updates for {ext.name}", exc_info=True)
|
||||
with lock:
|
||||
errors.report(f"Error checking updates for {ext.name}", exc_info=True)
|
||||
with lock:
|
||||
shared.state.textinfo = ext.name
|
||||
shared.state.nextjob()
|
||||
|
||||
shared.state.nextjob()
|
||||
with ThreadPoolExecutor(max_workers=max(1, int(shared.opts.concurrent_git_fetch_limit))) as executor:
|
||||
for ext in exts:
|
||||
executor.submit(_check_update, ext)
|
||||
|
||||
return extension_table(), ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user