mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
fix theme enum and preview
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Change Log for SD.Next
|
||||
|
||||
## Update for 2023-09-07
|
||||
|
||||
Service release with many fixes
|
||||
|
||||
## Update for 2023-09-06
|
||||
|
||||
One week later, another large update!
|
||||
|
||||
Submodule extensions-builtin/sd-extension-system-info updated: 761cf83c93...83dd4d8f65
+14
-12
@@ -361,19 +361,21 @@ function create_theme_element() {
|
||||
return el;
|
||||
}
|
||||
|
||||
async function preview_theme() {
|
||||
function previewTheme() {
|
||||
let name = gradioApp().getElementById('setting_gradio_theme').querySelectorAll('input')?.[0].value || '';
|
||||
const res = await fetch('/file=html/themes.json');
|
||||
const themes = await res.json();
|
||||
const theme = themes.find((t) => t.id === name);
|
||||
if (theme) {
|
||||
window.open(theme.subdomain, '_blank');
|
||||
} else {
|
||||
const el = document.getElementById('theme-preview') || create_theme_element();
|
||||
el.style.display = el.style.display === 'block' ? 'none' : 'block';
|
||||
name = name.replace('/', '-');
|
||||
el.src = `/file=html/${name}.jpg`;
|
||||
}
|
||||
fetch('/file=html/themes.json').then((res) => {
|
||||
res.json().then((themes) => {
|
||||
const theme = themes.find((t) => t.id === name);
|
||||
if (theme) {
|
||||
window.open(theme.subdomain, '_blank');
|
||||
} else {
|
||||
const el = document.getElementById('theme-preview') || create_theme_element();
|
||||
el.style.display = el.style.display === 'block' ? 'none' : 'block';
|
||||
name = name.replace('/', '-');
|
||||
el.src = `/file=html/${name}.jpg`;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function reconnectUI() {
|
||||
|
||||
+26
-20
@@ -248,33 +248,17 @@ def refresh_checkpoints():
|
||||
import modules.sd_models # pylint: disable=W0621
|
||||
return modules.sd_models.list_models()
|
||||
|
||||
|
||||
def refresh_vaes():
|
||||
import modules.sd_vae # pylint: disable=W0621
|
||||
modules.sd_vae.refresh_vae_list()
|
||||
|
||||
|
||||
def list_samplers():
|
||||
import modules.sd_samplers # pylint: disable=W0621
|
||||
modules.sd_samplers.set_samplers()
|
||||
return modules.sd_samplers.all_samplers
|
||||
|
||||
def list_builtin_themes():
|
||||
files = [os.path.splitext(f)[0] for f in os.listdir('javascript') if f.endswith('.css')]
|
||||
return files
|
||||
|
||||
def list_themes():
|
||||
fn = os.path.join('html', 'themes.json')
|
||||
if not os.path.exists(fn):
|
||||
refresh_themes()
|
||||
if os.path.exists(fn):
|
||||
with open(fn, mode='r', encoding='utf=8') as f:
|
||||
res = json.loads(f.read())
|
||||
else:
|
||||
res = []
|
||||
list_builtin_themes()
|
||||
builtin = list_builtin_themes() + ["gradio/default", "gradio/base", "gradio/glass", "gradio/monochrome", "gradio/soft"]
|
||||
themes = sorted(builtin) + sorted({x['id'] for x in res if x['status'] == 'RUNNING' and 'test' not in x['id'].lower()}, key=str.casefold)
|
||||
return themes
|
||||
|
||||
|
||||
def temp_disable_extensions():
|
||||
disabled = []
|
||||
@@ -290,6 +274,28 @@ def temp_disable_extensions():
|
||||
return disabled
|
||||
|
||||
|
||||
def list_builtin_themes():
|
||||
files = [os.path.splitext(f)[0] for f in os.listdir('javascript') if f.endswith('.css')]
|
||||
return files
|
||||
|
||||
|
||||
def list_themes():
|
||||
fn = os.path.join('html', 'themes.json')
|
||||
if not os.path.exists(fn):
|
||||
refresh_themes()
|
||||
if os.path.exists(fn):
|
||||
with open(fn, mode='r', encoding='utf=8') as f:
|
||||
res = json.loads(f.read())
|
||||
else:
|
||||
res = []
|
||||
builtin = list_builtin_themes()
|
||||
default = ["gradio/default", "gradio/base", "gradio/glass", "gradio/monochrome", "gradio/soft"]
|
||||
external = {x['id'] for x in res if x['status'] == 'RUNNING' and 'test' not in x['id'].lower()}
|
||||
log.info(f'Themes list: builtin={len(builtin)} default={len(default)} external={len(external)}')
|
||||
themes = sorted(builtin) + sorted(default) + sorted(external, key=str.casefold)
|
||||
return themes
|
||||
|
||||
|
||||
def refresh_themes():
|
||||
import requests
|
||||
try:
|
||||
@@ -297,8 +303,8 @@ def refresh_themes():
|
||||
if req.status_code == 200:
|
||||
res = req.json()
|
||||
fn = os.path.join('html', 'themes.json')
|
||||
with open(fn, mode='w', encoding='utf=8') as f:
|
||||
f.write(json.dumps(res))
|
||||
writefile(res, fn)
|
||||
list_themes()
|
||||
else:
|
||||
log.error('Error refreshing UI themes')
|
||||
except Exception:
|
||||
|
||||
+1
-1
@@ -1085,7 +1085,7 @@ def create_ui(startup_timer = None):
|
||||
unload_sd_model.click(fn=unload_sd_weights, inputs=[], outputs=[])
|
||||
reload_sd_model.click(fn=reload_sd_weights, inputs=[], outputs=[])
|
||||
request_notifications.click(fn=lambda: None, inputs=[], outputs=[], _js='function(){}')
|
||||
preview_theme.click(fn=None, _js='preview_theme', inputs=[dummy_component], outputs=[dummy_component])
|
||||
preview_theme.click(fn=None, _js='previewTheme', inputs=[], outputs=[])
|
||||
|
||||
timer.startup.record("ui-settings")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user