enable swtiching built-in themes on-the-fly

This commit is contained in:
Vladimir Mandic
2024-01-10 11:58:09 -05:00
parent 204853afea
commit d73001f1a9
14 changed files with 43 additions and 18 deletions
+2
View File
@@ -18,6 +18,7 @@
"max-len": [1, 275, 3],
"camelcase":"off",
"default-case":"off",
"no-await-in-loop":"off",
"no-bitwise":"off",
"no-confusing-arrow":"off",
"no-console":"off",
@@ -72,6 +73,7 @@
"updateInput": "readonly",
"toggleCompact": "readonly",
"setFontSize": "readonly",
"setTheme": "readonly",
// settings.js
"registerDragDrop": "readonly",
//extraNetworks.js
+7 -3
View File
@@ -1,6 +1,6 @@
# Change Log for SD.Next
## Update for 2023-01-09
## Update for 2023-01-10
Following-up on a major release, here is a lot more functionality in new Control module and FaceID & IPAdapter modules
Plus welcome additions to UI accessibility and flexibility of deployment
@@ -57,10 +57,12 @@ And it also includes fixes for all reported issues so far
- enable use via api, thanks @trojaner
- **Improvements**
- **ui**
- globally configurable font size
- globally configurable **font size**
will dynamically rescale ui depending on settings -> user interface
- built-in **themes** can be changed on-the-fly
this does not work with gradio-default themes as css is created by gradio itself
- modularized blip/booru interrogate
now appears as toolbuttons on image/gallery output
now appears as toolbuttons on image/gallery output
- **server startup**: performance
- reduced module imports
ldm support is now only loaded when running in backend=original
@@ -125,12 +127,14 @@ And it also includes fixes for all reported issues so far
- img2img: sampler selection offset
- api: return current image in progress api if requested
- api: sanitize response object
- api: cleanup error logging
- sampler: guard against invalid sampler index
- config: reset default cfg scale to 6.0
- processing: correct display metadata
- live preview: fix when using `bfloat16`
- upscale: fix ldsr
- cli: fix cmd args parsing
- global crlf->lf switch
## Update for 2023-12-29
+6 -3
View File
@@ -9,12 +9,13 @@ const monitoredOpts = [
const AppyOpts = [
{ compact_view: (val) => toggleCompact(val) },
{ gradio_theme: (val, old) => setTheme(val, old) },
{ font_size: (val) => setFontSize(val) },
];
async function updateOpts(json_string) {
const settings_data = JSON.parse(json_string);
opts = settings_data.values;
const new_opts = settings_data.values;
opts_metadata = settings_data.metadata;
for (const op of monitoredOpts) {
@@ -22,16 +23,18 @@ async function updateOpts(json_string) {
const callback = op[key];
if (opts[key] && opts[key] !== settings_data.values[key]) {
log('updateOpts', key, opts[key], settings_data.values[key]);
if (callback) callback(opts[key]);
if (callback) callback(new_opts[key], opts[key]);
}
}
for (const op of AppyOpts) {
const key = Object.keys(op)[0];
const callback = op[key];
if (callback) callback(settings_data.values[key]);
if (callback) callback(new_opts[key], opts[key]);
}
opts = new_opts;
Object.entries(opts_metadata).forEach(([opt, meta]) => {
if (!opts_tabs[meta.tab_name]) opts_tabs[meta.tab_name] = {};
if (!opts_tabs[meta.tab_name].unsaved_keys) opts_tabs[meta.tab_name].unsaved_keys = new Set();
+15 -1
View File
@@ -7,6 +7,7 @@ let img2img_textarea;
const wait_time = 800;
const token_timeouts = {};
let uiLoaded = false;
window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around
function rememberGallerySelection(name) {
// dummy
@@ -64,7 +65,20 @@ function extract_image_from_gallery(gallery) {
return [gallery[index]];
}
window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around
async function setTheme(val, old) {
if (!old) return;
const links = Array.from(document.getElementsByTagName('link')).filter((l) => l.href.includes(old));
for (const link of links) {
const href = link.href.replace(old, val);
const res = await fetch(href);
if (res.ok) {
log('setTheme:', old, val);
link.href = link.href.replace(old, val);
} else {
log('setTheme: CSS not found', val);
}
}
}
function setFontSize(val) {
const size = val || opts.font_size;
-1
View File
@@ -155,7 +155,6 @@ class Processor():
if self.processor_id != processor_id:
self.reset()
self.config(processor_id)
print('HERE', self.processor_id, processor_id, self.load_config)
cls = config[processor_id]['class']
log.debug(f'Control Processor loading: id="{processor_id}" class={cls.__name__}')
debug(f'Control Processor config={self.load_config}')
+6 -3
View File
@@ -65,16 +65,19 @@ def setup_middleware(app: FastAPI, cmd_opts):
def handle_exception(req: Request, e: Exception):
err = {
"error": type(e).__name__,
"code": vars(e).get('status_code', 500),
"detail": vars(e).get('detail', ''),
"body": vars(e).get('body', ''),
"errors": str(e),
}
log.error(f"API error: {req.method}: {req.url} {err}")
if not isinstance(e, HTTPException) and err['error'] != 'TypeError': # do not print backtrace on known httpexceptions
log.error(f"API error: {req.method}: {req.url} {err}")
errors.display(e, 'HTTP API', [anyio, fastapi, uvicorn, starlette])
elif err['code'] == 404:
pass
else:
log.debug(e, exc_info=True)
return JSONResponse(status_code=vars(e).get('status_code', 500), content=jsonable_encoder(err))
log.debug(e, exc_info=True) # print stack trace
return JSONResponse(status_code=err['code'], content=jsonable_encoder(err))
@app.exception_handler(HTTPException)
async def http_exception_handler(req: Request, e: HTTPException):
+1 -1
View File
@@ -2,10 +2,10 @@ import os
import json
import gradio as gr
import modules.shared
# from modules.shared import log, opts, req, writefile
gradio_theme = gr.themes.Base()
# modules.shared.opts.onchange("gradio_theme", reload_gradio_theme)
def list_builtin_themes():
+1
View File
@@ -5,6 +5,7 @@ from modules import shared, theme
from modules.paths import script_path, data_path
import modules.scripts
def webpath(fn):
if fn.startswith(script_path):
web_path = os.path.relpath(fn, script_path).replace('\\', '/')
-1
View File
@@ -112,7 +112,6 @@ def initialize():
shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
shared.opts.onchange("temp_dir", ui_tempdir.on_tmpdir_changed)
# shared.opts.onchange("gradio_theme", shared.reload_gradio_theme)
timer.startup.record("onchange")
modules.textual_inversion.textual_inversion.list_textual_inversion_templates()
+1 -1
Submodule wiki updated: 671e644b4a...f35e49fcc7