Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc34c0041c | |||
| fc54833505 | |||
| 078d04ef23 | |||
| 1a773bf2c8 | |||
| f113474a6e | |||
| 6577e063d1 | |||
| 7953c570d9 | |||
| f25c3fc9cb | |||
| fc0952abb9 | |||
| b414c62ce4 | |||
| 04903af798 | |||
| e8c3b1f2a0 | |||
| 8bf30e3c42 | |||
| fbc51fa210 | |||
| 7025a2c4a5 | |||
| 0120768f63 | |||
| b425b97ad6 | |||
| 539ea3982d | |||
| 65bd61e87c | |||
| 95686227bd | |||
| df74c3c638 |
@@ -22,7 +22,7 @@ jobs:
|
||||
- name: Install Ruff
|
||||
run: pip install ruff==0.3.3
|
||||
- name: Run Ruff
|
||||
run: ruff .
|
||||
run: ruff check .
|
||||
lint-js:
|
||||
name: eslint
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -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, counterElem) {
|
||||
const pairs = [
|
||||
['(', ')', 'round brackets'],
|
||||
['[', ']', 'square brackets'],
|
||||
['{', '}', 'curly brackets']
|
||||
];
|
||||
|
||||
function checkBrackets(textArea, counterElt) {
|
||||
const counts = {};
|
||||
textArea.value.matchAll(/(?<!\\)(?:\\\\)*?([(){}[\]])/g).forEach(bracket => {
|
||||
counts[bracket[1]] = (counts[bracket[1]] || 0) + 1;
|
||||
});
|
||||
const errors = [];
|
||||
const errors = new Set();
|
||||
let i = 0;
|
||||
|
||||
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}.`
|
||||
);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,3 +69,39 @@ onOptionsChanged(function() {
|
||||
});
|
||||
});
|
||||
|
||||
function downloadSysinfo() {
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
const now = new Date();
|
||||
const YY = now.getFullYear();
|
||||
const MM = pad(now.getMonth() + 1);
|
||||
const DD = pad(now.getDate());
|
||||
const HH = pad(now.getHours());
|
||||
const mm = pad(now.getMinutes());
|
||||
const link = document.createElement('a');
|
||||
link.download = `sysinfo-${YY}-${MM}-${DD}-${HH}-${mm}.json`;
|
||||
const sysinfo_textbox = gradioApp().querySelector('#internal-sysinfo-textbox textarea');
|
||||
const content = sysinfo_textbox.value;
|
||||
if (content.startsWith('file=')) {
|
||||
link.href = content;
|
||||
} else {
|
||||
const blob = new Blob([content], {type: 'application/json'});
|
||||
link.href = URL.createObjectURL(blob);
|
||||
}
|
||||
link.click();
|
||||
sysinfo_textbox.value = '';
|
||||
updateInput(sysinfo_textbox);
|
||||
}
|
||||
|
||||
function openTabSysinfo() {
|
||||
const sysinfo_textbox = gradioApp().querySelector('#internal-sysinfo-textbox textarea');
|
||||
const content = sysinfo_textbox.value;
|
||||
if (content.startsWith('file=')) {
|
||||
window.open(content, '_blank');
|
||||
} else {
|
||||
const blob = new Blob([content], {type: 'application/json'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
sysinfo_textbox.value = '';
|
||||
updateInput(sysinfo_textbox);
|
||||
}
|
||||
|
||||
+4
-1
@@ -17,7 +17,7 @@ from fastapi.encoders import jsonable_encoder
|
||||
from secrets import compare_digest
|
||||
|
||||
import modules.shared as shared
|
||||
from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, postprocessing, errors, restart, shared_items, script_callbacks, infotext_utils, sd_models, sd_schedulers
|
||||
from modules import sd_samplers, deepbooru, sd_hijack, images, scripts, ui, postprocessing, errors, restart, shared_items, script_callbacks, infotext_utils, sd_models, sd_schedulers, sysinfo
|
||||
from modules.api import models
|
||||
from modules.shared import opts
|
||||
from modules.processing import StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img, process_images
|
||||
@@ -33,6 +33,7 @@ import piexif.helper
|
||||
from contextlib import closing
|
||||
from modules.progress import create_task_id, add_task_to_queue, start_task, finish_task, current_task
|
||||
|
||||
|
||||
def script_name_to_index(name, scripts):
|
||||
try:
|
||||
return [script.title().lower() for script in scripts].index(name.lower())
|
||||
@@ -244,6 +245,8 @@ class Api:
|
||||
self.add_api_route("/sdapi/v1/scripts", self.get_scripts_list, methods=["GET"], response_model=models.ScriptsList)
|
||||
self.add_api_route("/sdapi/v1/script-info", self.get_script_info, methods=["GET"], response_model=list[models.ScriptInfo])
|
||||
self.add_api_route("/sdapi/v1/extensions", self.get_extensions_list, methods=["GET"], response_model=list[models.ExtensionItem])
|
||||
self.add_api_route("/internal/sysinfo", sysinfo.download_sysinfo, methods=["GET"])
|
||||
self.add_api_route("/internal/sysinfo-download", lambda: sysinfo.download_sysinfo(attachment=True), methods=["GET"])
|
||||
|
||||
if shared.cmd_opts.api_server_stop:
|
||||
self.add_api_route("/sdapi/v1/server-kill", self.kill_webui, methods=["POST"])
|
||||
|
||||
@@ -43,9 +43,7 @@ def check_python_version():
|
||||
supported_minors = [7, 8, 9, 10, 11]
|
||||
|
||||
if not (major == 3 and minor in supported_minors):
|
||||
import modules.errors
|
||||
|
||||
modules.errors.print_error_explanation(f"""
|
||||
errors.print_error_explanation(f"""
|
||||
INCOMPATIBLE PYTHON VERSION
|
||||
|
||||
This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}.
|
||||
|
||||
@@ -125,7 +125,7 @@ def ui_reorder_categories():
|
||||
|
||||
def callbacks_order_settings():
|
||||
options = {
|
||||
"sd_vae_explanation": OptionHTML("""
|
||||
"callbacks_order_explanation": OptionHTML("""
|
||||
For categories below, callbacks added to dropdowns happen before others, in order listed.
|
||||
"""),
|
||||
|
||||
|
||||
@@ -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"), {
|
||||
|
||||
@@ -213,3 +213,13 @@ def get_config():
|
||||
return json.load(f)
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
|
||||
def download_sysinfo(attachment=False):
|
||||
from fastapi.responses import PlainTextResponse
|
||||
from datetime import datetime
|
||||
|
||||
text = get()
|
||||
filename = f"sysinfo-{datetime.utcnow().strftime('%Y-%m-%d-%H-%M')}.json"
|
||||
|
||||
return PlainTextResponse(text, headers={'Content-Disposition': f'{"attachment" if attachment else "inline"}; filename="{filename}"'})
|
||||
|
||||
+2
-14
@@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
@@ -10,10 +9,10 @@ import gradio as gr
|
||||
import gradio.utils
|
||||
import numpy as np
|
||||
from PIL import Image, PngImagePlugin # noqa: F401
|
||||
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call, wrap_gradio_call_no_job # noqa: F401
|
||||
from modules.call_queue import wrap_gradio_gpu_call, wrap_queued_call, wrap_gradio_call, wrap_gradio_call_no_job # noqa: F401
|
||||
|
||||
from modules import gradio_extensons, sd_schedulers # noqa: F401
|
||||
from modules import sd_hijack, sd_models, script_callbacks, ui_extensions, deepbooru, extra_networks, ui_common, ui_postprocessing, progress, ui_loadsave, shared_items, ui_settings, timer, sysinfo, ui_checkpoint_merger, scripts, sd_samplers, processing, ui_extra_networks, ui_toprow, launch_utils
|
||||
from modules import sd_hijack, sd_models, script_callbacks, ui_extensions, deepbooru, extra_networks, ui_common, ui_postprocessing, progress, ui_loadsave, shared_items, ui_settings, timer, ui_checkpoint_merger, scripts, sd_samplers, processing, ui_extra_networks, ui_toprow, launch_utils
|
||||
from modules.ui_components import FormRow, FormGroup, ToolButton, FormHTML, InputAccordion, ResizeHandleRow
|
||||
from modules.paths import script_path
|
||||
from modules.ui_common import create_refresh_button
|
||||
@@ -1223,16 +1222,5 @@ def setup_ui_api(app):
|
||||
|
||||
app.add_api_route("/internal/profile-startup", lambda: timer.startup_record, methods=["GET"])
|
||||
|
||||
def download_sysinfo(attachment=False):
|
||||
from fastapi.responses import PlainTextResponse
|
||||
|
||||
text = sysinfo.get()
|
||||
filename = f"sysinfo-{datetime.datetime.utcnow().strftime('%Y-%m-%d-%H-%M')}.json"
|
||||
|
||||
return PlainTextResponse(text, headers={'Content-Disposition': f'{"attachment" if attachment else "inline"}; filename="{filename}"'})
|
||||
|
||||
app.add_api_route("/internal/sysinfo", download_sysinfo, methods=["GET"])
|
||||
app.add_api_route("/internal/sysinfo-download", lambda: download_sysinfo(attachment=True), methods=["GET"])
|
||||
|
||||
import fastapi.staticfiles
|
||||
app.mount("/webui-assets", fastapi.staticfiles.StaticFiles(directory=launch_utils.repo_dir('stable-diffusion-webui-assets')), name="webui-assets")
|
||||
|
||||
@@ -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(), ""
|
||||
|
||||
|
||||
+25
-3
@@ -1,12 +1,13 @@
|
||||
import gradio as gr
|
||||
|
||||
from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items
|
||||
from modules import ui_common, shared, script_callbacks, scripts, sd_models, sysinfo, timer, shared_items, paths_internal, util
|
||||
from modules.call_queue import wrap_gradio_call_no_job
|
||||
from modules.options import options_section
|
||||
from modules.shared import opts
|
||||
from modules.ui_components import FormRow
|
||||
from modules.ui_gradio_extensions import reload_javascript
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_value_for_setting(key):
|
||||
@@ -170,7 +171,28 @@ class UiSettings:
|
||||
loadsave.create_ui()
|
||||
|
||||
with gr.TabItem("Sysinfo", id="sysinfo", elem_id="settings_tab_sysinfo"):
|
||||
gr.HTML('<a href="./internal/sysinfo-download" class="sysinfo_big_link" download>Download system info</a><br /><a href="./internal/sysinfo" target="_blank">(or open as text in a new page)</a>', elem_id="sysinfo_download")
|
||||
download_sysinfo = gr.Button(value='Download system info', elem_id="internal-download-sysinfo", visible=False)
|
||||
open_sysinfo = gr.Button(value='Open as text in a new page', elem_id="internal-open-sysinfo", visible=False)
|
||||
sysinfo_html = gr.HTML('''<a class="sysinfo_big_link" onclick="gradioApp().getElementById('internal-download-sysinfo').click();">Download system info</a><br/><a onclick="gradioApp().getElementById('internal-open-sysinfo').click();">(or open as text in a new page)</a>''', elem_id="sysinfo_download")
|
||||
sysinfo_textbox = gr.Textbox(label='Sysinfo textarea', elem_id="internal-sysinfo-textbox", visible=False)
|
||||
|
||||
def create_sysinfo():
|
||||
sysinfo_str = sysinfo.get()
|
||||
if len(sysinfo_utf8 := sysinfo_str.encode('utf8')) > 2 ** 20: # 1MB
|
||||
sysinfo_path = Path(paths_internal.script_path) / 'tmp' / 'sysinfo.json'
|
||||
sysinfo_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
sysinfo_path.write_bytes(sysinfo_utf8)
|
||||
return gr.update(), gr.update(value=f'file={util.truncate_path(sysinfo_path)}')
|
||||
return gr.update(), gr.update(value=sysinfo_str)
|
||||
|
||||
download_sysinfo.click(
|
||||
fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success(
|
||||
fn=None, _js='downloadSysinfo'
|
||||
)
|
||||
open_sysinfo.click(
|
||||
fn=create_sysinfo, outputs=[sysinfo_html, sysinfo_textbox], show_progress=True).success(
|
||||
fn=None, _js='openTabSysinfo'
|
||||
)
|
||||
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
@@ -313,7 +335,7 @@ class UiSettings:
|
||||
|
||||
for method in methods:
|
||||
method(
|
||||
fn=lambda value, k=k: self.run_settings_single(value, key=k),
|
||||
fn=lambda value, key=k: self.run_settings_single(value, key=key),
|
||||
inputs=[component],
|
||||
outputs=[component, self.text_settings],
|
||||
show_progress=info.refresh is not None,
|
||||
|
||||
@@ -29,6 +29,10 @@ class ScriptPostprocessingCodeFormer(scripts_postprocessing.ScriptPostprocessing
|
||||
res = Image.fromarray(restored_img)
|
||||
|
||||
if codeformer_visibility < 1.0:
|
||||
if pp.image.size != res.size:
|
||||
res = res.resize(pp.image.size)
|
||||
if pp.image.mode != res.mode:
|
||||
res = res.convert(pp.image.mode)
|
||||
res = Image.blend(pp.image, res, codeformer_visibility)
|
||||
|
||||
pp.image = res
|
||||
|
||||
@@ -26,6 +26,10 @@ class ScriptPostprocessingGfpGan(scripts_postprocessing.ScriptPostprocessing):
|
||||
res = Image.fromarray(restored_img)
|
||||
|
||||
if gfpgan_visibility < 1.0:
|
||||
if pp.image.size != res.size:
|
||||
res = res.resize(pp.image.size)
|
||||
if pp.image.mode != res.mode:
|
||||
res = res.convert(pp.image.mode)
|
||||
res = Image.blend(pp.image, res, gfpgan_visibility)
|
||||
|
||||
pp.image = res
|
||||
|
||||
Reference in New Issue
Block a user