Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files- app.py +31 -7
- ex_card.jpg +0 -0
- ex_nutrition.jpg +0 -0
- ex_product.jpg +0 -0
- ex_receipt.jpg +0 -0
app.py
CHANGED
|
@@ -97,6 +97,21 @@ PRESETS = {
|
|
| 97 |
},
|
| 98 |
}
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# --------------------------------------------------------------------------- #
|
| 101 |
# Inference #
|
| 102 |
# --------------------------------------------------------------------------- #
|
|
@@ -263,7 +278,14 @@ const LQ_PRESETS = __PRESETS__;
|
|
| 263 |
row.querySelector('.lq-del').addEventListener('click', () => { row.remove(); syncStore(mount); });
|
| 264 |
mount.querySelector('#lq-rows').appendChild(row);
|
| 265 |
}
|
| 266 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
const p = LQ_PRESETS[key];
|
| 268 |
if (!p) return;
|
| 269 |
mount.querySelector('#lq-rows').innerHTML = '';
|
|
@@ -271,6 +293,7 @@ const LQ_PRESETS = __PRESETS__;
|
|
| 271 |
mount.querySelectorAll('.lq-chip').forEach(c =>
|
| 272 |
c.classList.toggle('active', c.dataset.preset === key));
|
| 273 |
syncStore(mount);
|
|
|
|
| 274 |
}
|
| 275 |
function init() {
|
| 276 |
const mount = document.getElementById('lq-schema-builder');
|
|
@@ -284,9 +307,9 @@ const LQ_PRESETS = __PRESETS__;
|
|
| 284 |
mount.innerHTML = chips + '<div id="lq-rows"></div>' +
|
| 285 |
'<button class="lq-add" id="lq-add">+ add field</button>';
|
| 286 |
mount.querySelectorAll('.lq-chip').forEach(c =>
|
| 287 |
-
c.addEventListener('click', () => loadPreset(mount, c.dataset.preset)));
|
| 288 |
mount.querySelector('#lq-add').addEventListener('click', () => { makeRow(mount, '', ''); });
|
| 289 |
-
loadPreset(mount, Object.keys(LQ_PRESETS)[0]);
|
| 290 |
}
|
| 291 |
setInterval(init, 250);
|
| 292 |
|
|
@@ -318,8 +341,8 @@ const LQ_PRESETS = __PRESETS__;
|
|
| 318 |
|
| 319 |
CSS = """
|
| 320 |
:root { --lq-orange:#ff7a00; --lq-amber:#ffb000; --lq-lime:#c6e600; }
|
| 321 |
-
.gradio-container { max-width: 1280px !important; }
|
| 322 |
-
#lq-schema-store { display: none !important; }
|
| 323 |
|
| 324 |
#lq-hero {
|
| 325 |
border-radius: 22px; padding: 26px 30px; margin-bottom: 6px;
|
|
@@ -328,8 +351,7 @@ CSS = """
|
|
| 328 |
box-shadow: 0 10px 30px -16px rgba(255,140,0,.55);
|
| 329 |
}
|
| 330 |
#lq-hero h1 { margin:0; font-size: 2.05rem; font-weight: 800; letter-spacing:-.02em;
|
| 331 |
-
|
| 332 |
-
-webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
|
| 333 |
#lq-hero p { margin:.4rem 0 0; color:#7a5a16; font-size:.98rem; max-width: 70ch; }
|
| 334 |
#lq-hero .lq-badges { margin-top:.7rem; display:flex; gap:.5rem; flex-wrap:wrap; }
|
| 335 |
#lq-hero .lq-badge { font-size:.74rem; font-weight:700; padding:.28rem .62rem; border-radius:999px;
|
|
@@ -429,12 +451,14 @@ with gr.Blocks(title="Liquid Image → JSON") as demo:
|
|
| 429 |
gr.Markdown("**Extraction schema** — pick a preset or craft your own fields")
|
| 430 |
gr.HTML('<div id="lq-schema-builder"></div>')
|
| 431 |
schema_store = gr.Textbox(elem_id="lq-schema-store", value="[]")
|
|
|
|
| 432 |
go = gr.Button("💧 Extract JSON", variant="primary", elem_id="lq-go")
|
| 433 |
|
| 434 |
with gr.Column(scale=5):
|
| 435 |
result = gr.HTML(placeholder_html())
|
| 436 |
|
| 437 |
go.click(extract, [image, model_key, schema_store], result)
|
|
|
|
| 438 |
|
| 439 |
if __name__ == "__main__":
|
| 440 |
demo.queue(max_size=20).launch(
|
|
|
|
| 97 |
},
|
| 98 |
}
|
| 99 |
|
| 100 |
+
# One example image per preset, swapped in when a preset chip is clicked.
|
| 101 |
+
EXAMPLE_IMAGES = {
|
| 102 |
+
"wood": "sample_wood.png",
|
| 103 |
+
"receipt": "ex_receipt.jpg",
|
| 104 |
+
"nutrition": "ex_nutrition.jpg",
|
| 105 |
+
"card": "ex_card.jpg",
|
| 106 |
+
"product": "ex_product.jpg",
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def load_example(key):
|
| 111 |
+
path = EXAMPLE_IMAGES.get(key)
|
| 112 |
+
return path if path else gr.update()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
# --------------------------------------------------------------------------- #
|
| 116 |
# Inference #
|
| 117 |
# --------------------------------------------------------------------------- #
|
|
|
|
| 278 |
row.querySelector('.lq-del').addEventListener('click', () => { row.remove(); syncStore(mount); });
|
| 279 |
mount.querySelector('#lq-rows').appendChild(row);
|
| 280 |
}
|
| 281 |
+
function setPreset(key) {
|
| 282 |
+
const store = document.querySelector('#lq-preset-store textarea');
|
| 283 |
+
if (!store) return;
|
| 284 |
+
const setter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, 'value').set;
|
| 285 |
+
setter.call(store, key);
|
| 286 |
+
store.dispatchEvent(new Event('input', { bubbles: true }));
|
| 287 |
+
}
|
| 288 |
+
function loadPreset(mount, key, swapImage) {
|
| 289 |
const p = LQ_PRESETS[key];
|
| 290 |
if (!p) return;
|
| 291 |
mount.querySelector('#lq-rows').innerHTML = '';
|
|
|
|
| 293 |
mount.querySelectorAll('.lq-chip').forEach(c =>
|
| 294 |
c.classList.toggle('active', c.dataset.preset === key));
|
| 295 |
syncStore(mount);
|
| 296 |
+
if (swapImage) setPreset(key);
|
| 297 |
}
|
| 298 |
function init() {
|
| 299 |
const mount = document.getElementById('lq-schema-builder');
|
|
|
|
| 307 |
mount.innerHTML = chips + '<div id="lq-rows"></div>' +
|
| 308 |
'<button class="lq-add" id="lq-add">+ add field</button>';
|
| 309 |
mount.querySelectorAll('.lq-chip').forEach(c =>
|
| 310 |
+
c.addEventListener('click', () => loadPreset(mount, c.dataset.preset, true)));
|
| 311 |
mount.querySelector('#lq-add').addEventListener('click', () => { makeRow(mount, '', ''); });
|
| 312 |
+
loadPreset(mount, Object.keys(LQ_PRESETS)[0], false);
|
| 313 |
}
|
| 314 |
setInterval(init, 250);
|
| 315 |
|
|
|
|
| 341 |
|
| 342 |
CSS = """
|
| 343 |
:root { --lq-orange:#ff7a00; --lq-amber:#ffb000; --lq-lime:#c6e600; }
|
| 344 |
+
.gradio-container { max-width: 1280px !important; margin: 0 auto !important; }
|
| 345 |
+
#lq-schema-store, #lq-preset-store { display: none !important; }
|
| 346 |
|
| 347 |
#lq-hero {
|
| 348 |
border-radius: 22px; padding: 26px 30px; margin-bottom: 6px;
|
|
|
|
| 351 |
box-shadow: 0 10px 30px -16px rgba(255,140,0,.55);
|
| 352 |
}
|
| 353 |
#lq-hero h1 { margin:0; font-size: 2.05rem; font-weight: 800; letter-spacing:-.02em;
|
| 354 |
+
color:#e0590a; -webkit-text-fill-color:#e0590a; text-shadow:0 1px 0 rgba(255,255,255,.4); }
|
|
|
|
| 355 |
#lq-hero p { margin:.4rem 0 0; color:#7a5a16; font-size:.98rem; max-width: 70ch; }
|
| 356 |
#lq-hero .lq-badges { margin-top:.7rem; display:flex; gap:.5rem; flex-wrap:wrap; }
|
| 357 |
#lq-hero .lq-badge { font-size:.74rem; font-weight:700; padding:.28rem .62rem; border-radius:999px;
|
|
|
|
| 451 |
gr.Markdown("**Extraction schema** — pick a preset or craft your own fields")
|
| 452 |
gr.HTML('<div id="lq-schema-builder"></div>')
|
| 453 |
schema_store = gr.Textbox(elem_id="lq-schema-store", value="[]")
|
| 454 |
+
preset_store = gr.Textbox(elem_id="lq-preset-store", value="")
|
| 455 |
go = gr.Button("💧 Extract JSON", variant="primary", elem_id="lq-go")
|
| 456 |
|
| 457 |
with gr.Column(scale=5):
|
| 458 |
result = gr.HTML(placeholder_html())
|
| 459 |
|
| 460 |
go.click(extract, [image, model_key, schema_store], result)
|
| 461 |
+
preset_store.change(load_example, preset_store, image)
|
| 462 |
|
| 463 |
if __name__ == "__main__":
|
| 464 |
demo.queue(max_size=20).launch(
|
ex_card.jpg
ADDED
|
ex_nutrition.jpg
ADDED
|
ex_product.jpg
ADDED
|
ex_receipt.jpg
ADDED
|