Skip to content

Commit

Permalink
massive hints update
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Feb 8, 2025
1 parent 7041b2b commit 8873b2f
Show file tree
Hide file tree
Showing 8 changed files with 1,015 additions and 110 deletions.
1,030 changes: 942 additions & 88 deletions html/locale_en.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion html/locale_ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
{"id":"","label":"Image Options","localized":"이미지 설정","hint":""},
{"id":"","label":"Image Processing","localized":"이미지 프로세싱","hint":""},
{"id":"","label":"Image Paths","localized":"이미지 위치","hint":""},
{"id":"","label":"User Interface","localized":"유저 인터페이스","hint":""},
{"id":"","label":"Live Previews","localized":"라이브 프리뷰","hint":""},
{"id":"","label":"Sampler Settings","localized":"샘플러 설정","hint":""},
{"id":"","label":"Postprocessing","localized":"후처리","hint":""},
Expand Down
56 changes: 46 additions & 10 deletions javascript/setHints.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,42 @@ async function tooltipHide(e) {
localeData.el.classList.remove('tooltip-show');
}

async function validateHints(elements, data) {
let original = elements.map((e) => e.textContent.toLowerCase().trim()).sort((a, b) => a > b);
async function validateHints(json, elements) {
json.missing = [];
const data = Object.values(json).flat().filter((e) => e.hint.length > 0);
for (const e of data) e.label = e.label.toLowerCase().trim();
let original = elements.map((e) => e.textContent.toLowerCase().trim()).sort();
let duplicateUI = original.filter((e, i, a) => a.indexOf(e) !== i).sort();
original = [...new Set(original)]; // remove duplicates
const current = data.map((e) => e.label.toLowerCase().trim()).sort((a, b) => a > b);
duplicateUI = [...new Set(duplicateUI)]; // remove duplicates
const current = data.map((e) => e.label.toLowerCase().trim()).sort();
log('all elements:', original);
log('all hints:', current);
log('hints-differences', { elements: original.length, hints: current.length });
const missingLocale = original.filter((e) => !current.includes(e));
log('missing in locale:', missingLocale);
const missingUI = current.filter((e) => !original.includes(e));
log('in locale but not ui:', missingUI);
const missingHints = original.filter((e) => !current.includes(e)).sort();
const orphanedHints = current.filter((e) => !original.includes(e)).sort();
const duplicateHints = current.filter((e, i, a) => a.indexOf(e) !== i).sort();
log('duplicate hints:', duplicateHints);
log('duplicate labels:', duplicateUI);
return [missingHints, orphanedHints];
}

async function addMissingHints(json, missingHints) {
if (missingHints.length === 0) return;
json.missing = [];
for (const h of missingHints.sort()) {
if (h.length <= 1) continue;
json.missing.push({ id: '', label: h, localized: '', hint: h });
}
log('missing hints', missingHints);
log('added missing hints:', { missing: json.missing });
}

async function removeOrphanedHints(json, orphanedHints) {
const data = Object.values(json).flat().filter((e) => e.hint.length > 0);
for (const e of data) e.label = e.label.toLowerCase().trim();
const orphaned = data.filter((e) => orphanedHints.includes(e.label));
log('orphaned hints:', { orphaned });
}

async function replaceButtonText(el) {
Expand All @@ -65,11 +90,12 @@ async function replaceButtonText(el) {
}
}

async function setHints() {
async function setHints(analyze = false) {
let json = {};
if (localeData.finished) return;
if (localeData.data.length === 0) {
const res = await fetch('/file=html/locale_en.json');
const json = await res.json();
json = await res.json();
localeData.data = Object.values(json).flat().filter((e) => e.hint.length > 0);
for (const e of localeData.data) e.label = e.label.toLowerCase().trim();
}
Expand Down Expand Up @@ -107,9 +133,19 @@ async function setHints() {
const t1 = performance.now();
log('setHints', { type: localeData.type, elements: elements.length, localized, hints, data: localeData.data.length, time: t1 - t0 });
// sortUIElements();
// validateHints(elements, localeData.data);
if (analyze) {
const [missingHints, orphanedHints] = await validateHints(json, elements);
await addMissingHints(json, missingHints);
await removeOrphanedHints(json, orphanedHints);
}
}

const analyzeHints = async () => {
localeData.finished = false;
localeData.data = [];
await setHints(true);
};

/*
onAfterUiUpdate(async () => {
if (localeData.timeout) clearTimeout(localeData.timeout);
Expand Down
4 changes: 2 additions & 2 deletions modules/postprocess/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ def ui_settings_change(detailers, classes, strength, padding, blur, min_confiden
with gr.Row():
enabled = gr.Checkbox(label="Enable detailer pass", elem_id=f"{tab}_detailer_enabled", value=False)
with gr.Row():
detailers = gr.Dropdown(label="Detailers", elem_id=f"{tab}_detailers", choices=self.list, value=shared.opts.detailer_models, multiselect=True)
detailers = gr.Dropdown(label="Detailer models", elem_id=f"{tab}_detailers", choices=self.list, value=shared.opts.detailer_models, multiselect=True)
ui_common.create_refresh_button(detailers, self.enumerate, {}, elem_id=f"{tab}_detailers_refresh")
with gr.Row():
classes = gr.Textbox(label="Classes", placeholder="Classes", elem_id=f"{tab}_detailer_classes")
classes = gr.Textbox(label="Detailer classes", placeholder="Classes", elem_id=f"{tab}_detailer_classes")
with gr.Row():
prompt = gr.Textbox(label="Detailer prompt", value='', placeholder='Detailer prompt', lines=2, elem_id=f"{tab}_detailer_prompt")
with gr.Row():
Expand Down
22 changes: 19 additions & 3 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,25 @@ def list_samplers():


def temp_disable_extensions():
disable_safe = ['sd-webui-controlnet', 'multidiffusion-upscaler-for-automatic1111', 'a1111-sd-webui-lycoris', 'sd-webui-agent-scheduler', 'clip-interrogator-ext', 'stable-diffusion-webui-images-browser']
disable_diffusers = ['sd-webui-controlnet', 'multidiffusion-upscaler-for-automatic1111', 'a1111-sd-webui-lycoris', 'sd-webui-animatediff']
disable_themes = ['sd-webui-lobe-theme', 'cozy-nest', 'sdnext-modernui']
disable_safe = [
'sd-webui-controlnet',
'multidiffusion-upscaler-for-automatic1111',
'a1111-sd-webui-lycoris',
'sd-webui-agent-scheduler',
'clip-interrogator-ext',
'stable-diffusion-webui-images-browser',
]
disable_diffusers = [
'sd-webui-controlnet',
'multidiffusion-upscaler-for-automatic1111',
'a1111-sd-webui-lycoris',
'sd-webui-animatediff',
]
disable_themes = [
'sd-webui-lobe-theme',
'cozy-nest',
'sdnext-modernui',
]
disable_original = []
disabled = []
if modules.shared.cmd_opts.theme is not None:
Expand Down
8 changes: 4 additions & 4 deletions modules/ui_loadsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ def ui_restore(self):
def create_ui(self):
"""creates ui elements for editing defaults UI, without adding any logic to them"""
with gr.Row(elem_id="config_row"):
self.ui_defaults_apply = gr.Button(value='Set new defaults', elem_id="ui_defaults_apply", variant="primary")
self.ui_defaults_submenu = gr.Button(value='Set menu states', elem_id="ui_submenu_apply", variant="primary")
self.ui_defaults_restore = gr.Button(value='Restore defaults', elem_id="ui_defaults_restore", variant="primary")
self.ui_defaults_view = gr.Button(value='Refresh changes', elem_id="ui_defaults_view", variant="secondary")
self.ui_defaults_apply = gr.Button(value='Set UI defaults', elem_id="ui_defaults_apply", variant="primary")
self.ui_defaults_submenu = gr.Button(value='Set UI menu states', elem_id="ui_submenu_apply", variant="primary")
self.ui_defaults_restore = gr.Button(value='Restore UI defaults', elem_id="ui_defaults_restore", variant="primary")
self.ui_defaults_view = gr.Button(value='Refresh UI values', elem_id="ui_defaults_view", variant="secondary")
self.ui_defaults_review = gr.HTML("", elem_id="ui_defaults_review")

def setup_ui(self):
Expand Down
2 changes: 1 addition & 1 deletion modules/ui_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def create_resize_inputs(tab, images, accordion=True, latent=False, non_zero=Tru
if not latent:
available_upscalers = [x for x in available_upscalers if not x.lower().startswith('latent')]
resize_mode = gr.Dropdown(label=f"Mode{prefix}" if non_zero else "Resize mode", elem_id=f"{tab}_resize_mode", choices=shared.resize_modes, type="index", value='Fixed')
resize_name = gr.Dropdown(label=f"Method{prefix}", elem_id=f"{tab}_resize_name", choices=available_upscalers, value=available_upscalers[0], visible=True)
resize_name = gr.Dropdown(label=f"Method{prefix}" if non_zero else "Resize method", elem_id=f"{tab}_resize_name", choices=available_upscalers, value=available_upscalers[0], visible=True)
resize_context_choices = ["Add with forward", "Remove with forward", "Add with backward", "Remove with backward"]
resize_context = gr.Dropdown(label=f"Context{prefix}", elem_id=f"{tab}_resize_context", choices=resize_context_choices, value=resize_context_choices[0], visible=False)
ui_common.create_refresh_button(resize_name, modelloader.load_upscalers, lambda: {"choices": modelloader.load_upscalers()}, 'refresh_upscalers')
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from d2874e to 13cc1b

0 comments on commit 8873b2f

Please sign in to comment.