multimodalart HF Staff commited on
Commit
fdd0e55
·
verified ·
1 Parent(s): 68375a4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +42 -2
app.py CHANGED
@@ -316,7 +316,41 @@ const LQ_PRESETS = __PRESETS__;
316
  ex.querySelectorAll('.lq-ex').forEach(c => c.addEventListener('click', () =>
317
  loadPreset(document.getElementById('lq-schema-builder'), c.dataset.preset)));
318
  }
319
- function init() { initBuilder(); initExamples(); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  setInterval(init, 250);
321
 
322
  document.addEventListener('click', function (e) {
@@ -383,6 +417,12 @@ CSS = """
383
  .lq-ex:hover { transform:translateY(-1px); border-color:var(--lq-orange); color:#b35900;
384
  box-shadow:0 5px 14px -8px rgba(255,140,0,.6); background:#fff; }
385
 
 
 
 
 
 
 
386
  /* result viewer */
387
  .lq-result-shell { border-radius:18px; min-height:360px; padding:16px;
388
  background:linear-gradient(160deg,#fffaf0,#fff7e6); border:1px solid rgba(255,160,0,.22); }
@@ -439,7 +479,7 @@ with gr.Blocks(title="Liquid Image → JSON") as demo:
439
 
440
  with gr.Row(equal_height=False):
441
  with gr.Column(scale=5):
442
- image = gr.Image(type="pil", label="Image", height=300)
443
  model_key = gr.Radio(
444
  choices=[("450M · ⚡ fastest", "450M"), ("1.6B · 🎯 most accurate", "1.6B")],
445
  value="1.6B",
 
316
  ex.querySelectorAll('.lq-ex').forEach(c => c.addEventListener('click', () =>
317
  loadPreset(document.getElementById('lq-schema-builder'), c.dataset.preset)));
318
  }
319
+ function initLoupe() {
320
+ const wrap = document.getElementById('lq-image');
321
+ if (!wrap || wrap.dataset.loupe) return;
322
+ wrap.dataset.loupe = '1';
323
+ const D = 190, r = D / 2, zoom = 2.8;
324
+ const loupe = document.createElement('div');
325
+ loupe.className = 'lq-loupe';
326
+ loupe.style.width = D + 'px';
327
+ loupe.style.height = D + 'px';
328
+ document.body.appendChild(loupe);
329
+ function previewImg() {
330
+ for (const im of wrap.querySelectorAll('img')) {
331
+ if (im.src && im.naturalWidth > 0 && im.offsetWidth > 48) return im;
332
+ }
333
+ return null;
334
+ }
335
+ wrap.addEventListener('mousemove', function (e) {
336
+ const img = previewImg();
337
+ if (!img) { loupe.style.display = 'none'; return; }
338
+ const rect = img.getBoundingClientRect();
339
+ if (e.clientX < rect.left || e.clientX > rect.right ||
340
+ e.clientY < rect.top || e.clientY > rect.bottom) {
341
+ loupe.style.display = 'none'; return;
342
+ }
343
+ const x = e.clientX - rect.left, y = e.clientY - rect.top;
344
+ loupe.style.display = 'block';
345
+ loupe.style.backgroundImage = 'url("' + img.src + '")';
346
+ loupe.style.backgroundSize = (rect.width * zoom) + 'px ' + (rect.height * zoom) + 'px';
347
+ loupe.style.backgroundPosition = (r - x * zoom) + 'px ' + (r - y * zoom) + 'px';
348
+ loupe.style.left = (e.clientX - r) + 'px';
349
+ loupe.style.top = (e.clientY - r) + 'px';
350
+ });
351
+ wrap.addEventListener('mouseleave', function () { loupe.style.display = 'none'; });
352
+ }
353
+ function init() { initBuilder(); initExamples(); initLoupe(); }
354
  setInterval(init, 250);
355
 
356
  document.addEventListener('click', function (e) {
 
417
  .lq-ex:hover { transform:translateY(-1px); border-color:var(--lq-orange); color:#b35900;
418
  box-shadow:0 5px 14px -8px rgba(255,140,0,.6); background:#fff; }
419
 
420
+ /* hover magnifier loupe */
421
+ .lq-loupe { position:fixed; border-radius:50%; pointer-events:none; display:none; z-index:9999;
422
+ background-repeat:no-repeat; background-color:#fff;
423
+ border:3px solid #fff; box-shadow:0 8px 24px -6px rgba(120,70,0,.5), 0 0 0 2px var(--lq-orange); }
424
+ #lq-image img { cursor:crosshair; }
425
+
426
  /* result viewer */
427
  .lq-result-shell { border-radius:18px; min-height:360px; padding:16px;
428
  background:linear-gradient(160deg,#fffaf0,#fff7e6); border:1px solid rgba(255,160,0,.22); }
 
479
 
480
  with gr.Row(equal_height=False):
481
  with gr.Column(scale=5):
482
+ image = gr.Image(type="pil", label="Image", height=300, elem_id="lq-image")
483
  model_key = gr.Radio(
484
  choices=[("450M · ⚡ fastest", "450M"), ("1.6B · 🎯 most accurate", "1.6B")],
485
  value="1.6B",