idol-studio / studio.html
akhaliq's picture
akhaliq HF Staff
Keepalive ping every 60s to keep the stored ZeroGPU token fresh
0c30772 verified
Raw History Blame Contribute Delete
24.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Idol Studio</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet" />
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/",
"@mkkellogg/gaussian-splats-3d": "https://cdn.jsdelivr.net/npm/@mkkellogg/gaussian-splats-3d@0.4.7/build/gaussian-splats-3d.module.js"
}
}
</script>
<style>
:root {
--bg: #000000; --panel: #000000; --panel2: #111111; --raised: #161616;
--border: rgba(255,255,255,0.15); --hairline: rgba(255,255,255,0.12);
--text: #ffffff; --muted: rgba(255,255,255,0.75); --dim: rgba(255,255,255,0.55);
--accent: #d94a1f; --accent-soft: rgba(217,74,31,0.16);
--stage: #0c0c0c;
--radius: 0px;
}
body.light {
--bg: #ffffff; --panel: #ffffff; --panel2: #f7f7f7; --raised: #f7f7f7;
--border: #e3e3e3; --hairline: #e3e3e3;
--text: #000000; --muted: #444444; --dim: #6b6b6b;
--accent-soft: #fbe7e0;
--stage: #f2f2f2;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
body {
font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
background: var(--bg); color: var(--text);
height: 100vh; display: flex; flex-direction: column; overflow: hidden;
font-size: 13px; font-weight: 500; -webkit-font-smoothing: antialiased;
}
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; text-transform: uppercase; letter-spacing: 0.12em; }
.topbar {
display: flex; align-items: flex-end; gap: 18px; padding: 18px 24px 14px;
border-bottom: 1px solid var(--hairline); flex-shrink: 0; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand .label { font-size: 11px; font-weight: 600; color: var(--dim); }
.brand h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.05em; line-height: 1; }
.brand .studio-badge {
font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 10px; font-weight: 600;
letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent);
border: 1px solid var(--accent); padding: 2px 8px;
}
.mode-tabs { display: flex; gap: 2px; border: 1px solid var(--border); padding: 3px; }
.mode-tabs button {
border: none; padding: 6px 18px; font-weight: 600; font-size: 0.82rem;
background: transparent; color: var(--muted); cursor: pointer; font-family: inherit;
}
.mode-tabs button:hover { color: var(--text); }
.mode-tabs button.active { background: var(--text); color: var(--bg); }
.spacer { flex: 1; }
.top-links { display: flex; gap: 8px; align-items: center; }
.top-links a, .theme-toggle {
display: inline-flex; align-items: center; height: 34px; padding: 0 14px;
border: 1px solid var(--text); background: transparent; color: var(--text);
text-decoration: none; cursor: pointer; font-family: "IBM Plex Mono", ui-monospace, monospace;
text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; font-weight: 600;
transition: background 0.15s, color 0.15s;
}
.top-links a:hover, .theme-toggle:hover { background: var(--text); color: var(--bg); }
.theme-toggle { width: 40px; padding: 0; justify-content: center; font-size: 16px; }
.theme-toggle::before { content: "☾"; }
body.light .theme-toggle::before { content: "☀"; }
.ml-badge-img { display: inline-flex; align-items: center; }
.ml-badge-img img { height: 20px; display: block; }
.ml-badge-img:hover { opacity: 0.8; }
.main { display: flex; flex: 1; min-height: 0; }
.panels {
width: 330px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px;
padding: 16px; overflow-y: auto; border-right: 1px solid var(--hairline);
}
.panel-title { font-size: 11px; font-weight: 600; color: var(--dim); margin-bottom: 8px; }
.panel label { display: block; font-size: 0.74rem; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.panel label:first-of-type { margin-top: 0; }
input[type="number"], select {
width: 100%; background: var(--raised); color: var(--text); border: 1px solid var(--border);
border-radius: 0; padding: 8px 10px; font-family: inherit; font-size: 0.85rem;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-row .val { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.75rem; color: var(--muted); width: 42px; text-align: right; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-top: 10px; }
.switch input { display: none; }
.switch .sw {
width: 34px; height: 20px; border-radius: 999px; background: var(--raised);
border: 1px solid var(--border); position: relative; flex-shrink: 0; transition: background 0.18s;
}
.switch .sw::after {
content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
border-radius: 50%; background: var(--muted); transition: transform 0.18s, background 0.18s;
}
.switch input:checked + .sw { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .sw::after { transform: translateX(14px); background: #fff; }
.switch .sw-label { font-size: 0.75rem; color: var(--muted); }
#dropzone {
border: 1px dashed var(--border); background: var(--raised); min-height: 180px;
display: flex; align-items: center; justify-content: center; cursor: pointer;
overflow: hidden; position: relative; text-align: center;
}
#dropzone:hover { border-color: var(--accent); }
#dropzone img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--stage); }
.drop-hint { color: var(--dim); font-size: 0.8rem; padding: 18px; }
.drop-hint b { color: var(--muted); display: block; margin-bottom: 4px; }
#run-btn {
margin-top: 2px; padding: 13px; border: none; cursor: pointer;
background: var(--text); color: var(--bg); font-weight: 600; font-size: 0.95rem;
font-family: inherit; transition: background 0.15s;
}
#run-btn:hover { background: var(--accent); color: #fff; }
#run-btn:disabled { opacity: 0.5; cursor: wait; }
#examples { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ex-chip {
border: 1px solid var(--border); cursor: pointer; background: var(--raised);
aspect-ratio: 1; overflow: hidden; padding: 0; position: relative;
}
.ex-chip:hover { border-color: var(--accent); }
.ex-chip img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s ease-out; }
.ex-chip:hover img { transform: scale(1.05); }
.ex-chip span {
position: absolute; left: 0; right: 0; bottom: 0; font-size: 0.56rem; padding: 2px 4px;
background: rgba(0,0,0,0.62); color: #eee; font-family: "IBM Plex Mono", ui-monospace, monospace;
text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.viewport { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.stage-wrap { flex: 1; min-height: 0; position: relative; background: var(--stage); }
#viewer { position: absolute; inset: 0; }
#viewer canvas { display: block; }
.viewer-empty {
position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
color: var(--dim); font-size: 0.9rem; text-align: center; padding: 20px;
}
.viewer-bar {
display: flex; align-items: center; gap: 14px; padding: 8px 16px; flex-shrink: 0;
border-top: 1px solid var(--hairline); font-size: 0.75rem; color: var(--muted);
}
.viewer-bar .meta { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.72rem; }
.viewer-bar a {
margin-left: auto; display: inline-flex; align-items: center; height: 30px; padding: 0 14px;
border: 1px solid var(--text); color: var(--text); text-decoration: none;
font-family: "IBM Plex Mono", ui-monospace, monospace; text-transform: uppercase;
letter-spacing: 0.12em; font-size: 10px; font-weight: 600;
}
.viewer-bar a:hover { background: var(--text); color: var(--bg); }
.prepared { display: flex; align-items: center; gap: 8px; }
.prepared img { width: 44px; height: 44px; object-fit: contain; background: var(--stage); border: 1px solid var(--border); }
.prepared span { font-size: 0.62rem; color: var(--dim); max-width: 120px; }
.workflow-view { position: absolute; inset: 0; padding: 12px; background: var(--bg); }
.workflow-view iframe { width: 100%; height: 100%; border: 1px solid var(--hairline); background: var(--stage); }
.statusbar {
display: flex; align-items: center; gap: 14px; padding: 7px 24px; flex-shrink: 0;
border-top: 1px solid var(--hairline); font-size: 0.75rem; color: var(--muted);
}
.statusbar .pulse { width: 8px; height: 8px; border-radius: 50%; background: #4fd1a5; }
.statusbar.busy .pulse { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.35; } to { opacity: 1; } }
.statusbar .links { margin-left: auto; display: flex; gap: 14px; }
.statusbar .links a { color: var(--dim); text-decoration: none; font-size: 0.72rem; }
.statusbar .links a:hover { color: var(--accent); }
#file-input { display: none; }
@media (max-width: 860px) {
html, body { height: auto !important; overflow: visible !important; }
body { display: block; }
.topbar { padding: 12px 14px; gap: 10px; align-items: center; flex-wrap: nowrap; }
.brand { gap: 8px; align-items: baseline; }
.brand .label, .brand .studio-badge { display: none; }
.brand h1 { font-size: 24px; }
.mode-tabs button { padding: 6px 12px; font-size: 0.78rem; }
.top-links a { display: none; }
.top-links a:last-of-type { display: inline-flex; } /* keep the build-your-own CTA */
.main { display: flex; flex-direction: column; }
/* viewer first: the result is the focus; an explicit height keeps it from collapsing */
.viewport { order: -1; display: flex; flex-direction: column; height: 62vh; min-height: 400px; border-bottom: 1px solid var(--hairline); }
.stage-wrap { flex: 1; min-height: 0; }
.workflow-view { position: static; flex: 1; min-height: 0; height: auto; padding: 0; }
.viewer-bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
.prepared span { display: none; }
.panels { width: 100%; border-right: none; padding: 14px; }
#dropzone { min-height: 140px; }
#examples { grid-template-columns: repeat(4, 1fr); }
.statusbar { position: sticky; bottom: 0; background: var(--panel); }
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="label mono">Speridlabs · Research</span>
<h1>Idol</h1>
<span class="studio-badge">Studio</span>
</div>
<div class="mode-tabs">
<button id="mode-generate" class="active">Generate</button>
<button id="mode-workflow">Workflow</button>
</div>
<div class="spacer"></div>
<div class="top-links">
<a class="ml-badge-img" href="https://hf.co/chat?mode=ml-intern" target="_blank" rel="noopener" style="border:none;padding:0">
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/built-with-ml-intern-md.svg" alt="Built with ML Intern" />
</a>
<a href="https://github.com/speridlabs/idol-sdk" target="_blank" rel="noopener">Code</a>
<a href="https://huggingface.co/speridlabs/idol" target="_blank" rel="noopener">Weights</a>
<a href="https://hf.co/chat?mode=ml-intern" target="_blank" rel="noopener" style="color:var(--accent);border-color:var(--accent)">Build your own app here →</a>
<button type="button" class="theme-toggle" id="theme-toggle" aria-label="Toggle light/dark"></button>
</div>
</header>
<div class="main">
<div class="panels" id="panels">
<div class="panel">
<div class="panel-title mono">Input image</div>
<div id="dropzone" title="Click, drop or paste an image">
<div class="drop-hint" id="drop-hint"><b>No image yet</b>Click, drop or paste</div>
<img id="source-img" alt="" hidden />
</div>
<label for="mode">Input type</label>
<select id="mode">
<option>Synthetic</option>
<option>Real photo</option>
</select>
</div>
<div class="panel">
<div class="panel-title mono">Settings</div>
<label for="gaussians">Gaussians</label>
<select id="gaussians">
<option>65,536</option>
<option>131,072</option>
<option selected>262,144</option>
<option>524,288</option>
<option>1,048,576</option>
</select>
<label for="steps">Steps</label>
<div class="slider-row"><input type="range" id="steps" min="10" max="100" step="1" value="50" /><span class="val" id="steps-val">50</span></div>
<label for="cfg">Guidance scale</label>
<div class="slider-row"><input type="range" id="cfg" min="0" max="10" step="0.1" value="3" /><span class="val" id="cfg-val">3.0</span></div>
<label for="rescale">Time shift</label>
<div class="slider-row"><input type="range" id="rescale" min="1" max="6" step="0.1" value="3" /><span class="val" id="rescale-val">3.0</span></div>
<label for="seed">Seed</label>
<input type="number" id="seed" value="42" min="0" />
<label class="switch"><input type="checkbox" id="randomize" checked /><span class="sw"></span><span class="sw-label">Random seed</span></label>
</div>
<button id="run-btn">Generate</button>
<div class="panel">
<div class="panel-title mono">Examples — click to load</div>
<div id="examples"></div>
</div>
</div>
<div class="viewport">
<div class="workflow-view" id="workflow-view" hidden>
<iframe src="/workflow/?ui=canvas" title="Workflow canvas"></iframe>
</div>
<div class="stage-wrap" id="stage-wrap">
<div id="viewer"></div>
<div class="viewer-empty" id="viewer-empty">The generated 3D object appears here.<br />Drag to orbit, scroll to zoom.</div>
</div>
<div class="viewer-bar">
<span class="meta" id="result-meta">—</span>
<div class="prepared" id="prepared" hidden>
<img id="prepared-img" alt="What the model saw" />
<span>What the model saw</span>
</div>
<a id="download" href="#" download hidden>Download .ply</a>
</div>
</div>
</div>
<footer class="statusbar" id="statusbar">
<span class="pulse"></span>
<span id="status">Idle</span>
</footer>
<input type="file" id="file-input" accept="image/*" />
<script type="module">
import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client@2.7.1/dist/index.min.js";
import * as GaussianSplats3D from "@mkkellogg/gaussian-splats-3d";
const $ = (id) => document.getElementById(id);
const state = { mode: "generate", sourcePath: null, app: null, viewer: null };
async function getApp() {
if (!state.app) state.app = await client(location.origin);
return state.app;
}
async function uploadFile(file) {
const form = new FormData();
form.append("files", file);
const resp = await fetch("/gradio_api/upload", { method: "POST", body: form });
if (!resp.ok) throw new Error(`Upload failed (${resp.status})`);
const paths = await resp.json();
return Array.isArray(paths) ? paths[0] : paths;
}
function setStatus(text, busy = false) {
$("status").textContent = text;
$("statusbar").classList.toggle("busy", busy);
$("run-btn").disabled = busy;
}
// ---------- theme ----------
function applyTheme(mode) {
document.body.classList.toggle("light", mode === "light");
try { localStorage.setItem("idol-theme", mode); } catch (e) {}
}
$("theme-toggle").onclick = () =>
applyTheme(document.body.classList.contains("light") ? "dark" : "light");
(function initTheme() {
let mode = "dark";
try { if (localStorage.getItem("idol-theme") === "light") mode = "light"; } catch (e) {}
applyTheme(mode);
})();
// ---------- mode tabs ----------
function setMode(mode) {
state.mode = mode;
for (const m of ["generate", "workflow"]) $(`mode-${m}`).classList.toggle("active", mode === m);
const workflow = mode === "workflow";
$("workflow-view").hidden = !workflow;
$("stage-wrap").style.display = workflow ? "none" : "";
document.querySelector(".viewer-bar").style.display = workflow ? "none" : "";
$("panels").style.display = workflow ? "none" : "";
}
$("mode-generate").onclick = () => setMode("generate");
$("mode-workflow").onclick = () => { setMode("workflow"); pingHandshake(); };
// The nested workflow canvas cannot run gradio's ZeroGPU postMessage handshake itself,
// so the server stashes the token this client's calls carry and reuses it for canvas runs.
function pingHandshake() {
getApp().then((app) => app.predict("/handshake", {})).catch(() => {});
}
// ---------- sliders ----------
for (const [id, digits] of [["steps", 0], ["cfg", 1], ["rescale", 1]]) {
$(id).oninput = () => { $(`${id}-val`).textContent = Number($(id).value).toFixed(digits); };
}
// ---------- input image ----------
function showSource(file) {
const img = $("source-img");
img.src = URL.createObjectURL(file);
img.hidden = false;
$("drop-hint").style.display = "none";
}
async function takeFile(file) {
setStatus("Uploading…", true);
try {
state.sourcePath = await uploadFile(file);
showSource(file);
setStatus("Idle");
} catch (err) { setStatus(String(err)); }
}
$("dropzone").onclick = () => $("file-input").click();
$("file-input").onchange = (e) => {
const file = e.target.files[0];
e.target.value = "";
if (file) takeFile(file);
};
for (const event of ["dragover", "drop"]) {
$("dropzone").addEventListener(event, (e) => {
e.preventDefault();
if (event === "drop" && e.dataTransfer.files[0]) takeFile(e.dataTransfer.files[0]);
});
}
document.addEventListener("paste", (e) => {
const file = [...(e.clipboardData?.files || [])][0];
if (file) takeFile(file);
});
// ---------- splat viewer ----------
async function showSplat(url) {
if (state.viewer) {
try { await state.viewer.dispose(); } catch (e) {}
state.viewer = null;
}
const container = $("viewer");
container.innerHTML = "";
const viewer = new GaussianSplats3D.Viewer({
rootElement: container,
cameraUp: [0, 1, 0],
initialCameraPosition: [0, 0.15, 1.7],
initialCameraLookAt: [0, 0, 0],
sphericalHarmonicsDegree: 0,
sharedMemoryForWorkers: false,
});
state.viewer = viewer;
await viewer.addSplatScene(url, {
format: GaussianSplats3D.SceneFormat.Ply,
progressiveLoad: false,
showLoadingUI: true,
// idol's .ply is y-up; this viewer's 3DGS convention is y-down — flip 180° about X
rotation: [1, 0, 0, 0],
});
viewer.start();
$("viewer-empty").style.display = "none";
}
// ---------- result ----------
function unwrap(result) {
const data = Array.isArray(result?.data) ? result.data[0] : result?.data;
return data ?? {};
}
async function showResult(result) {
const payload = unwrap(result);
if (!payload.model_url) { setStatus("Run finished but no model came back (see console)."); return false; }
await showSplat(payload.model_url);
$("result-meta").textContent = payload.info || "Done";
const link = $("download");
link.href = payload.model_url;
link.download = payload.model_name || "idol.ply";
link.hidden = false;
if (payload.prepared_data) {
$("prepared-img").src = payload.prepared_data;
$("prepared").hidden = false;
}
return true;
}
$("run-btn").onclick = async () => {
if (!state.sourcePath) { setStatus("Upload an image or pick an example first."); return; }
try {
const app = await getApp();
setStatus("Generating the 3D object…", true);
const result = await app.predict("/generate", {
image: state.sourcePath,
mode: $("mode").value,
steps: Number($("steps").value),
cfg_scale: Number($("cfg").value),
rescale_t: Number($("rescale").value),
seed: Number($("seed").value) || 0,
randomize: $("randomize").checked,
gaussians: $("gaussians").value,
});
if (await showResult(result)) setStatus("Done");
} catch (err) {
setStatus(err?.message || String(err));
}
};
// ---------- examples (bundled presets, served by the space itself) ----------
const MODE_LABEL = { synthetic: "Synthetic", real: "Real photo" };
async function loadExamples() {
try {
const resp = await fetch("/examples/presets.json");
const presets = await resp.json();
const stride = Math.max(1, Math.floor(presets.length / 12));
const row = $("examples");
presets.filter((_, i) => i % stride === 0).slice(0, 12).forEach((p) => {
const file = p.image.replace(/^examples\//, "");
const chip = document.createElement("button");
chip.className = "ex-chip";
chip.title = p.title || file;
chip.innerHTML = `<img src="/examples/${file}" alt="${p.title || ""}" loading="lazy" /><span>${p.title || ""}</span>`;
chip.onclick = async () => {
$("mode").value = MODE_LABEL[p.mode] || "Synthetic";
$("steps").value = p.steps; $("steps").oninput();
$("cfg").value = p.cfg; $("cfg").oninput();
$("rescale").value = p.rescale_t; $("rescale").oninput();
$("seed").value = p.seed;
$("randomize").checked = false;
$("gaussians").value = Number(p.num_gaussians).toLocaleString("en-US");
setStatus("Loading the example…", true);
try {
const blob = await (await fetch(`/examples/${file}`)).blob();
await takeFile(new File([blob], file, { type: blob.type || "image/webp" }));
setStatus("Example loaded — hit Generate");
} catch (err) { setStatus(String(err)); }
};
row.appendChild(chip);
});
} catch (err) { /* examples are decorative; the app works without them */ }
}
// ---------- opening state: the default example and its pre-generated splat ----------
async function loadDefault() {
try {
await showSplat("/examples/default-obj-backpack.ply");
$("result-meta").textContent = "262,144 Gaussians · 50 steps (pre-generated example)";
const link = $("download");
link.href = "/examples/default-obj-backpack.ply";
link.download = "default-obj-backpack.ply";
link.hidden = false;
const blob = await (await fetch("/examples/obj-backpack.webp")).blob();
await takeFile(new File([blob], "obj-backpack.webp", { type: "image/webp" }));
$("randomize").checked = false;
$("seed").value = 7;
} catch (err) { /* the viewer simply starts empty */ }
}
loadExamples();
loadDefault();
pingHandshake();
// proxy tokens live ~2-4 min; keep the stored token fresh while the page is open
setInterval(pingHandshake, 60000);
document.addEventListener("visibilitychange", () => { if (!document.hidden) pingHandshake(); });
</script>
</body>
</html>