Spaces:
Running
Running
image2vienna browser demo: Vienna 10 (2ceef57)
Browse filesFiles changed (2)
- app.js+40-4
- index.html+8-4
20 unmodified lines212223242526282 unmodified lines3093103113123133143154 unmodified lines3203213223233243253265 unmodified lines3323333343353363373383393403413423433443453463473483497 unmodified lines357358359360361362363364407 unmodified lines77277377477577677720 unmodified linesconst ui = {drop: $("drop"),dropText: $("drop-text"),preview: $("preview"),file: $("file"),gallery: $("gallery"),282 unmodified linesfail(err, "The vision model failed");} finally {describing = false;ui.describe.disabled = !state.image; // the note written above stays}}4 unmodified linesui.describe.hidden = true;return;}ui.describe.disabled = !state.image;ui.describe.title = `${v.web_model} runs in a Web Worker in this tab; about 250 MB once`;if (state.example) {const ex = state.example;5 unmodified lines} else if (state.image) {ui.descNote.textContent = "Click Describe to let the vision model write the inventory here, or type it.";}}// -- image input --------------------------------------------------------------function setImage(bytes, mime, name, example = null) {state.image = { bytes, mime, name };state.example = example;const url = URL.createObjectURL(new Blob([bytes], { type: mime }));ui.preview.src = url;ui.preview.alt = name;ui.preview.hidden = false;ui.dropText.textContent = name;if (!example) ui.text.value = "";state.error = null;updateDescribeUi();7 unmodified linessetImage(bytes, file.type, file.name);}function bindImageInput() {ui.file.addEventListener("change", () => takeFile(ui.file.files[0]));ui.drop.addEventListener("dragover", (e) => {e.preventDefault();ui.drop.classList.add("over");407 unmodified linesfillSelect(ui.level, [AUTO_LEVEL, ...LEVELS]);ui.level.value = "section";if (!state.manifest.vision) ui.describe.hidden = true;await loadExamples();renderGallery();bindImageInput();20 unmodified lines21222324252627282 unmodified lines3103113123133143153164 unmodified lines3213223233243253265 unmodified lines3323333343353363373383393403413423433443453463473483493503513523533543553563573583593607 unmodified lines368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399407 unmodified lines80780880981081181281320 unmodified linesconst ui = {drop: $("drop"),dropText: $("drop-text"),pick: $("pick"),preview: $("preview"),file: $("file"),gallery: $("gallery"),282 unmodified linesfail(err, "The vision model failed");} finally {describing = false;refreshButtons(); // the note written above stays}}4 unmodified linesui.describe.hidden = true;return;}ui.describe.title = `${v.web_model} runs in a Web Worker in this tab; about 250 MB once`;if (state.example) {const ex = state.example;5 unmodified lines} else if (state.image) {ui.descNote.textContent = "Click Describe to let the vision model write the inventory here, or type it.";}refreshButtons();}// -- image input --------------------------------------------------------------/** A new image makes the previous results stale: the graph and the table go until Classify. */function clearResults() {ui.graph.innerHTML = "";ui.legend.hidden = true;ui.results.innerHTML = "";ui.meta.textContent = "";hideTip();}function setImage(bytes, mime, name, example = null) {state.image = { bytes, mime, name };state.example = example;clearResults();const url = URL.createObjectURL(new Blob([bytes], { type: mime }));ui.preview.src = url;ui.preview.alt = name;ui.preview.hidden = false;ui.dropText.textContent = `${name} · drop, paste or`;if (!example) ui.text.value = "";state.error = null;updateDescribeUi();7 unmodified linessetImage(bytes, file.type, file.name);}/** The Describe button is the next step (blue) while an image has no description. */function refreshButtons() {const enabled = Boolean(state.image) && Boolean(state.manifest.vision);ui.describe.disabled = !enabled;const next = enabled && !ui.text.value.trim();ui.describe.classList.toggle("primary", next);ui.describe.classList.toggle("secondary", !next);}function bindImageInput() {const pick = (e) => {e.preventDefault();ui.file.click();};ui.file.addEventListener("change", () => {takeFile(ui.file.files[0]);ui.file.value = ""; // the same file can be picked again});// the label opens the picker natively; a click elsewhere in the area does it by scriptui.drop.addEventListener("click", (e) => {if (e.target !== ui.pick && e.target !== ui.file) pick(e);});ui.drop.addEventListener("keydown", (e) => {if (e.key === "Enter" || e.key === " ") pick(e);});ui.text.addEventListener("input", refreshButtons);ui.drop.addEventListener("dragover", (e) => {e.preventDefault();ui.drop.classList.add("over");407 unmodified linesfillSelect(ui.level, [AUTO_LEVEL, ...LEVELS]);ui.level.value = "section";if (!state.manifest.vision) ui.describe.hidden = true;refreshButtons();await loadExamples();renderGallery();bindImageInput();
31 unmodified lines323334353637383972 unmodified lines11211311411511611711811912012112231 unmodified linescolor: var(--muted); cursor: pointer; min-height: 220px; display: flex; flex-direction: column;align-items: center; justify-content: center; gap: 8px; }#drop.over { border-color: var(--accent); color: var(--fg); }#drop img { max-width: 100%; max-height: 260px; border-radius: 6px; background: #fff; }#drop input { display: none; }#gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 10px; }#gallery button { padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff;cursor: pointer; aspect-ratio: 1; overflow: hidden; }72 unmodified lines<div class="panes"><div><label id="drop" for="file"><img id="preview" alt="" hidden><span id="drop-text">Drop an image here, click to choose one, or paste it</span><input id="file" type="file" accept="image/*"></label><h2>Examples</h2><div id="gallery"></div></div>31 unmodified lines323334353637383940414272 unmodified lines11511611711811912012112212312412512631 unmodified linescolor: var(--muted); cursor: pointer; min-height: 220px; display: flex; flex-direction: column;align-items: center; justify-content: center; gap: 8px; }#drop.over { border-color: var(--accent); color: var(--fg); }#drop:focus-visible { outline: 2px solid var(--accent); }#drop img { max-width: 100%; max-height: 260px; border-radius: 6px; background: #fff; }#drop input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }#drop label.secondary { display: inline-block; padding: 8px 16px; border-radius: 6px; font-weight: 600;cursor: pointer; background: var(--chip); color: var(--fg); border: 1px solid var(--line); }#gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 10px; }#gallery button { padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff;cursor: pointer; aspect-ratio: 1; overflow: hidden; }72 unmodified lines<div class="panes"><div><div id="drop" role="button" tabindex="0" aria-label="Choose an image" style="position: relative;"><img id="preview" alt="" hidden><span id="drop-text">Drop an image here, paste it, or</span><label id="pick" class="secondary" for="file">Choose an image…</label><input id="file" type="file" accept="image/*"></div><h2>Examples</h2><div id="gallery"></div></div>
app.js+40-4
index.html+8-4