Spaces:
Running
Running
Static in-browser demo
Browse filesFiles changed (14)
- .gitattributes+1
- README.md+13-5
- app.jsAdded+159
- assets/favicon.svgAdded
- common.jsAdded+125
- demo.cssAdded+91
- examples/ATTRIBUTION.mdAdded+11
- examples/example_1.jpgAdded
- examples/example_2.jpgAdded
- examples/example_3.jpgAdded
- index.html+59-17
- models/polyp_unet_fp16.onnxAdded+3
- style.cssDeleted-28
- styles.cssAdded+295
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textexamples/example_2.jpg filter=lfs diff=lfs merge=lfs -text
12345678910---title: Polypshiftemoji: 👁colorFrom: bluecolorTo: yellowsdk: staticpinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718---title: "PolypShift: polyp segmentation"emoji: 🔬colorFrom: greencolorTo: bluesdk: staticapp_file: index.htmlpinned: falselicense: mitshort_description: "In-browser colonoscopy polyp segmentation"---# PolypShift: polyp segmentationResearch demo, **not for clinical use**. The model runs entirely in your browser with ONNX Runtime Web: nothing you choose or upload leaves your device.- Full project, code and results: https://github.com/rigel08- All demos: https://rigel08.github.io/portfolio-site/demos/
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159(function () { "use strict"; Demo.chrome({ repo: "https://github.com/rigel08/polyp-segmentation", footer: 'Training data: Jha et al., Kvasir-SEG (MMM 2020, research use). Example images: Wikimedia Commons, <a href="https://github.com/rigel08/portfolio-site/blob/main/demos/polyp/examples/ATTRIBUTION.md">credits</a>.', privacy: "Your image stays in your browser: the model runs on this device and nothing you choose or upload is sent anywhere. Even so, do not use images that could identify a patient." });
var SIZE = 256, MEAN = [0.485, 0.456, 0.406], STD = [0.229, 0.224, 0.225], MAX_SIDE = 1024; var EXAMPLES = ["example_1.jpg", "example_2.jpg", "example_3.jpg"]; var st = Demo.status(document.getElementById("load")); var thr = document.getElementById("thr"), tta = document.getElementById("tta"); var sessP = null, current = null, busy = Promise.resolve();
function session() { if (!sessP) sessP = Demo.loadSession("models/polyp_unet_fp16.onnx", function (f, got) { st.set("Downloading the model (49 MB, once)… " + Math.round(f * 100) + "%", f); }); return sessP; }
/* RGB uint8 (256*256*4 RGBA) -> NCHW float tensor data */ function toTensor(rgba) { var n = SIZE * SIZE, x = new Float32Array(3 * n); for (var i = 0; i < n; i++) for (var c = 0; c < 3; c++) x[c * n + i] = (rgba[i * 4 + c] / 255 - MEAN[c]) / STD[c]; return x; } function flip(x, h, v) { // flip each channel horizontally and/or vertically if (!h && !v) return x; var out = new Float32Array(x.length), n = SIZE * SIZE; for (var c = 0; c < x.length / n; c++) for (var r = 0; r < SIZE; r++) for (var q = 0; q < SIZE; q++) out[c * n + r * SIZE + q] = x[c * n + (v ? SIZE - 1 - r : r) * SIZE + (h ? SIZE - 1 - q : q)]; return out; }
async function probMap(rgba256, useTTA) { var sess = await session(), x = toTensor(rgba256), n = SIZE * SIZE, total = new Float32Array(n); var flips = useTTA ? [[0, 0], [1, 0], [0, 1], [1, 1]] : [[0, 0]]; for (var f of flips) { var out = await sess.run({ image: new ort.Tensor("float32", flip(x, f[0], f[1]), [1, 3, SIZE, SIZE]) }); var lg = flip(out.logits.data, f[0], f[1]); for (var i = 0; i < n; i++) total[i] += 1 / (1 + Math.exp(-lg[i])); } for (i = 0; i < n; i++) total[i] /= flips.length; return total; }
function resized(img, w, h) { var c = document.createElement("canvas"); c.width = w; c.height = h; var ctx = c.getContext("2d", { willReadFrequently: true }); ctx.imageSmoothingEnabled = true; ctx.imageSmoothingQuality = "high"; ctx.drawImage(img, 0, 0, w, h); return { canvas: c, data: ctx.getImageData(0, 0, w, h).data }; }
function render() { if (!current) return; var t = +thr.value, img = current.img, prob = current.prob; document.getElementById("thr-val").textContent = t.toFixed(2); var s = Math.min(1, MAX_SIDE / Math.max(img.naturalWidth, img.naturalHeight)); var W = Math.round(img.naturalWidth * s), H = Math.round(img.naturalHeight * s); var out = document.getElementById("out"); out.width = W; out.height = H; var ctx = out.getContext("2d"); ctx.drawImage(img, 0, 0, W, H); var im = ctx.getImageData(0, 0, W, H), d = im.data, mask = new Uint8Array(W * H), area = 0; for (var y = 0; y < H; y++) { // bilinear upsampling of the 256x256 probability map var fy = Math.max(0, Math.min(SIZE - 1, (y + 0.5) * SIZE / H - 0.5)), y0 = Math.floor(fy), y1 = Math.min(y0 + 1, SIZE - 1), wy = fy - y0; for (var x = 0; x < W; x++) { var fx = Math.max(0, Math.min(SIZE - 1, (x + 0.5) * SIZE / W - 0.5)), x0 = Math.floor(fx), x1 = Math.min(x0 + 1, SIZE - 1), wx = fx - x0; var p = (prob[y0 * SIZE + x0] * (1 - wx) + prob[y0 * SIZE + x1] * wx) * (1 - wy) + (prob[y1 * SIZE + x0] * (1 - wx) + prob[y1 * SIZE + x1] * wx) * wy; if (p > t) { mask[y * W + x] = 1; area++; } } } var lw = Math.max(2, Math.round(Math.max(W, H) / 200)); for (y = 0; y < H; y++) for (x = 0; x < W; x++) { var k = y * W + x; if (!mask[k]) continue; var edge = false; for (var dy = -lw; dy <= lw && !edge; dy += lw) for (var dx = -lw; dx <= lw; dx += lw) { var yy = y + dy, xx = x + dx; if (yy < 0 || xx < 0 || yy >= H || xx >= W || !mask[yy * W + xx]) { edge = true; break; } } var j = k * 4; if (edge) { d[j] = 40; d[j + 1] = 90; d[j + 2] = 255; } else { d[j] = 0.65 * d[j] + 0.35 * 40; d[j + 1] = 0.65 * d[j + 1] + 0.35 * 90; d[j + 2] = 0.65 * d[j + 2] + 0.35 * 255; } } ctx.putImageData(im, 0, 0); var heat = document.getElementById("heat").getContext("2d"), hm = heat.createImageData(SIZE, SIZE); for (var i = 0; i < SIZE * SIZE; i++) { var v = prob[i]; hm.data[i * 4] = 255 * v; hm.data[i * 4 + 1] = 120 * v; hm.data[i * 4 + 2] = 255 * (1 - v) * 0.35; hm.data[i * 4 + 3] = 255; } heat.putImageData(hm, 0, 0); var pct = 100 * area / (W * H), v = document.getElementById("verdict"); v.className = "verdict" + (area ? " alert" : ""); v.innerHTML = area ? "<b>Predicted polyp area: " + pct.toFixed(1) + "% of the image</b>" + current.label : "<b>No polyp pixels above the threshold</b>This does not rule out a polyp." + current.label; }
function analyse(src, label) { busy = busy.then(async function () { try { var img = await Demo.loadImage(src); var small = resized(img, SIZE, SIZE); st.set(sessP ? "Running the model…" : "Downloading the model…", null); await session(); st.set("Running the model…", null); var t0 = performance.now(); var prob = await probMap(small.data, tta.checked); current = { img: img, prob: prob, label: "<br><span class='cap'>" + label + "</span>" }; render(); st.set("Segmented on this device in " + Math.round(performance.now() - t0) + " ms" + (tta.checked ? " (4 flipped passes)." : "."), null); } catch (e) { console.error(e); st.set(e.message, null, true); } }); return busy; }
var exBox = document.getElementById("examples"), lastSrc = null, lastLabel = ""; EXAMPLES.forEach(function (name, i) { var b = document.createElement("button"); b.className = "btn small"; b.type = "button"; b.textContent = "Example " + (i + 1); b.addEventListener("click", function () { exBox.querySelectorAll("button").forEach(function (o) { o.setAttribute("aria-pressed", o === b); }); lastSrc = "examples/" + name; lastLabel = "Example " + (i + 1) + " (Wikimedia Commons)"; analyse(lastSrc, lastLabel); }); exBox.append(b); }); document.getElementById("file").addEventListener("change", function (e) { var f = e.target.files[0]; if (!f) return; if (f.size > 20 * 1048576) { st.set("That file is larger than 20 MB.", null, true); return; } exBox.querySelectorAll("button").forEach(function (o) { o.setAttribute("aria-pressed", false); }); lastSrc = f; lastLabel = "Your image (stays on this device)"; analyse(f, lastLabel); }); thr.addEventListener("input", render); tta.addEventListener("change", function () { if (lastSrc) analyse(lastSrc, lastLabel); }); exBox.querySelector("button").click();
// Parity hook (demos/VERIFY.md): feed the exact 256x256 pixels Python used, compare probability maps. window.__demo = { parity: async function () { await busy; var out = {}; for (var k = 1; k <= 3; k++) { var img = await Demo.loadImage("https://rigel08.github.io/portfolio-site/demos/parity/polyp/example_" + k + "_256.png"); var rgba = resized(img, SIZE, SIZE).data, p = await probMap(rgba, true); var res = { }; for (var ref of ["fp32", "fp16"]) { var u = new Uint16Array(await (await fetch("https://rigel08.github.io/portfolio-site/demos/parity/polyp/example_" + k + "_prob_" + ref + ".u16")).arrayBuffer()); var mx = 0, inter = 0, a = 0, b = 0; for (var i = 0; i < u.length; i++) { var q = u[i] / 65535; mx = Math.max(mx, Math.abs(q - p[i])); var m1 = p[i] > 0.4, m2 = q > 0.4; inter += m1 && m2; a += m1; b += m2; } res[ref] = { maxAbs: mx, dice: 2 * inter / Math.max(a + b, 1) }; } // full browser pipeline: canvas resize of the original JPEG instead of OpenCV INTER_AREA var full = await probMap(resized(await Demo.loadImage("examples/example_" + k + ".jpg"), SIZE, SIZE).data, true); u = new Uint16Array(await (await fetch("https://rigel08.github.io/portfolio-site/demos/parity/polyp/example_" + k + "_prob_fp32.u16")).arrayBuffer()); inter = a = b = 0; mx = 0; for (i = 0; i < u.length; i++) { q = u[i] / 65535; mx = Math.max(mx, Math.abs(q - full[i])); m1 = full[i] > 0.4; m2 = q > 0.4; inter += m1 && m2; a += m1; b += m2; } res.browserResize_vs_fp32 = { maxAbs: mx, dice: 2 * inter / Math.max(a + b, 1) }; out["example_" + k] = res; } return out; }, };})();123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125/* Shared helpers for the in-browser demos: page chrome, theme toggle, model loading. ONNX Runtime Web is pinned to 1.31.1 (see the <script> tag in each page). Nothing is uploaded: models and examples are static files, inference runs in this tab with WebAssembly. */(function () { "use strict"; var ORT_VERSION = "1.31.1"; var root = document.documentElement; try { var t = localStorage.getItem("theme"); if (t === "light" || t === "dark") root.dataset.theme = t; } catch (e) {}
var SUN = '<svg class="icon-sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.2"/><path d="M12 2.5v2.2M12 19.3v2.2M4.6 4.6l1.6 1.6M17.8 17.8l1.6 1.6M2.5 12h2.2M19.3 12h2.2M4.6 19.4l1.6-1.6M17.8 6.2l1.6-1.6"/></svg>'; var MOON = '<svg class="icon-moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M20.5 14.2A8.5 8.5 0 0 1 9.8 3.5a8.5 8.5 0 1 0 10.7 10.7z"/></svg>';
function chrome(opts) { var base = opts.base || "https://rigel08.github.io/portfolio-site/"; var header = document.createElement("header"); header.className = "topbar scrolled"; header.innerHTML = '<div class="wrap demo-top">' + '<a class="brand" href="' + base + '"><span class="brand-mark" aria-hidden="true"></span>Srihith Rao Eravelli</a>' + '<nav class="crumbs" aria-label="Demo navigation">' + '<a href="' + base + 'demos/">All demos</a>' + (opts.repo ? '<a class="hide-sm" href="' + opts.repo + '" target="_blank" rel="noopener">Repo ↗</a>' : "") + "</nav>" + '<button class="theme-toggle" type="button">' + SUN + MOON + "</button></div>"; document.body.prepend(header);
var slot = document.querySelector("[data-banner]"); if (slot) { slot.className = "banner"; slot.setAttribute("role", "note"); slot.innerHTML = "<span><strong>Research demo, not for clinical use.</strong> Not a medical device; do not use it for any medical decision.</span>" + '<span class="private">🔒 ' + (opts.privacy || "Your data stays in your browser: the model runs on this device and nothing you choose or upload is sent anywhere.") + "</span>"; }
var foot = document.createElement("footer"); foot.className = "demo-foot"; foot.innerHTML = '<div class="wrap">' + (opts.footer || "") + ' Inference: <a href="https://onnxruntime.ai/docs/tutorials/web/" target="_blank" rel="noopener">ONNX Runtime Web</a> ' + ORT_VERSION + " (WebAssembly), static files on GitHub Pages. " + '<a href="https://github.com/rigel08/portfolio-site/blob/main/demos/VERIFY.md" target="_blank" rel="noopener">How the browser outputs were checked against Python</a>.</div>'; document.body.append(foot);
var toggle = header.querySelector(".theme-toggle"); function current() { if (root.dataset.theme) return root.dataset.theme; return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } function sync() { var next = current() === "dark" ? "light" : "dark"; toggle.setAttribute("aria-label", "Switch to " + next + " mode"); toggle.title = "Switch to " + next + " mode"; } toggle.addEventListener("click", function () { root.dataset.theme = current() === "dark" ? "light" : "dark"; try { localStorage.setItem("theme", root.dataset.theme); } catch (e) {} sync(); document.dispatchEvent(new CustomEvent("themechange")); }); sync(); }
/* fetch with a progress callback (fraction 0..1, or null if the size is unknown) */ async function fetchBytes(url, onProgress) { var res = await fetch(url); if (!res.ok) throw new Error("Could not download " + url + " (HTTP " + res.status + ")"); var total = +res.headers.get("content-length") || 0; if (!res.body || !total) { var buf = await res.arrayBuffer(); onProgress && onProgress(1, buf.byteLength); return new Uint8Array(buf); } var reader = res.body.getReader(), chunks = [], got = 0; for (;;) { var r = await reader.read(); if (r.done) break; chunks.push(r.value); got += r.value.length; onProgress && onProgress(Math.min(got / total, 1), got); } var out = new Uint8Array(got), off = 0; chunks.forEach(function (c) { out.set(c, off); off += c.length; }); return out; }
async function loadSession(url, onProgress) { if (!window.ort) throw new Error("ONNX Runtime Web did not load (blocked CDN?)"); ort.env.wasm.numThreads = 1; // GitHub Pages cannot send the headers that multithreading needs ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@" + ORT_VERSION + "/dist/"; var bytes = await fetchBytes(url, onProgress); return ort.InferenceSession.create(bytes, { executionProviders: ["wasm"], graphOptimizationLevel: "all" }); }
function mb(n) { return (n / 1048576).toFixed(1) + " MB"; } function sigmoid(z) { return 1 / (1 + Math.exp(-z)); }
/* Status line + progress bar bound to an element containing .status and .bar-fill */ function status(el) { var txt = el.querySelector(".status"), bar = el.querySelector(".bar-fill"); return { set: function (msg, frac, isErr) { txt.textContent = msg; txt.classList.toggle("err", !!isErr); if (bar) { bar.style.width = (frac == null ? 0 : Math.round(frac * 100)) + "%"; bar.parentNode.hidden = frac == null; } }, }; }
/* Load an <img>/File/URL into an HTMLImageElement */ function loadImage(src) { return new Promise(function (resolve, reject) { var img = new Image(); img.onload = function () { resolve(img); }; img.onerror = function () { reject(new Error("Could not read that image file.")); }; img.src = typeof src === "string" ? src : URL.createObjectURL(src); }); }
function cssVar(name) { return getComputedStyle(root).getPropertyValue(name).trim(); }
window.Demo = { chrome: chrome, loadSession: loadSession, fetchBytes: fetchBytes, mb: mb, sigmoid: sigmoid, status: status, loadImage: loadImage, cssVar: cssVar, ORT_VERSION: ORT_VERSION };})();12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091/* Shared styles for the in-browser demos. Tokens come from ../styles.css (loaded first). */.demo-top { display: flex; align-items: center; gap: 16px; height: 60px; }.demo-top .crumbs { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }.demo-top .crumbs a { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 999px; }.demo-top .crumbs a:hover { background: var(--bg-tint); color: var(--ink); }
.banner { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin: 18px 0 0; padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); font-size: 14.5px; line-height: 1.5;}.banner strong { color: var(--warn); }.banner .private { color: var(--ink-2); }
.demo-head { padding: 28px 0 8px; }.demo-head h1 { font: 700 clamp(30px, 4.6vw, 46px)/1.08 var(--sans); letter-spacing: -.03em; margin-top: 10px; }.demo-head .lede { color: var(--ink-2); max-width: 70ch; margin-top: 12px; font-size: 16.5px; }
.demo-grid { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 24px; margin: 24px 0 40px; align-items: start; }.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }.panel h2 { font: 650 13px/1.2 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 12px; }.panel h2:not(:first-child) { margin-top: 22px; }.field { display: grid; gap: 6px; margin-bottom: 14px; }.field label, .field .lbl { font-size: 13.5px; color: var(--ink-2); font-weight: 600; }select, input[type="file"] { font: inherit; font-size: 14.5px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }input[type="range"] { width: 100%; accent-color: var(--accent); }.seg { display: grid; gap: 6px; }.seg label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 14px; color: var(--ink-2); background: var(--bg); }.seg input { accent-color: var(--accent); }.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }.btn.small { padding: 8px 14px; font-size: 14px; }.btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.status { font-size: 13.5px; color: var(--ink-3); margin-top: 10px; min-height: 1.4em; font-variant-numeric: tabular-nums; }.status.err { color: #c2410c; }.bar-track { height: 4px; background: var(--bg-tint); border-radius: 4px; overflow: hidden; margin-top: 8px; }.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.probs { display: grid; gap: 10px; }.prob { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 14px; }.prob .name { color: var(--ink-2); }.prob .name b { color: var(--ink); }.prob .val { font-variant-numeric: tabular-nums; font-weight: 650; }.prob .track { grid-column: 1 / -1; position: relative; height: 8px; background: var(--bg-tint); border-radius: 6px; overflow: visible; }.prob .fill { height: 100%; border-radius: 6px; background: var(--ink-3); }.prob.flag .fill { background: var(--accent); }.prob .tick { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--ink); opacity: .55; }.verdict { margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--bg-tint); font-size: 15px; }.verdict b { display: block; font-size: 18px; margin-bottom: 2px; }.verdict.alert { background: var(--accent-soft); }.note { font-size: 13.5px; color: var(--ink-3); margin-top: 12px; line-height: 1.55; }.note code, .mono { font-family: var(--mono); font-size: 12.5px; }
.canvas-wrap { position: relative; width: 100%; }.canvas-wrap canvas { display: block; width: 100%; height: auto; border-radius: 10px; background: var(--bg); }.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }.pair figure { margin: 0; }.pair figcaption, .cap { font-size: 13px; color: var(--ink-3); margin-top: 6px; }.kv { width: 100%; border-collapse: collapse; font-size: 14.5px; }.kv td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }.flags { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; font-size: 14.5px; }.flags li { padding: 8px 12px; border-radius: 10px; background: var(--bg-tint); }.flags li.on { background: var(--warn-soft); color: var(--ink); }.flags li.on::before { content: "⚠ "; color: var(--warn); }
.demo-foot { border-top: 1px solid var(--line); padding: 24px 0 40px; color: var(--ink-3); font-size: 13.5px; }.demo-foot a { color: var(--ink-2); }
/* Demos index */.demo-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin: 28px 0 48px; }.demo-card { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; text-decoration: none; color: var(--ink); transition: transform .15s, box-shadow .15s; }.demo-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }.demo-card h2 { font: 700 22px/1.15 var(--sans); letter-spacing: -.02em; }.demo-card p { color: var(--ink-2); font-size: 15px; }.demo-card .meta { margin-top: auto; font-size: 13px; color: var(--ink-3); }.demo-card .go { color: var(--accent-ink); font-weight: 650; font-size: 15px; }.kind { display: inline-block; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }.kind.replay { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 860px) { .demo-grid { grid-template-columns: 1fr; }}@media (max-width: 520px) { .pair { grid-template-columns: 1fr; } .demo-top .crumbs a.hide-sm { display: none; } .panel { padding: 16px; }}.demo-card .kind { align-self: flex-start; }1234567891011# Example image credits
All three come from Wikimedia Commons. Each was re-saved as JPEG (removing camera metadata) andshrunk to at most 1000 pixels. They have **no expert masks**, so they illustrate the demo and arenot evidence of accuracy. The code licence of this demo does not change the licences below.
| File | Original | Author | Licence | Further change ||---|---|---|---|---|| example_1.jpg | [Polyp.jpeg](https://commons.wikimedia.org/wiki/File:Polyp.jpeg) | Stephen Holland, M.D., Naperville Gastroenterology | [CC BY 2.5](https://creativecommons.org/licenses/by/2.5/) | none || example_2.jpg | [Colon polyp (Telugu title)](https://commons.wikimedia.org/wiki/File:%E0%B0%AA%E0%B1%86%E0%B0%A6%E0%B1%8D%E0%B0%A6%E0%B0%AA%E0%B1%8D%E0%B0%B0%E0%B1%87%E0%B0%B5%E0%B1%81%E0%B0%B2%E0%B1%8B_%E0%B0%95%E0%B0%82%E0%B0%A4%E0%B0%BF_(Colon_polyp).jpeg) | డా. గన్నవరపు నరసింహమూర్తి | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | none || example_3.jpg | [Polypectomy.jpg](https://commons.wikimedia.org/wiki/File:Polypectomy.jpg) | Gilo1969 | [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) (this crop is shared under the same licence) | cropped to the left panel, white border removed |12345678910111213141516171819<!doctype html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><link rel="stylesheet" href="style.css" /></head><body><div class="card"><h1>Welcome to your static Space!</h1><p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p><p>Also don't forget to check the<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.</p></div></body></html>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>PolypShift · live polyp segmentation demo</title><meta name="description" content="Live in-browser demo: a ResNet34 U-Net outlines colon polyps. Runs on your device with ONNX Runtime Web."><meta name="color-scheme" content="light dark"><link rel="icon" href="assets/favicon.svg" type="image/svg+xml"><link rel="stylesheet" href="styles.css"><link rel="stylesheet" href="demo.css"><script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.31.1/dist/ort.wasm.min.js" integrity="sha384-tNxIwEqSlcdvKtUte98AsccPbDKM958LBXB/+3BLS42TTihXHKTWgdqPqXI/lot8" crossorigin="anonymous"></script><script src="common.js"></script></head><body><main class="wrap"><div data-banner></div><div class="demo-head"><span class="eyebrow">L2 · Live demo · Colonoscopy</span><h1>PolypShift: outline a polyp, on your device</h1><p class="lede">A ResNet34 U-Net trained on Kvasir-SEG marks every pixel it thinks is polyp. It scores Dice 0.894 on held-out Kvasir images but 0.649 to 0.754 on other hospitals' equipment. Try an example or your own image and move the threshold.</p></div><div class="demo-grid"><section class="panel" aria-label="Controls and results"><h2>Input</h2><div class="field"><span class="lbl">Example (Wikimedia Commons, no expert masks)</span><div class="btn-row" id="examples"></div></div><div class="field"><label for="file">…or your own colonoscopy image</label><input type="file" id="file" accept="image/png,image/jpeg,image/webp"></div><div class="field"><label for="thr">Threshold: <span id="thr-val" class="mono">0.40</span> <span class="cap">(0.40 chosen on validation)</span></label><input type="range" id="thr" min="0.05" max="0.95" step="0.05" value="0.4"></div><div class="field"><label><input type="checkbox" id="tta" checked> Flip test-time augmentation (4 passes, as evaluated)</label></div><div id="load"><div class="status">Loading…</div><div class="bar-track"><div class="bar-fill"></div></div></div><h2>Model output</h2><div class="verdict" id="verdict">Waiting for the model…</div><p class="note">The area is a share of the picture, not a physical size: it changes with camera distance. An empty mask does not rule out a polyp. Every training image contained a polyp, so the model can also mark normal tissue.</p><p class="note">Model: ONNX export of the shipped U-Net with its weights stored in 16-bit (49 MB, computed in 32-bit). Downloaded once, then cached by your browser.</p></section><section class="panel" aria-label="Segmentation"><h2>Predicted polyp (blue)</h2><div class="pair"><figure><div class="canvas-wrap"><canvas id="out" width="512" height="512" role="img" aria-label="Image with predicted polyp mask"></canvas></div><figcaption>Mask overlay at the chosen threshold</figcaption></figure><figure><div class="canvas-wrap"><canvas id="heat" width="256" height="256" role="img" aria-label="Probability map"></canvas></div><figcaption>Raw probability map (256 × 256 model input)</figcaption></figure></div></section></div></main><script src="app.js"></script></body></html>
123version https://git-lfs.github.com/spec/v1oid sha256:b22d2cf7cbbaba828636c1b9430fc036f2852a64cecfd32cf12b33d1e0881c32size 4916479312345678910111213141516171819202122232425262728body { padding: 2rem; font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;}
h1 { font-size: 16px; margin-top: 0;}
p { color: rgb(107, 114, 128); font-size: 15px; margin-bottom: 10px; margin-top: 5px;}
.card { max-width: 620px; margin: 0 auto; padding: 16px; border: 1px solid lightgray; border-radius: 16px;}
.card p:last-child { margin-bottom: 0;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295/* ---------- Tokens ---------- */:root { --bg: #faf9f6; --bg-tint: #f1efe9; --surface: #ffffff; --ink: #15171c; --ink-2: #4a4f5a; --ink-3: #737885; --line: #e3e0d8; --accent: #0f766e; --accent-ink: #0b5f58; --accent-soft: #e2f1ef; --warn: #9a5b00; --warn-soft: #fbefd9; --shadow: 0 1px 2px rgba(20, 22, 28, .04), 0 8px 28px -12px rgba(20, 22, 28, .12); --radius: 18px; --maxw: 1160px; --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif; --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color-scheme: light;}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0d1014; --bg-tint: #12161c; --surface: #161b22; --ink: #ecebe7; --ink-2: #b4b8c0; --ink-3: #8a909b; --line: #262c35; --accent: #5fd4c4; --accent-ink: #7fe3d5; --accent-soft: #123a37; --warn: #f3c06b; --warn-soft: #3a2c12; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6); color-scheme: dark; }}:root[data-theme="dark"] { --bg: #0d1014; --bg-tint: #12161c; --surface: #161b22; --ink: #ecebe7; --ink-2: #b4b8c0; --ink-3: #8a909b; --line: #262c35; --accent: #5fd4c4; --accent-ink: #7fe3d5; --accent-soft: #123a37; --warn: #f3c06b; --warn-soft: #3a2c12; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6); color-scheme: dark;}
/* ---------- Base ---------- */*, *::before, *::after { box-sizing: border-box; }html { scroll-behavior: smooth; scroll-padding-top: 76px; -webkit-text-size-adjust: 100%; }body { margin: 0; background: var(--bg); color: var(--ink); font: 16.5px/1.6 var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; transition: background-color .25s ease, color .25s ease;}img { max-width: 100%; height: auto; display: block; }a { color: var(--accent-ink); text-underline-offset: 3px; }h1, h2, h3 { line-height: 1.15; margin: 0; letter-spacing: -.01em; }p { margin: 0; }em { font-style: italic; }:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }.skip:focus { left: 8px; }
/* ---------- Top bar ---------- */.topbar { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px); border-bottom: 1px solid transparent; transition: border-color .2s ease;}.topbar.scrolled { border-bottom-color: var(--line); }.topbar-inner { display: flex; align-items: center; gap: 20px; height: 60px; }.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }.brand-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }.nav { margin-left: auto; display: flex; gap: 4px; }.nav a { color: var(--ink-2); text-decoration: none; font-size: 14.5px; padding: 6px 12px; border-radius: 999px; transition: background .15s, color .15s; }.nav a:hover, .nav a.active { color: var(--ink); background: var(--bg-tint); }.theme-toggle { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: grid; place-items: center; flex: none; transition: border-color .15s, transform .15s;}.theme-toggle:hover { border-color: var(--ink-3); }.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }.theme-toggle .icon-moon { fill: currentColor; stroke: none; }.icon-moon { display: none; }:root[data-theme="dark"] .icon-sun { display: none; }:root[data-theme="dark"] .icon-moon { display: block; }@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .icon-sun { display: none; } :root:not([data-theme="light"]) .icon-moon { display: block; }}
/* ---------- Hero ---------- */.hero { padding-top: 88px; padding-bottom: 72px; }.eyebrow, .kicker { font: 600 12.5px/1.2 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink);}.hero-title { font: 700 clamp(44px, 7vw, 76px)/1.02 var(--sans); letter-spacing: -.035em; margin-top: 18px; }.hero-theme { font-family: var(--serif); font-size: clamp(24px, 3.3vw, 36px); line-height: 1.28; max-width: 24ch; margin-top: 22px; color: var(--ink); letter-spacing: -.005em;}.hero-theme em { color: var(--accent-ink); }.hero-sub { max-width: 60ch; margin-top: 22px; color: var(--ink-2); font-size: 17.5px; }.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }.btn { display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 550; font-size: 15px; transition: transform .15s ease, border-color .15s, box-shadow .15s;}.btn:hover { transform: translateY(-1px); border-color: var(--ink-3); box-shadow: var(--shadow); }.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }.btn-primary:hover { border-color: var(--ink); }.btn .gh { width: 17px; height: 17px; fill: currentColor; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 56px 0 0; border-top: 1px solid var(--line);}.stat { padding: 22px 24px 0 0; }.stat + .stat { padding-left: 24px; border-left: 1px solid var(--line); }.stat dt { color: var(--ink-3); font-size: 13.5px; line-height: 1.4; }.stat dd { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; }.stat .num { display: block; font: 650 26px/1.15 var(--sans); color: var(--ink); letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
/* ---------- Sections ---------- */.section { padding-top: 88px; padding-bottom: 88px; }.section-tint { background: var(--bg-tint); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }.section-head { margin-bottom: 40px; }.section-head h2 { font: 700 clamp(30px, 4vw, 42px)/1.1 var(--sans); letter-spacing: -.025em; margin-top: 12px; }.section-lede { color: var(--ink-2); max-width: 62ch; margin-top: 14px; }
/* ---------- Projects ---------- */.projects { display: grid; gap: 24px; }.project { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 36px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow);}.project-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }.project-idx { font: 600 12px/1 var(--mono); color: var(--accent-ink); background: var(--accent-soft); padding: 5px 8px; border-radius: 6px;}.project-domain { font-size: 13px; color: var(--ink-3); }.badge { font: 600 11.5px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--warn); background: var(--warn-soft); padding: 6px 9px; border-radius: 999px;}.project h3 { font: 700 28px/1.1 var(--sans); letter-spacing: -.02em; margin-top: 14px; }.hook { margin-top: 10px; color: var(--ink-2); font-size: 16.5px; }.metric { margin-top: 20px; padding: 14px 0 14px 16px; border-left: 3px solid var(--accent); }.metric-value { display: block; font: 700 36px/1.05 var(--sans); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }.metric-label { display: block; margin-top: 6px; font-size: 13.5px; line-height: 1.5; color: var(--ink-3); }.found { margin-top: 16px; font-size: 15px; color: var(--ink-2); }.found strong { display: block; color: var(--ink); font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }.wip { color: var(--warn); font-weight: 600; }.tags { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }.tags li { font-size: 12.5px; color: var(--ink-2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; background: var(--bg); }.repo { display: inline-flex; gap: 6px; margin-top: 20px; font-weight: 600; font-size: 15px; text-decoration: none; }.repo:hover { text-decoration: underline; }.repo-soon { color: var(--ink-3); font-weight: 500; }.repo-soon::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); align-self: center; }
.figure { display: block; background: #fff; border-radius: 12px; padding: 10px; border: 1px solid var(--line); overflow: hidden; cursor: zoom-in; transition: transform .2s ease, box-shadow .2s ease;}.figure:hover { transform: translateY(-2px); box-shadow: var(--shadow); }.figure img { width: 100%; border-radius: 6px; }.figure-square { max-width: 420px; justify-self: center; width: 100%; }
/* ---------- Shortcuts ---------- */.shortcuts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }.shortcut { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);}.shortcut-where { font: 600 12px/1.2 var(--mono); color: var(--accent-ink); }.shortcut h3 { font: 700 21px/1.2 var(--sans); }.shortcut p { color: var(--ink-2); font-size: 15px; }.shortcut .caveat { margin-top: auto; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13.5px; color: var(--ink-3); }.drops { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 8px; }.drops li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: 14.5px; color: var(--ink-2); }.drops b { font: 650 18px/1 var(--sans); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* ---------- Methods ---------- */.methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }.method { background: var(--bg); padding: 24px; }.method h3 { font: 650 16.5px/1.25 var(--sans); }.method h3::before { content: ""; display: block; width: 22px; height: 3px; border-radius: 2px; background: var(--accent); margin-bottom: 14px; }.method p { margin-top: 8px; color: var(--ink-2); font-size: 14.5px; line-height: 1.55; }
/* ---------- Skills / About ---------- */.about-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 64px; }.skills { margin: 0; display: grid; gap: 0; }.skills div { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }.skills div:last-child { border-bottom: 1px solid var(--line); }.skills dt { font-weight: 600; font-size: 14.5px; }.skills dd { margin: 0; color: var(--ink-2); font-size: 14.5px; }.about p { color: var(--ink-2); }.about p + p { margin-top: 14px; }.ph { background: var(--warn-soft); color: var(--warn); border-radius: 4px; padding: 0 4px; font-size: .95em; }.links { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }.links a, .links span { font-size: 15px; font-weight: 550; }.ph-link { color: var(--warn); }
/* ---------- Footer ---------- */.footer { padding: 36px 0 48px; color: var(--ink-3); font-size: 13.5px; }.footer-inner { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }.footer a { color: var(--ink-2); text-decoration: none; }
/* ---------- Motion (subtle, opt-out) ---------- */.js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .6s ease, transform .6s ease; }.js .reveal.in { opacity: 1; transform: none; }@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .js .reveal { opacity: 1; transform: none; transition: none; } .btn, .figure, body { transition: none; }}
/* ---------- Responsive ---------- */@media (max-width: 980px) { .project { grid-template-columns: 1fr; gap: 24px; } .shortcuts { grid-template-columns: 1fr; } .methods { grid-template-columns: repeat(2, 1fr); } .about-grid { grid-template-columns: 1fr; gap: 48px; }}@media (max-width: 680px) { body { font-size: 16px; } .wrap { padding: 0 18px; } .nav { display: none; } .topbar-inner { justify-content: space-between; } .hero { padding-top: 48px; padding-bottom: 52px; } .hero-stats { grid-template-columns: 1fr; margin-top: 40px; } .stat, .stat + .stat { padding: 18px 0; border-left: 0; } .stat + .stat { border-top: 1px solid var(--line); } .section { padding-top: 60px; padding-bottom: 60px; } .project { padding: 22px; border-radius: 16px; } .project h3 { font-size: 25px; } .metric-value { font-size: 31px; } .figure { padding: 6px; } .methods { grid-template-columns: 1fr; } .skills div { grid-template-columns: 1fr; gap: 4px; }}
/* ---------- Small polish ---------- */.nw { white-space: nowrap; }.hero-theme { max-width: 28ch; }.figure { position: relative; }.figure::after { content: "Open full size ↗"; position: absolute; right: 14px; bottom: 14px; font: 600 11.5px/1 var(--sans); color: #15171c; background: rgba(255, 255, 255, .92); border: 1px solid #e3e0d8; padding: 6px 9px; border-radius: 999px; opacity: 0; transition: opacity .2s ease;}.figure:hover::after, .figure:focus-visible::after { opacity: 1; }@media (hover: none) { .figure::after { content: "Tap to enlarge"; opacity: 1; position: static; display: block; text-align: center; margin-top: 6px; border: 0; background: none; color: #737885; font-weight: 500; } }.repo-links { display: flex; flex-wrap: wrap; gap: 6px 22px; }
/* "Try it live" links to the in-browser demos */.repo-links .try-live, .try-live { display: inline-flex; align-items: center; gap: 6px; margin-top: 20px; padding: 7px 14px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 650; font-size: 14.5px; text-decoration: none; transition: transform .15s, box-shadow .15s;}:root[data-theme="dark"] .try-live { color: #0d1014; }@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .try-live { color: #0d1014; } }.try-live:hover { transform: translateY(-1px); box-shadow: var(--shadow); }.try-live .try-note { font-weight: 500; opacity: .85; }.repo-links { align-items: center; }.gitattributes+1
README.md+13-5
app.jsAdded+159
assets/favicon.svgAdded
common.jsAdded+125
demo.cssAdded+91
examples/ATTRIBUTION.mdAdded+11
examples/example_1.jpgAdded

examples/example_2.jpgAdded

Large File Pointer Details
- SHA256: 54320f6cd1fbb204066488e53c45207dd28b12a2a7ac6dfdfeb09c4a733fa139
- Pointer size: 131 Bytes
- Size of remote file: 301 kB
examples/example_3.jpgAdded

index.html+59-17
models/polyp_unet_fp16.onnxAdded+3
style.cssDeleted-28
styles.cssAdded+295