akhaliq HF Staff commited on
Commit
5b574e8
·
verified ·
1 Parent(s): 2ec90db

Two separate windows: input left, depth output right; slider removed

Browse files
Files changed (1) hide show
  1. index.html +87 -100
index.html CHANGED
@@ -16,78 +16,63 @@
16
  -webkit-font-smoothing: antialiased;
17
  display: flex; flex-direction: column; align-items: center; padding: 56px 20px 72px;
18
  }
19
- header { text-align: center; max-width: 760px; }
20
  h1 { font-size: clamp(48px, 9vw, 80px); font-weight: 700; letter-spacing: -0.035em; margin: 0; }
21
  .subtitle { font-size: clamp(19px, 3.2vw, 28px); font-weight: 600; color: var(--text-2); margin: 14px 0 24px; }
22
  .authors { font-size: 14px; color: var(--text-2); line-height: 1.7; margin: 0; }
23
  .affil { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 10px 0 0; }
24
- header { margin-bottom: 44px; }
25
- .btn {
26
- display: inline-flex; align-items: center; gap: 8px; padding: 12px 22px;
27
- border-radius: 980px; font-size: 15px; font-weight: 500; text-decoration: none;
28
- transition: transform 0.15s ease, opacity 0.15s ease;
29
  }
30
- .btn:active { transform: scale(0.97); }
31
- .btn.dark { background: var(--text); color: #fff; }
32
- .btn.dark:hover { opacity: 0.85; }
33
- .btn.ghost { background: var(--fill); color: var(--text); border: 1px solid var(--line); }
34
- .btn.ghost:hover { background: #ebebef; }
35
- .btn .soon { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; opacity: 0.55; }
36
- .stage {
37
- position: relative; width: min(880px, 100%); aspect-ratio: 16 / 10;
38
- border-radius: 28px; overflow: hidden; background: var(--fill);
39
- box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.28), 0 2px 10px rgba(0, 0, 0, 0.06);
40
- transition: box-shadow 0.25s ease;
41
  }
42
- .stage.dragover { outline: 3px dashed var(--accent); outline-offset: -14px; }
43
- #drop {
44
- position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
 
 
 
 
 
 
 
 
 
 
45
  align-items: center; justify-content: center; text-align: center; padding: 20px;
46
  }
47
- #drop .glyph {
48
- width: 72px; height: 72px; border-radius: 22px; background: #fff;
49
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
50
- display: flex; align-items: center; justify-content: center; font-size: 32px;
51
  }
52
- #drop strong { font-size: 21px; font-weight: 600; }
53
- #drop .hint { font-size: 15px; color: var(--text-2); max-width: 420px; }
54
- #drop .fine { font-size: 12px; color: #a1a1a6; }
55
- #drop .link { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; }
56
- #drop input { display: none; }
57
  .cta {
58
- margin-top: 8px; padding: 12px 26px; border-radius: 980px; border: none; cursor: pointer;
59
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500;
60
  font-family: inherit; transition: transform 0.15s ease, opacity 0.15s ease;
61
  }
62
  .cta:hover { opacity: 0.9; }
63
  .cta:active { transform: scale(0.97); }
64
- #compare { position: absolute; inset: 0; }
65
- #compare img, #compare video {
66
- position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
67
- background: #0b0b12; user-select: none; -webkit-user-drag: none;
68
- }
69
- #depthLayer { clip-path: inset(0 0 0 50%); }
70
- #handle {
71
- position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fff;
72
- transform: translateX(-50%); cursor: ew-resize; z-index: 3; touch-action: none;
73
- }
74
- #handle::after {
75
- content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
76
- width: 40px; height: 40px; border-radius: 50%; background: #fff;
77
- box-shadow: 0 3px 14px rgba(0, 0, 0, 0.35);
78
- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%231d1d1f' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 5l-6 7 6 7M16 5l6 7-6 7'/%3E%3C/svg%3E");
79
- background-repeat: no-repeat; background-position: center;
80
- }
81
- .tag {
82
- position: absolute; top: 16px; z-index: 2; padding: 6px 14px; border-radius: 980px;
83
- background: rgba(29, 29, 31, 0.75); color: #fff; font-size: 13px; font-weight: 600;
84
- pointer-events: none; backdrop-filter: blur(6px);
85
  }
86
- .tag.left { left: 16px; }
87
- .tag.right { right: 16px; }
 
88
  #busy {
89
  position: absolute; inset: 0; z-index: 5; display: none;
90
- flex-direction: column; gap: 16px; align-items: center; justify-content: center;
91
  background: rgba(11, 11, 18, 0.55); color: #fff; font-size: 15px; font-weight: 600;
92
  text-align: center; padding: 20px; backdrop-filter: blur(3px);
93
  }
@@ -115,34 +100,37 @@
115
  <p class="affil">Apple</p>
116
  </header>
117
 
118
- <div class="stage" id="stage">
119
- <div id="drop">
120
- <div class="glyph">&#128247;</div>
121
- <strong>Drop an image or video</strong>
122
- <span class="hint">Metric depth for every pixel, in meters &mdash; sharp at edges, steady across frames</span>
123
- <button class="cta" id="browse">Choose photo or video</button>
124
- <span class="fine">or try an <span class="link" id="example">example image</span> &middot;
125
- videos: first 60 frames, up to 960&nbsp;px</span>
126
- <input type="file" id="file" accept="image/*,video/*">
127
- </div>
128
- <div id="compare" hidden>
129
- <img id="srcImg" alt="source" hidden>
130
  <video id="srcVid" muted loop playsinline hidden></video>
131
- <div id="depthLayer">
132
- <img id="depthImg" alt="depth" hidden>
133
- <video id="depthVid" muted loop playsinline hidden></video>
 
 
 
 
 
134
  </div>
135
- <div id="handle"></div>
136
- <span class="tag left">Source</span>
137
- <span class="tag right">Depth Pro 2</span>
138
  </div>
139
- <div id="busy"><div class="spin"></div><span id="busyText"></span></div>
 
 
 
 
 
 
 
 
 
 
140
  </div>
141
  <p id="status"></p>
142
 
143
  <footer>
144
  Runs <a href="https://huggingface.co/apple/DepthPro2-H">apple/DepthPro2-H</a> (872M, bfloat16) on ZeroGPU &middot;
145
- red is near, blue is far, white is the infinitely far &middot;
146
  <a href="https://github.com/apple-aiml-research/ml-depth-pro-2">research use only</a>
147
  </footer>
148
 
@@ -150,9 +138,10 @@
150
  // UI wiring must not depend on any import: clicks always respond, even before or without the
151
  // Gradio client. The client is imported on demand inside the first request.
152
  const $ = (id) => document.getElementById(id);
153
- const stage = $("stage"), drop = $("drop"), compare = $("compare");
 
154
  const srcImg = $("srcImg"), srcVid = $("srcVid"), depthImg = $("depthImg"), depthVid = $("depthVid");
155
- const depthLayer = $("depthLayer"), handle = $("handle"), status = $("status");
156
  const busy = $("busy"), busyText = $("busyText");
157
  const fileInput = $("file");
158
 
@@ -171,8 +160,8 @@
171
  setStatus(`Error: ${e.reason?.message || e.reason}`, true));
172
 
173
  function show(kind, sourceUrl, depthUrl) {
174
- drop.hidden = true;
175
- compare.hidden = false;
176
  const isVideo = kind === "video";
177
  srcImg.hidden = isVideo; depthImg.hidden = isVideo;
178
  srcVid.hidden = !isVideo; depthVid.hidden = !isVideo;
@@ -185,29 +174,12 @@
185
  } else {
186
  srcImg.src = sourceUrl; depthImg.src = depthUrl;
187
  depthImg.onload = () =>
188
- setStatus(`\u2713 Depth loaded \u2014 drag the divider to compare`, false, false);
189
  depthImg.onerror = () =>
190
  setStatus(`The depth output failed to decode (${Math.round(depthUrl.length / 1024)} KB received) \u2014 reload the page and try once more.`, true);
191
  }
192
- setSlider(50);
193
  }
194
 
195
- function setSlider(pct) {
196
- pct = Math.max(0, Math.min(100, pct));
197
- depthLayer.style.clipPath = `inset(0 0 0 ${pct}%)`;
198
- handle.style.left = `${pct}%`;
199
- }
200
-
201
- let dragging = false;
202
- const pctFromEvent = (e) => {
203
- const rect = compare.getBoundingClientRect();
204
- return ((e.clientX - rect.left) / rect.width) * 100;
205
- };
206
- handle.addEventListener("pointerdown", (e) => { dragging = true; handle.setPointerCapture(e.pointerId); });
207
- handle.addEventListener("pointermove", (e) => { if (dragging) setSlider(pctFromEvent(e)); });
208
- handle.addEventListener("pointerup", () => { dragging = false; });
209
- compare.addEventListener("click", (e) => { if (e.target !== handle) setSlider(pctFromEvent(e)); });
210
-
211
  const CLIENT_SOURCES = [
212
  "/gradio-client.js",
213
  "https://cdn.jsdelivr.net/npm/@gradio/client@2.7.1/dist/index.min.js",
@@ -240,7 +212,18 @@
240
  if (!file) return;
241
  const isVideo = file.type.startsWith("video/");
242
  const sourceUrl = URL.createObjectURL(file);
243
- setStatus(`Estimating depth${isVideo ? " (first 60 frames)" : ""}\u2026`);
 
 
 
 
 
 
 
 
 
 
 
244
  try {
245
  const client = await getClient();
246
  const result = await client.predict(isVideo ? "/predict_depth_video" : "/predict_depth", {
@@ -253,26 +236,30 @@
253
  `The server returned no depth output \u2014 payload: ${JSON.stringify(payload)?.slice(0, 160)}`,
254
  );
255
  }
 
256
  show(isVideo ? "video" : "image", sourceUrl, depthUrl);
257
  setStatus("");
258
  } catch (err) {
259
  console.error(err);
 
 
260
  setStatus(String(err?.message || err), true);
261
  }
262
  }
263
 
264
- $("browse").addEventListener("click", () => fileInput.click());
 
265
  fileInput.addEventListener("change", () => {
266
  if (fileInput.files.length) processFile(fileInput.files[0]);
267
  fileInput.value = "";
268
  });
269
  for (const type of ["dragenter", "dragover"]) {
270
- stage.addEventListener(type, (e) => { e.preventDefault(); stage.classList.add("dragover"); });
271
  }
272
  for (const type of ["dragleave", "drop"]) {
273
- stage.addEventListener(type, (e) => { e.preventDefault(); stage.classList.remove("dragover"); });
274
  }
275
- stage.addEventListener("drop", (e) => {
276
  const file = e.dataTransfer?.files?.[0];
277
  if (file) processFile(file);
278
  });
 
16
  -webkit-font-smoothing: antialiased;
17
  display: flex; flex-direction: column; align-items: center; padding: 56px 20px 72px;
18
  }
19
+ header { text-align: center; max-width: 760px; margin-bottom: 44px; }
20
  h1 { font-size: clamp(48px, 9vw, 80px); font-weight: 700; letter-spacing: -0.035em; margin: 0; }
21
  .subtitle { font-size: clamp(19px, 3.2vw, 28px); font-weight: 600; color: var(--text-2); margin: 14px 0 24px; }
22
  .authors { font-size: 14px; color: var(--text-2); line-height: 1.7; margin: 0; }
23
  .affil { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 10px 0 0; }
24
+ .windows {
25
+ width: min(1060px, 100%);
26
+ display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
 
 
27
  }
28
+ @media (max-width: 720px) { .windows { grid-template-columns: 1fr; } }
29
+ .win {
30
+ position: relative; aspect-ratio: 4 / 3; border-radius: 24px; overflow: hidden;
31
+ background: var(--fill); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.28), 0 2px 10px rgba(0, 0, 0, 0.06);
 
 
 
 
 
 
 
32
  }
33
+ .win.dragover { outline: 3px dashed var(--accent); outline-offset: -12px; }
34
+ .win.clickable { cursor: pointer; }
35
+ .label {
36
+ position: absolute; top: 14px; left: 14px; z-index: 4; padding: 6px 14px; border-radius: 980px;
37
+ background: rgba(29, 29, 31, 0.75); color: #fff; font-size: 13px; font-weight: 600;
38
+ pointer-events: none; backdrop-filter: blur(6px);
39
+ }
40
+ .win img, .win video {
41
+ position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
42
+ background: #0b0b12; user-select: none; -webkit-user-drag: none;
43
+ }
44
+ .pane {
45
+ position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
46
  align-items: center; justify-content: center; text-align: center; padding: 20px;
47
  }
48
+ .pane .glyph {
49
+ width: 64px; height: 64px; border-radius: 20px; background: #fff;
50
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
51
+ display: flex; align-items: center; justify-content: center; font-size: 28px;
52
  }
53
+ .pane strong { font-size: 18px; font-weight: 600; }
54
+ .pane .hint { font-size: 14px; color: var(--text-2); max-width: 340px; }
55
+ .pane .fine { font-size: 12px; color: #a1a1a6; }
56
+ .pane .link { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; }
57
+ .pane input { display: none; }
58
  .cta {
59
+ margin-top: 6px; padding: 11px 24px; border-radius: 980px; border: none; cursor: pointer;
60
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500;
61
  font-family: inherit; transition: transform 0.15s ease, opacity 0.15s ease;
62
  }
63
  .cta:hover { opacity: 0.9; }
64
  .cta:active { transform: scale(0.97); }
65
+ #outPlaceholder .spin {
66
+ width: 34px; height: 34px; border-radius: 50%;
67
+ border: 3px solid rgba(29, 29, 31, 0.15); border-top-color: var(--accent);
68
+ animation: spin 0.9s linear infinite;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
+ #outPlaceholder .spin { display: none; }
71
+ #outPlaceholder.working .spin { display: block; }
72
+ #outPlaceholder.working strong { color: var(--text-2); }
73
  #busy {
74
  position: absolute; inset: 0; z-index: 5; display: none;
75
+ flex-direction: column; gap: 14px; align-items: center; justify-content: center;
76
  background: rgba(11, 11, 18, 0.55); color: #fff; font-size: 15px; font-weight: 600;
77
  text-align: center; padding: 20px; backdrop-filter: blur(3px);
78
  }
 
100
  <p class="affil">Apple</p>
101
  </header>
102
 
103
+ <div class="windows">
104
+ <div class="win clickable" id="inWin">
105
+ <span class="label">Input</span>
106
+ <img id="srcImg" alt="input" hidden>
 
 
 
 
 
 
 
 
107
  <video id="srcVid" muted loop playsinline hidden></video>
108
+ <div class="pane" id="drop">
109
+ <div class="glyph">&#128247;</div>
110
+ <strong>Drop an image or video</strong>
111
+ <span class="hint">Metric depth for every pixel, in meters</span>
112
+ <button class="cta" id="browse">Choose photo or video</button>
113
+ <span class="fine">or try an <span class="link" id="example">example image</span> &middot;
114
+ videos: first 60 frames, up to 960&nbsp;px</span>
115
+ <input type="file" id="file" accept="image/*,video/*">
116
  </div>
 
 
 
117
  </div>
118
+ <div class="win" id="outWin">
119
+ <span class="label">Depth Pro 2</span>
120
+ <img id="depthImg" alt="depth" hidden>
121
+ <video id="depthVid" muted loop playsinline hidden></video>
122
+ <div class="pane" id="outPlaceholder">
123
+ <div class="spin"></div>
124
+ <strong id="outTitle">Depth appears here</strong>
125
+ <span class="hint">Red is near, blue is far, white is the infinitely far &mdash; distances in meters</span>
126
+ </div>
127
+ <div id="busy"><div class="spin"></div><span id="busyText"></span></div>
128
+ </div>
129
  </div>
130
  <p id="status"></p>
131
 
132
  <footer>
133
  Runs <a href="https://huggingface.co/apple/DepthPro2-H">apple/DepthPro2-H</a> (872M, bfloat16) on ZeroGPU &middot;
 
134
  <a href="https://github.com/apple-aiml-research/ml-depth-pro-2">research use only</a>
135
  </footer>
136
 
 
138
  // UI wiring must not depend on any import: clicks always respond, even before or without the
139
  // Gradio client. The client is imported on demand inside the first request.
140
  const $ = (id) => document.getElementById(id);
141
+ const inWin = $("inWin"), outWin = $("outWin");
142
+ const drop = $("drop"), outPlaceholder = $("outPlaceholder"), outTitle = $("outTitle");
143
  const srcImg = $("srcImg"), srcVid = $("srcVid"), depthImg = $("depthImg"), depthVid = $("depthVid");
144
+ const status = $("status");
145
  const busy = $("busy"), busyText = $("busyText");
146
  const fileInput = $("file");
147
 
 
160
  setStatus(`Error: ${e.reason?.message || e.reason}`, true));
161
 
162
  function show(kind, sourceUrl, depthUrl) {
163
+ drop.style.display = "none";
164
+ outPlaceholder.style.display = "none";
165
  const isVideo = kind === "video";
166
  srcImg.hidden = isVideo; depthImg.hidden = isVideo;
167
  srcVid.hidden = !isVideo; depthVid.hidden = !isVideo;
 
174
  } else {
175
  srcImg.src = sourceUrl; depthImg.src = depthUrl;
176
  depthImg.onload = () =>
177
+ setStatus(`\u2713 Depth loaded \u2014 click the input window to try another photo`, false, false);
178
  depthImg.onerror = () =>
179
  setStatus(`The depth output failed to decode (${Math.round(depthUrl.length / 1024)} KB received) \u2014 reload the page and try once more.`, true);
180
  }
 
181
  }
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  const CLIENT_SOURCES = [
184
  "/gradio-client.js",
185
  "https://cdn.jsdelivr.net/npm/@gradio/client@2.7.1/dist/index.min.js",
 
212
  if (!file) return;
213
  const isVideo = file.type.startsWith("video/");
214
  const sourceUrl = URL.createObjectURL(file);
215
+ // The input window shows the source immediately; the output window shows work in progress.
216
+ drop.style.display = "none";
217
+ outPlaceholder.style.display = "";
218
+ outPlaceholder.classList.add("working");
219
+ outTitle.textContent = `Estimating depth${isVideo ? " (first 60 frames)" : ""}\u2026`;
220
+ if (isVideo) {
221
+ srcImg.hidden = true; srcVid.hidden = false;
222
+ srcVid.src = sourceUrl; srcVid.play();
223
+ } else {
224
+ srcVid.hidden = true; srcImg.hidden = false;
225
+ srcImg.src = sourceUrl;
226
+ }
227
  try {
228
  const client = await getClient();
229
  const result = await client.predict(isVideo ? "/predict_depth_video" : "/predict_depth", {
 
236
  `The server returned no depth output \u2014 payload: ${JSON.stringify(payload)?.slice(0, 160)}`,
237
  );
238
  }
239
+ outPlaceholder.classList.remove("working");
240
  show(isVideo ? "video" : "image", sourceUrl, depthUrl);
241
  setStatus("");
242
  } catch (err) {
243
  console.error(err);
244
+ outPlaceholder.classList.remove("working");
245
+ outTitle.textContent = "Depth appears here";
246
  setStatus(String(err?.message || err), true);
247
  }
248
  }
249
 
250
+ $("browse").addEventListener("click", (e) => { e.stopPropagation(); fileInput.click(); });
251
+ inWin.addEventListener("click", () => fileInput.click());
252
  fileInput.addEventListener("change", () => {
253
  if (fileInput.files.length) processFile(fileInput.files[0]);
254
  fileInput.value = "";
255
  });
256
  for (const type of ["dragenter", "dragover"]) {
257
+ inWin.addEventListener(type, (e) => { e.preventDefault(); inWin.classList.add("dragover"); });
258
  }
259
  for (const type of ["dragleave", "drop"]) {
260
+ inWin.addEventListener(type, (e) => { e.preventDefault(); inWin.classList.remove("dragover"); });
261
  }
262
+ inWin.addEventListener("drop", (e) => {
263
  const file = e.dataTransfer?.files?.[0];
264
  if (file) processFile(file);
265
  });