Download index.html from akhaliq/DepthPro2: direct link, hf CLI and curl.
- Browser
- Download file 13.1 kB
-
https://huggingface.co/spaces/akhaliq/DepthPro2/resolve/main/index.html
- Command line
-
hf download hf://spaces/akhaliq/DepthPro2/index.html
-
curl -L -o index.html https://huggingface.co/spaces/akhaliq/DepthPro2/resolve/main/index.html
13.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Depth Pro 2</title> | |
| <style> | |
| :root { | |
| --text: #1d1d1f; --text-2: #6e6e73; --accent: #0071e3; | |
| --fill: #f5f5f7; --line: #e8e8ed; | |
| } | |
| * { box-sizing: border-box; } | |
| body { | |
| margin: 0; background: #fff; color: var(--text); | |
| font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif; | |
| -webkit-font-smoothing: antialiased; | |
| display: flex; flex-direction: column; align-items: center; padding: 56px 20px 72px; | |
| } | |
| header { text-align: center; max-width: 760px; margin-bottom: 44px; } | |
| h1 { font-size: clamp(48px, 9vw, 80px); font-weight: 700; letter-spacing: -0.035em; margin: 0; } | |
| .subtitle { font-size: clamp(19px, 3.2vw, 28px); font-weight: 600; color: var(--text-2); margin: 14px 0 24px; } | |
| .authors { font-size: 14px; color: var(--text-2); line-height: 1.7; margin: 0; } | |
| .affil { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 10px 0 0; } | |
| .windows { | |
| width: min(1060px, 100%); | |
| display: grid; grid-template-columns: 1fr 1fr; gap: 20px; | |
| } | |
| @media (max-width: 720px) { .windows { grid-template-columns: 1fr; } } | |
| .win { | |
| position: relative; aspect-ratio: 4 / 3; border-radius: 24px; overflow: hidden; | |
| background: var(--fill); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.28), 0 2px 10px rgba(0, 0, 0, 0.06); | |
| } | |
| .win.dragover { outline: 3px dashed var(--accent); outline-offset: -12px; } | |
| .win.clickable { cursor: pointer; } | |
| .label { | |
| position: absolute; top: 14px; left: 14px; z-index: 4; padding: 6px 14px; border-radius: 980px; | |
| background: rgba(29, 29, 31, 0.75); color: #fff; font-size: 13px; font-weight: 600; | |
| pointer-events: none; backdrop-filter: blur(6px); | |
| } | |
| .win img, .win video { | |
| position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; | |
| background: #0b0b12; user-select: none; -webkit-user-drag: none; | |
| } | |
| .pane { | |
| position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; | |
| align-items: center; justify-content: center; text-align: center; padding: 20px; | |
| } | |
| .pane .glyph { | |
| width: 64px; height: 64px; border-radius: 20px; background: #fff; | |
| box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08); | |
| display: flex; align-items: center; justify-content: center; font-size: 28px; | |
| } | |
| .pane strong { font-size: 18px; font-weight: 600; } | |
| .pane .hint { font-size: 14px; color: var(--text-2); max-width: 340px; } | |
| .pane .fine { font-size: 12px; color: #a1a1a6; } | |
| .pane .link { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; } | |
| .pane input { display: none; } | |
| .cta { | |
| margin-top: 6px; padding: 11px 24px; border-radius: 980px; border: none; cursor: pointer; | |
| background: var(--accent); color: #fff; font-size: 15px; font-weight: 500; | |
| font-family: inherit; transition: transform 0.15s ease, opacity 0.15s ease; | |
| } | |
| .cta:hover { opacity: 0.9; } | |
| .cta:active { transform: scale(0.97); } | |
| #outPlaceholder .spin { | |
| width: 34px; height: 34px; border-radius: 50%; | |
| border: 3px solid rgba(29, 29, 31, 0.15); border-top-color: var(--accent); | |
| animation: spin 0.9s linear infinite; | |
| } | |
| #outPlaceholder .spin { display: none; } | |
| #outPlaceholder.working .spin { display: block; } | |
| #outPlaceholder.working strong { color: var(--text-2); } | |
| #busy { | |
| position: absolute; inset: 0; z-index: 5; display: none; | |
| flex-direction: column; gap: 14px; align-items: center; justify-content: center; | |
| background: rgba(11, 11, 18, 0.55); color: #fff; font-size: 15px; font-weight: 600; | |
| text-align: center; padding: 20px; backdrop-filter: blur(3px); | |
| } | |
| #busy.on { display: flex; } | |
| #busy .spin { | |
| width: 38px; height: 38px; border-radius: 50%; | |
| border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: #fff; | |
| animation: spin 0.9s linear infinite; | |
| } | |
| #busy.error { color: #ffb4b4; } | |
| #busy.error .spin { display: none; } | |
| @keyframes spin { to { transform: rotate(360deg); } } | |
| #status { min-height: 22px; margin: 20px 0 0; font-size: 14px; color: var(--text-2); text-align: center; } | |
| #status.error { color: #c02626; font-weight: 600; } | |
| footer { margin-top: 36px; font-size: 12px; color: #a1a1a6; text-align: center; line-height: 1.7; } | |
| footer a { color: var(--text-2); } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <h1>Depth Pro 2</h1> | |
| <p class="subtitle">Sharp and Temporally Consistent Metric Monocular Depth</p> | |
| <p class="authors">Peiyun Hu, Marko Mihajlovic, Lyndon Duong, Lahav Lipson, Wei Dong,<br> | |
| Amaël Delaunoy, Stephan R. Richter, Vladlen Koltun</p> | |
| <p class="affil">Apple</p> | |
| </header> | |
| <div class="windows"> | |
| <div class="win clickable" id="inWin"> | |
| <span class="label">Input</span> | |
| <img id="srcImg" alt="input" hidden> | |
| <video id="srcVid" muted loop playsinline hidden></video> | |
| <div class="pane" id="drop"> | |
| <div class="glyph">📷</div> | |
| <strong>Drop an image or video</strong> | |
| <span class="hint">Metric depth for every pixel, in meters</span> | |
| <button class="cta" id="browse">Choose photo or video</button> | |
| <span class="fine">or try an <span class="link" id="example">example image</span> · | |
| videos: first 60 frames, up to 960 px</span> | |
| <input type="file" id="file" accept="image/*,video/*"> | |
| </div> | |
| </div> | |
| <div class="win" id="outWin"> | |
| <span class="label">Depth Pro 2</span> | |
| <img id="depthImg" alt="depth" hidden> | |
| <video id="depthVid" muted loop playsinline hidden></video> | |
| <div class="pane" id="outPlaceholder"> | |
| <div class="spin"></div> | |
| <strong id="outTitle">Depth appears here</strong> | |
| <span class="hint">Red is near, blue is far, white is the infinitely far — distances in meters</span> | |
| </div> | |
| <div id="busy"><div class="spin"></div><span id="busyText"></span></div> | |
| </div> | |
| </div> | |
| <p id="status"></p> | |
| <footer> | |
| Runs <a href="https://huggingface.co/apple/DepthPro2-H">apple/DepthPro2-H</a> (872M, bfloat16) on ZeroGPU · | |
| <a href="https://github.com/apple-aiml-research/ml-depth-pro-2">research use only</a> | |
| </footer> | |
| <script> | |
| // UI wiring must not depend on any import: clicks always respond, even before or without the | |
| // Gradio client. The client is imported on demand inside the first request. | |
| const $ = (id) => document.getElementById(id); | |
| const inWin = $("inWin"), outWin = $("outWin"); | |
| const drop = $("drop"), outPlaceholder = $("outPlaceholder"), outTitle = $("outTitle"); | |
| const srcImg = $("srcImg"), srcVid = $("srcVid"), depthImg = $("depthImg"), depthVid = $("depthVid"); | |
| const status = $("status"); | |
| const busy = $("busy"), busyText = $("busyText"); | |
| const fileInput = $("file"); | |
| let clientPromise = null; | |
| function setStatus(text, error = false, spin = true) { | |
| status.textContent = text; | |
| status.classList.toggle("error", error); | |
| busy.classList.toggle("on", !error && spin && text !== ""); | |
| busy.classList.toggle("error", error); | |
| busyText.textContent = text; | |
| } | |
| window.addEventListener("error", (e) => setStatus(`Script error: ${e.message}`, true)); | |
| window.addEventListener("unhandledrejection", (e) => | |
| setStatus(`Error: ${e.reason?.message || e.reason}`, true)); | |
| function show(kind, sourceUrl, depthUrl) { | |
| drop.style.display = "none"; | |
| outPlaceholder.style.display = "none"; | |
| const isVideo = kind === "video"; | |
| srcImg.hidden = isVideo; depthImg.hidden = isVideo; | |
| srcVid.hidden = !isVideo; depthVid.hidden = !isVideo; | |
| if (isVideo) { | |
| srcVid.src = sourceUrl; depthVid.src = depthUrl; | |
| const sync = () => { depthVid.currentTime = srcVid.currentTime; }; | |
| srcVid.addEventListener("loadeddata", sync, { once: true }); | |
| // Some uploads (e.g. iPhone HEVC) cannot decode in Chrome at all \u2014 the depth result is | |
| // still valid, so say so instead of failing the whole view. | |
| srcVid.onerror = () => | |
| setStatus(`The original video format cannot be played by this browser \u2014 the depth result is unaffected.`, false, false); | |
| srcVid.play(); depthVid.play(); | |
| depthVid.onerror = () => setStatus("The depth video failed to load.", true); | |
| } else { | |
| srcImg.src = sourceUrl; depthImg.src = depthUrl; | |
| depthImg.onload = () => | |
| setStatus(`\u2713 Depth loaded \u2014 click the input window to try another photo`, false, false); | |
| depthImg.onerror = () => | |
| setStatus(`The depth output failed to decode (${Math.round(depthUrl.length / 1024)} KB received) \u2014 reload the page and try once more.`, true); | |
| } | |
| } | |
| const CLIENT_SOURCES = [ | |
| "/gradio-client.js", | |
| "https://cdn.jsdelivr.net/npm/@gradio/client@2.7.1/dist/index.min.js", | |
| "https://unpkg.com/@gradio/client@2.7.1/dist/index.min.js", | |
| "https://cdn.statically.io/npm/@gradio/client@2.7.1/dist/index.min.js", | |
| ]; | |
| async function loadClientModule() { | |
| for (const src of CLIENT_SOURCES) { | |
| try { | |
| return await import(src); | |
| } catch (err) { | |
| console.error("Client source failed:", src, err); | |
| } | |
| } | |
| throw new Error("Could not load the Gradio client from this Space or any CDN."); | |
| } | |
| let handleFile = null; | |
| async function getClient() { | |
| if (!clientPromise) { | |
| clientPromise = loadClientModule().then((m) => { | |
| handleFile = m.handle_file; | |
| return m.Client.connect(window.location.origin); | |
| }); | |
| } | |
| return clientPromise; | |
| } | |
| async function processFile(file) { | |
| if (!file) return; | |
| const isVideo = file.type.startsWith("video/"); | |
| const sourceUrl = URL.createObjectURL(file); | |
| // The input window shows the source immediately; the output window shows work in progress. | |
| drop.style.display = "none"; | |
| outPlaceholder.style.display = ""; | |
| outPlaceholder.classList.add("working"); | |
| outTitle.textContent = `Estimating depth${isVideo ? " (first 60 frames)" : ""}\u2026`; | |
| if (isVideo) { | |
| srcImg.hidden = true; srcVid.hidden = false; | |
| srcVid.src = sourceUrl; srcVid.play(); | |
| } else { | |
| srcVid.hidden = true; srcImg.hidden = false; | |
| srcImg.src = sourceUrl; | |
| } | |
| try { | |
| const client = await getClient(); | |
| const result = await client.predict(isVideo ? "/predict_depth_video" : "/predict_depth", { | |
| [isVideo ? "video" : "image"]: handleFile(file), | |
| }); | |
| const payload = result.data?.[0]; | |
| let depthUrl = typeof payload === "string" ? payload : payload?.image_data; | |
| if (!depthUrl || depthUrl === sourceUrl) { | |
| throw new Error( | |
| `The server returned no depth output \u2014 payload: ${JSON.stringify(payload)?.slice(0, 160)}`, | |
| ); | |
| } | |
| if (isVideo && depthUrl.startsWith("data:")) { | |
| // Chrome refuses large data-URI videos ("no supported source") but has no limit on | |
| // blob URLs \u2014 decode the data URI into a blob and hand the player that instead. | |
| depthUrl = URL.createObjectURL(await (await fetch(depthUrl)).blob()); | |
| } | |
| outPlaceholder.classList.remove("working"); | |
| show(isVideo ? "video" : "image", sourceUrl, depthUrl); | |
| setStatus(""); | |
| } catch (err) { | |
| console.error(err); | |
| outPlaceholder.classList.remove("working"); | |
| outTitle.textContent = "Depth appears here"; | |
| setStatus(String(err?.message || err), true); | |
| } | |
| } | |
| $("browse").addEventListener("click", (e) => { e.stopPropagation(); fileInput.click(); }); | |
| inWin.addEventListener("click", () => fileInput.click()); | |
| fileInput.addEventListener("change", () => { | |
| if (fileInput.files.length) processFile(fileInput.files[0]); | |
| fileInput.value = ""; | |
| }); | |
| for (const type of ["dragenter", "dragover"]) { | |
| inWin.addEventListener(type, (e) => { e.preventDefault(); inWin.classList.add("dragover"); }); | |
| } | |
| for (const type of ["dragleave", "drop"]) { | |
| inWin.addEventListener(type, (e) => { e.preventDefault(); inWin.classList.remove("dragover"); }); | |
| } | |
| inWin.addEventListener("drop", (e) => { | |
| const file = e.dataTransfer?.files?.[0]; | |
| if (file) processFile(file); | |
| }); | |
| // Wikimedia's thumbnail endpoint returns HTTP 400 for this file, so fetch the original and | |
| // decode-validate it before sending — an error page saved as example.jpg once reached the server. | |
| const EXAMPLE_URL = "https://upload.wikimedia.org/wikipedia/commons/6/68/Orange_tabby_cat_sitting_on_fallen_leaves-Hisashi-01A.jpg"; | |
| async function fetchExampleFile() { | |
| const blob = await (await fetch(EXAMPLE_URL)).blob(); | |
| try { | |
| await createImageBitmap(blob); | |
| } catch (err) { | |
| throw new Error("The example image could not be fetched as a valid picture \u2014 try uploading one instead."); | |
| } | |
| return new File([blob], "example.jpg", { type: blob.type || "image/jpeg" }); | |
| } | |
| $("example").addEventListener("click", async (e) => { | |
| e.stopPropagation(); | |
| setStatus("Fetching the example image\u2026"); | |
| try { | |
| await processFile(await fetchExampleFile()); | |
| } catch (err) { | |
| console.error(err); | |
| setStatus(String(err?.message || err), true); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |