File size: 3,851 Bytes
111769a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
() => {
  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);
}