Compare commits

..

11 Commits

Author SHA1 Message Date
w-e-w 661322707f set min brush size to 1 2024-11-23 06:59:28 +09:00
w-e-w 1b9dea7d90 apply brush size limit early 2024-11-22 11:30:19 +09:00
w-e-w 7cf80a70d9 allow brush size up to 1/2 diagonal image 2024-11-22 11:00:45 +09:00
w-e-w 2eef345743 reduce complexity
remove the overly complex option of radius / area brush size change mode
2024-11-22 11:00:45 +09:00
w-e-w 3a1497aaf1 eslint 2024-11-20 06:09:01 +09:00
w-e-w 96eaca6153 make "Adjust brush size by area" Default behavior 2024-11-20 05:56:10 +09:00
w-e-w dd237f2541 make Undo Clear hotkey disableable 2024-11-20 05:40:01 +09:00
w-e-w c9f8953200 Canvas: Clear hotkey 2024-11-20 05:31:27 +09:00
w-e-w e009f586a2 limit the minimum delta to 1 2024-11-20 05:17:22 +09:00
w-e-w 356339eff2 Canvas: Undo hotkey 2024-11-20 04:46:26 +09:00
w-e-w 4e808fbef4 Canvas: Adjust brush size by area 2024-11-20 04:46:10 +09:00
6 changed files with 75 additions and 91 deletions
@@ -226,6 +226,8 @@ onUiLoaded(async() => {
canvas_show_tooltip: true, canvas_show_tooltip: true,
canvas_auto_expand: true, canvas_auto_expand: true,
canvas_blur_prompt: false, canvas_blur_prompt: false,
canvas_hotkey_undo: "KeyZ",
canvas_hotkey_clear: "KeyC",
}; };
const functionMap = { const functionMap = {
@@ -236,7 +238,9 @@ onUiLoaded(async() => {
"Moving canvas": "canvas_hotkey_move", "Moving canvas": "canvas_hotkey_move",
"Fullscreen": "canvas_hotkey_fullscreen", "Fullscreen": "canvas_hotkey_fullscreen",
"Reset Zoom": "canvas_hotkey_reset", "Reset Zoom": "canvas_hotkey_reset",
"Overlap": "canvas_hotkey_overlap" "Overlap": "canvas_hotkey_overlap",
"Undo": "canvas_hotkey_undo",
"Clear": "canvas_hotkey_clear"
}; };
// Loading the configuration from opts // Loading the configuration from opts
@@ -321,6 +325,8 @@ onUiLoaded(async() => {
action: "Adjust brush size", action: "Adjust brush size",
keySuffix: " + wheel" keySuffix: " + wheel"
}, },
{configKey: "canvas_hotkey_undo", action: "Undo brush stroke"},
{configKey: "canvas_hotkey_clear", action: "Clear canvas"},
{configKey: "canvas_hotkey_reset", action: "Reset zoom"}, {configKey: "canvas_hotkey_reset", action: "Reset zoom"},
{ {
configKey: "canvas_hotkey_fullscreen", configKey: "canvas_hotkey_fullscreen",
@@ -464,22 +470,45 @@ onUiLoaded(async() => {
gradioApp().querySelector( gradioApp().querySelector(
`${elemId} button[aria-label="Use brush"]` `${elemId} button[aria-label="Use brush"]`
); );
if (input) { if (input) {
input.click(); input.click();
if (!withoutValue) { if (!withoutValue) {
const maxValue = const maxValue = parseFloat(input.getAttribute("max")) || 100;
parseFloat(input.getAttribute("max")) || 100; const minValue = parseFloat(input.getAttribute("min")) || 1;
const changeAmount = maxValue * (percentage / 100); // allow brush size up to 1/2 diagonal of the image, beyond gradio's arbitrary limit
const newValue = const canvasImg = gradioApp().querySelector(`${elemId} img`);
parseFloat(input.value) + if (canvasImg) {
(deltaY > 0 ? -changeAmount : changeAmount); const maxDiameter = Math.sqrt(canvasImg.naturalWidth ** 2 + canvasImg.naturalHeight ** 2) / 2;
input.value = Math.min(Math.max(newValue, 0), maxValue); if (maxDiameter > maxValue) {
input.setAttribute("max", maxDiameter);
}
if (minValue > 1) {
input.setAttribute("min", '1');
}
}
const brush_factor = deltaY > 0 ? 1 - opts.canvas_hotkey_brush_factor : 1 + opts.canvas_hotkey_brush_factor;
const currentRadius = parseFloat(input.value);
let delta = Math.sqrt(currentRadius ** 2 * brush_factor) - currentRadius;
// minimum brush size step of 1
if (Math.abs(delta) < 1) {
delta = deltaY > 0 ? -1 : 1;
}
const newValue = currentRadius + delta;
input.value = Math.max(newValue, 1);
input.dispatchEvent(new Event("change")); input.dispatchEvent(new Event("change"));
} }
} }
} }
// Undo the last brush stroke by clicking the undo button
function undoBrushStroke() {
gradioApp().querySelector(`${elemId} button[aria-label='Undo']`).click();
}
function clearCanvas() {
gradioApp().querySelector(`${elemId} button[aria-label='Clear']`).click();
}
// Reset zoom when uploading a new image // Reset zoom when uploading a new image
const fileInput = gradioApp().querySelector( const fileInput = gradioApp().querySelector(
`${elemId} input[type="file"][accept="image/*"].svelte-116rqfv` `${elemId} input[type="file"][accept="image/*"].svelte-116rqfv`
@@ -699,7 +728,9 @@ onUiLoaded(async() => {
[hotkeysConfig.canvas_hotkey_overlap]: toggleOverlap, [hotkeysConfig.canvas_hotkey_overlap]: toggleOverlap,
[hotkeysConfig.canvas_hotkey_fullscreen]: fitToScreen, [hotkeysConfig.canvas_hotkey_fullscreen]: fitToScreen,
[hotkeysConfig.canvas_hotkey_shrink_brush]: () => adjustBrushSize(elemId, 10), [hotkeysConfig.canvas_hotkey_shrink_brush]: () => adjustBrushSize(elemId, 10),
[hotkeysConfig.canvas_hotkey_grow_brush]: () => adjustBrushSize(elemId, -10) [hotkeysConfig.canvas_hotkey_grow_brush]: () => adjustBrushSize(elemId, -10),
[hotkeysConfig.canvas_hotkey_undo]: undoBrushStroke,
[hotkeysConfig.canvas_hotkey_clear]: clearCanvas
}; };
const action = hotkeyActions[event.code]; const action = hotkeyActions[event.code];
@@ -7,11 +7,14 @@ shared.options_templates.update(shared.options_section(('canvas_hotkey', "Canvas
"canvas_hotkey_shrink_brush": shared.OptionInfo("Q", "Shrink the brush size"), "canvas_hotkey_shrink_brush": shared.OptionInfo("Q", "Shrink the brush size"),
"canvas_hotkey_grow_brush": shared.OptionInfo("W", "Enlarge the brush size"), "canvas_hotkey_grow_brush": shared.OptionInfo("W", "Enlarge the brush size"),
"canvas_hotkey_move": shared.OptionInfo("F", "Moving the canvas").info("To work correctly in firefox, turn off 'Automatically search the page text when typing' in the browser settings"), "canvas_hotkey_move": shared.OptionInfo("F", "Moving the canvas").info("To work correctly in firefox, turn off 'Automatically search the page text when typing' in the browser settings"),
"canvas_hotkey_undo": shared.OptionInfo("Z", "Undo brush stroke"),
"canvas_hotkey_clear": shared.OptionInfo("C", "Clear canvas"),
"canvas_hotkey_fullscreen": shared.OptionInfo("S", "Fullscreen Mode, maximizes the picture so that it fits into the screen and stretches it to its full width "), "canvas_hotkey_fullscreen": shared.OptionInfo("S", "Fullscreen Mode, maximizes the picture so that it fits into the screen and stretches it to its full width "),
"canvas_hotkey_reset": shared.OptionInfo("R", "Reset zoom and canvas position"), "canvas_hotkey_reset": shared.OptionInfo("R", "Reset zoom and canvas position"),
"canvas_hotkey_overlap": shared.OptionInfo("O", "Toggle overlap").info("Technical button, needed for testing"), "canvas_hotkey_overlap": shared.OptionInfo("O", "Toggle overlap").info("Technical button, needed for testing"),
"canvas_show_tooltip": shared.OptionInfo(True, "Enable tooltip on the canvas"), "canvas_show_tooltip": shared.OptionInfo(True, "Enable tooltip on the canvas"),
"canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"), "canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"),
"canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"), "canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"),
"canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom","Adjust brush size","Hotkey enlarge brush","Hotkey shrink brush","Moving canvas","Fullscreen","Reset Zoom","Overlap"]}), "canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom", "Adjust brush size", "Hotkey enlarge brush", "Hotkey shrink brush", "Undo", "Clear", "Moving canvas", "Fullscreen", "Reset Zoom", "Overlap"]}),
"canvas_hotkey_brush_factor": shared.OptionInfo(0.1, "Brush size change rate", gr.Slider, {"minimum": 0, "maximum": 1, "step": 0.01}).info('controls how much the brush size is changed when using hotkeys or scroll wheel'),
})) }))
@@ -1,69 +1,36 @@
// Stable Diffusion WebUI - Bracket Checker // Stable Diffusion WebUI - Bracket checker
// By @Bwin4L, @akx, @w-e-w, @Haoming02 // By Hingashi no Florin/Bwin4L & @akx
// Counts open and closed brackets (round, square, curly) in the prompt and negative prompt text boxes in the txt2img and img2img tabs. // 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, counterElem) { function checkBrackets(textArea, counterElt) {
const pairs = [ var counts = {};
['(', ')', 'round brackets'], (textArea.value.match(/[(){}[\]]/g) || []).forEach(bracket => {
['[', ']', 'square brackets'], counts[bracket] = (counts[bracket] || 0) + 1;
['{', '}', 'curly brackets'] });
]; var errors = [];
const counts = {}; function checkPair(open, close, kind) {
const errors = new Set(); if (counts[open] !== counts[close]) {
let i = 0; errors.push(
`${open}...${close} - Detected ${counts[open] || 0} opening and ${counts[close] || 0} closing ${kind}.`
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}.`);
} }
} }
counterElem.title = [...errors].join('\n'); checkPair('(', ')', 'round brackets');
counterElem.classList.toggle('error', errors.size !== 0); checkPair('[', ']', 'square brackets');
checkPair('{', '}', 'curly brackets');
counterElt.title = errors.join('\n');
counterElt.classList.toggle('error', errors.length !== 0);
} }
function setupBracketChecking(id_prompt, id_counter) { function setupBracketChecking(id_prompt, id_counter) {
const textarea = gradioApp().querySelector(`#${id_prompt} > label > textarea`); var textarea = gradioApp().querySelector("#" + id_prompt + " > label > textarea");
const counter = gradioApp().getElementById(id_counter); var counter = gradioApp().getElementById(id_counter);
if (textarea && counter) { if (textarea && counter) {
onEdit(`${id_prompt}_BracketChecking`, textarea, 400, () => checkBrackets(textarea, counter)); textarea.addEventListener("input", () => checkBrackets(textarea, counter));
} }
} }
-9
View File
@@ -249,8 +249,6 @@ class Api:
self.add_api_route("/sdapi/v1/server-kill", self.kill_webui, methods=["POST"]) 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-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-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_txt2img = []
self.default_script_arg_img2img = [] self.default_script_arg_img2img = []
@@ -928,10 +926,3 @@ class Api:
shared.state.server_command = "stop" shared.state.server_command = "stop"
return Response("Stopping.") 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.")
+2 -3
View File
@@ -33,12 +33,12 @@ categories.register_category("training", "Training")
options_templates.update(options_section(('saving-images', "Saving images/grids", "saving"), { options_templates.update(options_section(('saving-images', "Saving images/grids", "saving"), {
"samples_save": OptionInfo(True, "Always save all generated images"), "samples_save": OptionInfo(True, "Always save all generated 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_format": OptionInfo('png', 'File format for images'),
"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"), "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_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}), "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_save": OptionInfo(True, "Always save all generated image 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_format": OptionInfo('png', 'File format for grids'),
"grid_extended_filename": OptionInfo(False, "Add extended info (seed, prompt) to filename when saving grid"), "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_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)"), "grid_prevent_empty_spots": OptionInfo(False, "Prevent empty spots in grid (when set to autodetect)"),
@@ -128,7 +128,6 @@ 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"), "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."), "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."), "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"), { options_templates.update(options_section(('profiler', "Profiler", "system"), {
+3 -10
View File
@@ -1,6 +1,5 @@
import json import json
import os import os
from concurrent.futures import ThreadPoolExecutor
import threading import threading
import time import time
from datetime import datetime, timezone from datetime import datetime, timezone
@@ -107,24 +106,18 @@ 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] 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) shared.state.job_count = len(exts)
lock = threading.Lock() for ext in exts:
shared.state.textinfo = ext.name
def _check_update(ext):
try: try:
ext.check_updates() ext.check_updates()
except FileNotFoundError as e: except FileNotFoundError as e:
if 'FETCH_HEAD' not in str(e): if 'FETCH_HEAD' not in str(e):
raise raise
except Exception: except Exception:
with lock:
errors.report(f"Error checking updates for {ext.name}", exc_info=True) errors.report(f"Error checking updates for {ext.name}", exc_info=True)
with lock:
shared.state.textinfo = ext.name
shared.state.nextjob()
with ThreadPoolExecutor(max_workers=max(1, int(shared.opts.concurrent_git_fetch_limit))) as executor: shared.state.nextjob()
for ext in exts:
executor.submit(_check_update, ext)
return extension_table(), "" return extension_table(), ""