mirror of
https://github.com/vladmandic/automatic
synced 2026-09-10 23:08:43 +02:00
diffusers img2img and inpaint
This commit is contained in:
+24
-24
@@ -1,4 +1,4 @@
|
||||
const locale = {
|
||||
const localeData = {
|
||||
data: [],
|
||||
timeout: null,
|
||||
finished: false,
|
||||
@@ -7,25 +7,25 @@ const locale = {
|
||||
};
|
||||
|
||||
function tooltipCreate() {
|
||||
locale.el = document.createElement('div');
|
||||
locale.el.className = 'tooltip';
|
||||
locale.el.id = 'tooltip-container';
|
||||
locale.el.innerText = 'this is a hint';
|
||||
gradioApp().appendChild(locale.el);
|
||||
if (window.opts.tooltips === 'None') locale.type = 0;
|
||||
if (window.opts.tooltips === 'Browser default') locale.type = 1;
|
||||
if (window.opts.tooltips === 'UI tooltips') locale.type = 2;
|
||||
localeData.el = document.createElement('div');
|
||||
localeData.el.className = 'tooltip';
|
||||
localeData.el.id = 'tooltip-container';
|
||||
localeData.el.innerText = 'this is a hint';
|
||||
gradioApp().appendChild(localeData.el);
|
||||
if (window.opts.tooltips === 'None') localeData.type = 0;
|
||||
if (window.opts.tooltips === 'Browser default') localeData.type = 1;
|
||||
if (window.opts.tooltips === 'UI tooltips') localeData.type = 2;
|
||||
}
|
||||
|
||||
async function tooltipShow(e) {
|
||||
if (e.target.dataset.hint) {
|
||||
locale.el.classList.add('tooltip-show');
|
||||
locale.el.innerHTML = `<b>${e.target.textContent}</b><br>${e.target.dataset.hint}`;
|
||||
localeData.el.classList.add('tooltip-show');
|
||||
localeData.el.innerHTML = `<b>${e.target.textContent}</b><br>${e.target.dataset.hint}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function tooltipHide(e) {
|
||||
locale.el.classList.remove('tooltip-show');
|
||||
localeData.el.classList.remove('tooltip-show');
|
||||
}
|
||||
|
||||
async function validateHints(elements, data) {
|
||||
@@ -47,11 +47,11 @@ async function validateHints(elements, data) {
|
||||
}
|
||||
|
||||
async function setHints() {
|
||||
if (locale.finished) return;
|
||||
if (locale.data.length === 0) {
|
||||
if (localeData.finished) return;
|
||||
if (localeData.data.length === 0) {
|
||||
const res = await fetch('/file=html/locale_en.json');
|
||||
const json = await res.json();
|
||||
locale.data = Object.values(json).flat();
|
||||
localeData.data = Object.values(json).flat();
|
||||
}
|
||||
const elements = [
|
||||
...Array.from(gradioApp().querySelectorAll('button')),
|
||||
@@ -59,22 +59,22 @@ async function setHints() {
|
||||
];
|
||||
if (elements.length === 0) return;
|
||||
if (Object.keys(opts).length === 0) return;
|
||||
if (!locale.el) tooltipCreate();
|
||||
if (!localeData.el) tooltipCreate();
|
||||
let localized = 0;
|
||||
let hints = 0;
|
||||
locale.finished = true;
|
||||
localeData.finished = true;
|
||||
const t0 = performance.now();
|
||||
for (const el of elements) {
|
||||
const found = locale.data.find((l) => l.label === el.textContent.trim());
|
||||
const found = localeData.data.find((l) => l.label === el.textContent.trim());
|
||||
if (found?.localized?.length > 0) {
|
||||
localized++;
|
||||
el.textContent = found.localized;
|
||||
}
|
||||
if (found?.hint?.length > 0) {
|
||||
hints++;
|
||||
if (locale.type === 1) {
|
||||
if (localeData.type === 1) {
|
||||
el.title = found.hint;
|
||||
} else if (locale.type === 2) {
|
||||
} else if (localeData.type === 2) {
|
||||
el.dataset.hint = found.hint;
|
||||
el.addEventListener('mouseover', tooltipShow);
|
||||
el.addEventListener('mouseout', tooltipHide);
|
||||
@@ -84,12 +84,12 @@ async function setHints() {
|
||||
}
|
||||
}
|
||||
const t1 = performance.now();
|
||||
console.log('setHints', { type: locale.type, elements: elements.length, localized, hints, data: locale.data.length, time: t1 - t0 });
|
||||
console.log('setHints', { type: localeData.type, elements: elements.length, localized, hints, data: localeData.data.length, time: t1 - t0 });
|
||||
removeSplash();
|
||||
// validateHints(elements, locale.data)
|
||||
// validateHints(elements, localeData.data)
|
||||
}
|
||||
|
||||
onAfterUiUpdate(async () => {
|
||||
if (locale.timeout) clearTimeout(locale.timeout);
|
||||
locale.timeout = setTimeout(setHints, 250);
|
||||
if (localeData.timeout) clearTimeout(localeData.timeout);
|
||||
localeData.timeout = setTimeout(setHints, 250);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user