fix theme enum and preview

This commit is contained in:
Vladimir Mandic
2023-09-07 11:30:57 -04:00
parent 09b4c79f4a
commit c81a909e85
5 changed files with 46 additions and 34 deletions
+4
View File
@@ -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!
+14 -12
View File
@@ -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
View File
@@ -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
View File
@@ -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")