Qdpie-Qwen-Image-Editor / ui /lora_demo.js
Qdpie's picture
Upload 8 files
111769a verified
Raw
History Blame Contribute Delete
3.85 kB
() => {
window.__LORA_HELP = __LORA_HELP_JS__;
window.__LORA_DEFAULT_PROMPTS = __LORA_DEFAULT_PROMPTS_JS__;
window.__LORA_DEMO_BEFORE = __LORA_DEMO_BEFORE_JS__;
window.__LORA_DEMO_AFTER = __LORA_DEMO_AFTER_JS__;
window.__LORA_DEMO_GENERIC_BEFORE = __LORA_DEMO_GENERIC_BEFORE_JS__;
window.__LORA_DEMO_GENERIC_AFTER = __LORA_DEMO_GENERIC_AFTER_JS__;
window.__setLoraDemos = function(val, opts) {
opts = opts || {};
var before = document.getElementById('lora-demo-before');
var after = document.getElementById('lora-demo-after');
var nameEl = document.getElementById('lora-demo-name');
var status = document.getElementById('lora-demo-status');
var tip = document.getElementById('lora-help-tooltip');
var box = document.getElementById('lora-help-text');
var help = window.__LORA_HELP || {};
var v = val || 'none';
var text = help[v] || help['none'] || '';
// Phone skin CSS hides demos until a LoRA is selected
try {
document.documentElement.classList.toggle('has-lora-selected', !!(v && v !== 'none'));
} catch (e) {}
if (nameEl) nameEl.textContent = (v === 'none') ? 'Choose a LoRA…' : v;
if (tip) tip.textContent = text;
if (box) {
if (v === 'none') box.textContent = text;
else box.innerHTML = '<b>' + String(v).replace(/</g,'&lt;') + '</b> — ' + String(text).replace(/</g,'&lt;');
}
// Starter prompts come from chips only (LoRA menu does not auto-fill the prompt box).
function setSrc(img, url) {
if (!img || !url) return;
img.style.display = 'block';
img.style.width = '100%';
img.style.height = '200px';
img.style.objectFit = 'contain';
img.style.background = '#0a0a0c';
img.onerror = function() {
if (img.dataset.retried) return;
img.dataset.retried = '1';
if (url.indexOf('/gradio_api/file=') === 0) {
img.src = url.replace('/gradio_api/file=', '/file=');
}
};
delete img.dataset.retried;
img.src = url;
}
var genB = window.__LORA_DEMO_GENERIC_BEFORE;
var genA = window.__LORA_DEMO_GENERIC_AFTER;
var beforeMap = window.__LORA_DEMO_BEFORE || {};
var afterMap = window.__LORA_DEMO_AFTER || {};
if (v === 'none') {
setSrc(before, genB); setSrc(after, genA);
if (status) status.textContent = 'Generic demo (loras/generic-*)';
return;
}
var slug = String(v).toLowerCase();
setSrc(before, beforeMap[slug] || genB);
setSrc(after, afterMap[slug] || genA);
if (status) status.textContent = (beforeMap[slug] ? 'Before from loras/' : 'Before missing') + ' · ' + (afterMap[slug] ? 'After from loras/' : 'After missing (generic)');
};
function bindLoraDemoSelect() {
// Ensure dual-skin boot ran (unique #custom-lora-select in DOM)
if (typeof window.__qwenActivateUiSkin === 'function' && !window.__qwenUiSkin) {
window.__qwenActivateUiSkin();
}
if (!window.__qwenUiSkin) {
var dual = document.getElementById('skin-desktop') || document.getElementById('skin-phone');
if (dual) { setTimeout(bindLoraDemoSelect, 50); return; }
}
var sel = document.getElementById('custom-lora-select');
if (!sel) { setTimeout(bindLoraDemoSelect, 250); return; }
if (sel.dataset.loraDemoBound) return;
sel.dataset.loraDemoBound = '1';
sel.addEventListener('change', function() {
window.__setLoraDemos(sel.value, { fromUser: true });
});
// Initial paint: demos/help only; don't stomp a restored prompt
window.__setLoraDemos(sel.value || 'none', { skipPrompt: true });
}
bindLoraDemoSelect();
setTimeout(function() {
if (window.__setLoraDemos) {
var sel = document.getElementById('custom-lora-select');
window.__setLoraDemos(sel ? sel.value : 'none', { skipPrompt: true });
}
}, 500);
}