Spaces:
Running on Zero
Running on Zero
Download studio.html from akhaliq/LongCat-Avatar-Studio: direct link, hf CLI and curl.
- Browser
- Download file 24.3 kB
-
https://huggingface.co/spaces/akhaliq/LongCat-Avatar-Studio/resolve/main/studio.html
- Command line
-
hf download hf://spaces/akhaliq/LongCat-Avatar-Studio/studio.html
-
curl -L -o studio.html https://huggingface.co/spaces/akhaliq/LongCat-Avatar-Studio/resolve/main/studio.html
24.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>LongCat Avatar 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&display=swap" rel="stylesheet" /> | |
| <style> | |
| :root { | |
| --bg: #fcfdf9; --panel: #ffffff; --panel2: #f4f7f0; --raised: #eaf1e2; | |
| --border: #e4e9dc; --hairline: rgba(24,24,27,0.07); | |
| --text: #18181b; --muted: #71717a; --dim: #a1a1aa; | |
| --accent: #84cc16; --accent2: #65a30d; --accent-soft: rgba(132,204,22,0.12); | |
| --lavender: #4d7c0f; --link: #4d7c0f; | |
| --glow: radial-gradient(ellipse 60% 35% at 50% -5%, rgba(132,204,22,0.16), transparent 55%); | |
| --dots: radial-gradient(rgba(101,163,13,0.13) 1px, transparent 1.4px); | |
| --stage-base: #f1f5ea; --stage-square: #fafcf5; --thumb-bg: #f0f4e9; | |
| --btn-bg: #18181b; --btn-text: #ffffff; | |
| --shadow: 0 1px 3px rgba(60,90,20,0.08); | |
| --radius: 12px; | |
| } | |
| body.dark { | |
| --bg: #10140a; --panel: #161b0e; --panel2: #1b2212; --raised: #242c16; | |
| --border: rgba(132,204,22,0.22); --hairline: rgba(255,255,255,0.08); | |
| --text: #fafafa; --muted: #a3a3a3; --dim: #71717a; | |
| --accent: #a3e635; --accent2: #bef264; --accent-soft: rgba(163,230,53,0.12); | |
| --lavender: #bef264; --link: #bef264; | |
| --glow: radial-gradient(ellipse 60% 35% at 50% -5%, rgba(163,230,53,0.14), transparent 55%); | |
| --dots: radial-gradient(rgba(163,230,53,0.10) 1px, transparent 1.4px); | |
| --stage-base: #0d1107; --stage-square: #151b0c; --thumb-bg: #131809; | |
| --btn-bg: #a3e635; --btn-text: #1a2e05; | |
| --shadow: 0 1px 3px rgba(0,0,0,0.45); | |
| } | |
| * { margin: 0; padding: 0; box-sizing: border-box; } | |
| [hidden] { display: none ; } | |
| body { | |
| font-family: "Inter", ui-sans-serif, system-ui, sans-serif; | |
| background: var(--bg); background-image: var(--glow), var(--dots); background-repeat: no-repeat, repeat; | |
| background-size: auto, 15px 15px; | |
| background-attachment: fixed; | |
| color: var(--text); height: 100vh; | |
| display: flex; flex-direction: column; overflow: hidden; | |
| font-size: 13px; -webkit-font-smoothing: antialiased; | |
| } | |
| .topbar { | |
| display: flex; align-items: center; gap: 14px; padding: 8px 16px; | |
| background: var(--panel); border-bottom: 1px solid var(--hairline); flex-shrink: 0; | |
| } | |
| .brand { font-weight: 700; font-size: 0.95rem; white-space: nowrap; letter-spacing: -0.02em; display: flex; align-items: center; } | |
| .brand .logo { display: inline-flex; margin-right: 9px; } | |
| .brand .logo svg { display: block; } | |
| .studio-badge { | |
| font-size: 0.6rem; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; | |
| color: var(--lavender); border: 1px solid var(--border); border-radius: 999px; | |
| padding: 2px 8px; margin-left: 10px; background: var(--accent-soft); | |
| } | |
| .mode-tabs { display: flex; gap: 2px; background: var(--panel2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; } | |
| .mode-tabs button { | |
| border: none; border-radius: 999px; padding: 6px 16px; font-weight: 550; font-size: 0.82rem; | |
| background: transparent; color: var(--muted); cursor: pointer; transition: color 0.15s, background 0.15s; | |
| font-family: inherit; | |
| } | |
| .mode-tabs button:hover { color: var(--text); } | |
| .mode-tabs button.active { background: var(--btn-bg); color: var(--btn-text); box-shadow: var(--shadow); } | |
| .spacer { flex: 1; } | |
| .ml-badge { color: var(--muted); text-decoration: none; font-size: 0.8rem; font-weight: 500; transition: color 0.15s; white-space: nowrap; } | |
| .ml-badge:hover { color: var(--text); } | |
| .ml-badge-img { display: inline-flex; align-items: center; } | |
| .ml-badge-img img { height: 20px; display: block; } | |
| .ml-badge-img:hover { opacity: 0.85; } | |
| .theme-toggle { | |
| width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 999px; | |
| background: transparent; color: var(--muted); cursor: pointer; flex-shrink: 0; | |
| display: inline-flex; align-items: center; justify-content: center; | |
| transition: color 0.15s, background 0.15s; | |
| } | |
| .theme-toggle:hover { color: var(--text); background: var(--panel2); } | |
| .theme-toggle svg { width: 17px; height: 17px; } | |
| .theme-toggle .theme-icon-sun { display: none; } | |
| .theme-toggle[data-mode="dark"] .theme-icon-sun { display: block; } | |
| .theme-toggle[data-mode="dark"] .theme-icon-moon { display: none; } | |
| .main { display: flex; flex: 1; min-height: 0; } | |
| .workflow-view { position: absolute; inset: 0; padding: 12px; } | |
| .workflow-view iframe { width: 100%; height: 100%; border: none; border-radius: 12px; background: var(--stage-base); } | |
| .viewport { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: auto; position: relative; } | |
| .workspace { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 20px 20px 10px; align-items: stretch; } | |
| /* ---------- left control panel ---------- */ | |
| .controls { | |
| width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; | |
| overflow-y: auto; padding-right: 2px; | |
| } | |
| .panel { | |
| background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); | |
| padding: 12px; box-shadow: var(--shadow); | |
| } | |
| .panel-title { | |
| font-size: 0.62rem; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; | |
| color: var(--dim); margin-bottom: 10px; | |
| } | |
| .drop { | |
| border: 1.5px dashed var(--border); border-radius: 10px; background: var(--panel2); | |
| min-height: 96px; display: flex; align-items: center; justify-content: center; | |
| cursor: pointer; overflow: hidden; position: relative; transition: border-color 0.15s; | |
| text-align: center; padding: 8px; | |
| } | |
| .drop:hover { border-color: var(--accent); } | |
| .drop .hint { color: var(--dim); font-size: 0.78rem; line-height: 1.5; pointer-events: none; } | |
| .drop .hint b { color: var(--muted); font-weight: 600; display: block; font-size: 0.82rem; } | |
| .drop img { width: 100%; height: 100%; object-fit: contain; max-height: 220px; display: block; } | |
| .drop audio { width: 100%; } | |
| textarea, select, input[type="number"] { | |
| width: 100%; background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; | |
| color: var(--text); font-family: inherit; font-size: 0.84rem; padding: 8px 10px; outline: none; | |
| transition: border-color 0.15s; | |
| } | |
| textarea:focus, select:focus, input[type="number"]:focus { border-color: var(--accent); } | |
| textarea { resize: vertical; min-height: 74px; line-height: 1.45; } | |
| .field { margin-bottom: 10px; } | |
| .field:last-child { margin-bottom: 0; } | |
| .field label { display: block; font-size: 0.74rem; font-weight: 550; color: var(--muted); margin-bottom: 5px; } | |
| .row { display: flex; gap: 8px; } | |
| .row > * { flex: 1; min-width: 0; } | |
| .check { display: flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--muted); padding: 8px 2px 0; } | |
| .check input { accent-color: var(--accent2); } | |
| .run-btn { | |
| border: none; border-radius: 999px; padding: 12px; font-weight: 650; font-size: 0.88rem; | |
| background: var(--btn-bg); color: var(--btn-text); | |
| cursor: pointer; font-family: inherit; transition: filter 0.15s, opacity 0.15s, transform 0.1s; | |
| box-shadow: var(--shadow); | |
| } | |
| .run-btn:hover { filter: brightness(1.08); transform: translateY(-1px); } | |
| .run-btn:disabled { opacity: 0.5; cursor: default; filter: none; transform: none; } | |
| /* ---------- stage ---------- */ | |
| .stage-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; } | |
| .doc { | |
| flex: 1; min-height: 0; display: flex; flex-direction: column; | |
| background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); | |
| overflow: hidden; box-shadow: var(--shadow); | |
| } | |
| .doc figcaption { | |
| padding: 8px 12px; font-size: 0.62rem; font-weight: 650; letter-spacing: 0.12em; | |
| color: var(--dim); border-bottom: 1px solid var(--hairline); display: flex; | |
| align-items: center; gap: 10px; text-transform: uppercase; | |
| } | |
| .doc figcaption .meta { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); } | |
| .stage { | |
| flex: 1; min-height: 280px; display: flex; align-items: center; justify-content: center; | |
| background: | |
| linear-gradient(45deg, var(--stage-square) 25%, transparent 25%, transparent 75%, var(--stage-square) 75%), | |
| linear-gradient(45deg, var(--stage-square) 25%, transparent 25%, transparent 75%, var(--stage-square) 75%), | |
| var(--stage-base); | |
| background-size: 24px 24px; background-position: 0 0, 12px 12px; | |
| position: relative; overflow: hidden; | |
| } | |
| .stage video { max-width: 100%; max-height: 100%; outline: none; } | |
| .stage .hint { color: var(--dim); font-size: 0.85rem; text-align: center; line-height: 1.7; padding: 20px; } | |
| .stage .hint .big { font-size: 34px; display: block; margin-bottom: 8px; } | |
| /* ---------- history ---------- */ | |
| .history-strip { | |
| display: flex; align-items: center; gap: 8px; padding: 8px 12px; overflow-x: auto; | |
| background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); | |
| min-height: 64px; flex-shrink: 0; box-shadow: var(--shadow); | |
| } | |
| .history-strip .hlabel { font-size: 0.62rem; font-weight: 650; letter-spacing: 0.12em; color: var(--dim); text-transform: uppercase; white-space: nowrap; } | |
| .history-chip { | |
| position: relative; width: 76px; height: 48px; border-radius: 8px; overflow: hidden; | |
| border: 1px solid var(--border); cursor: pointer; flex-shrink: 0; background: var(--thumb-bg); | |
| } | |
| .history-chip:hover { border-color: var(--accent); } | |
| .history-chip video { width: 100%; height: 100%; object-fit: cover; } | |
| .history-chip .hseed { | |
| position: absolute; bottom: 0; left: 0; right: 0; font-size: 0.58rem; font-family: "IBM Plex Mono", monospace; | |
| background: rgba(0,0,0,0.55); color: #e5e5e5; padding: 1px 4px; text-align: right; | |
| } | |
| /* ---------- examples + statusbar ---------- */ | |
| .examples { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 20px 8px; } | |
| .ex-chip { | |
| border: 1px solid var(--border); background: var(--panel); color: var(--muted); | |
| border-radius: 999px; padding: 5px 12px; font-size: 0.75rem; font-weight: 500; | |
| cursor: pointer; font-family: inherit; transition: color 0.15s, border-color 0.15s; | |
| } | |
| .ex-chip:hover { color: var(--text); border-color: var(--accent); } | |
| .statusbar { | |
| display: flex; align-items: center; gap: 10px; padding: 7px 16px; flex-shrink: 0; | |
| background: var(--panel); border-top: 1px solid var(--hairline); | |
| font-size: 0.76rem; color: var(--muted); | |
| } | |
| .statusbar .pulse { | |
| width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex-shrink: 0; | |
| } | |
| .statusbar.busy .pulse { background: var(--accent2); animation: pulse 1.1s ease-in-out infinite; } | |
| @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } } | |
| #status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } | |
| </style> | |
| </head> | |
| <body> | |
| <header class="topbar"> | |
| <div class="brand"><span class="logo"><svg width="22" height="22" viewBox="0 0 24 24" aria-hidden="true"><rect width="24" height="24" rx="6" fill="#84cc16"/><path d="M6 17V7l6 6 6-6v10" stroke="#18181b" stroke-width="2.2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg></span>LongCat Avatar<span class="studio-badge">Studio</span></div> | |
| <nav class="mode-tabs"> | |
| <button id="mode-studio" class="active">Studio</button> | |
| <button id="mode-workflow">Workflow</button> | |
| </nav> | |
| <div class="spacer"></div> | |
| <a class="ml-badge" href="https://huggingface.co/meituan-longcat/LongCat-Video-Avatar-1.6" target="_blank" rel="noopener">LongCat-Video-Avatar 1.6</a> | |
| <a class="ml-badge-img" href="https://hf.co/chat?mode=ml-intern" target="_blank" rel="noopener"><img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/built-with-ml-intern-sm.svg" alt="Built with ML Intern" /></a> | |
| <button class="theme-toggle" id="theme-toggle" data-mode="light" aria-label="Switch to dark mode"> | |
| <svg class="theme-icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M4.9 4.9l1.4 1.4m11.4 11.4 1.4 1.4M2 12h2m16 0h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg> | |
| <svg class="theme-icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8z"/></svg> | |
| </button> | |
| </header> | |
| <div class="main"> | |
| <div class="viewport"> | |
| <div class="workflow-view" id="workflow-view" hidden> | |
| <iframe src="/workflow" title="Workflow canvas"></iframe> | |
| </div> | |
| <div class="workspace" id="workspace"> | |
| <aside class="controls"> | |
| <section class="panel"> | |
| <div class="panel-title">Reference portrait</div> | |
| <div class="drop" id="image-drop"> | |
| <div class="hint" id="image-hint"><b>Drop a portrait</b>or click to upload — a face, chest-up, looking at the camera works best</div> | |
| <img id="image-preview" hidden alt="Reference portrait" /> | |
| </div> | |
| <input type="file" id="image-input" accept="image/*" hidden /> | |
| </section> | |
| <section class="panel"> | |
| <div class="panel-title">Driving audio</div> | |
| <div class="drop" id="audio-drop"> | |
| <div class="hint" id="audio-hint"><b>Drop an audio clip</b>or click to upload — speech or singing, ~5 s is one video</div> | |
| <audio id="audio-preview" controls hidden></audio> | |
| </div> | |
| <input type="file" id="audio-input" accept="audio/*" hidden /> | |
| </section> | |
| <section class="panel"> | |
| <div class="panel-title">Direction</div> | |
| <div class="field"> | |
| <label for="prompt">Prompt</label> | |
| <textarea id="prompt" placeholder="e.g. A person is speaking expressively, looking at the camera.">A person is speaking expressively, looking at the camera.</textarea> | |
| </div> | |
| <div class="row"> | |
| <div class="field"> | |
| <label for="resolution">Resolution</label> | |
| <select id="resolution"> | |
| <option value="480p" selected>480p (480×832)</option> | |
| <option value="720p">720p (768×1280)</option> | |
| </select> | |
| </div> | |
| <div class="field"> | |
| <label for="seed">Seed</label> | |
| <input type="number" id="seed" value="42" min="0" /> | |
| </div> | |
| </div> | |
| <div class="check"><input type="checkbox" id="randomize" checked /><label for="randomize">Randomize seed</label></div> | |
| </section> | |
| <section class="panel"> | |
| <div class="panel-title">Advanced</div> | |
| <div class="field"> | |
| <label for="vocal-mode">Audio preprocessing</label> | |
| <select id="vocal-mode"> | |
| <option value="clean" selected>Clean speech (fast)</option> | |
| <option value="isolate">Isolate vocals (quality — separates music)</option> | |
| </select> | |
| </div> | |
| <div class="field"> | |
| <label for="acceleration">Acceleration</label> | |
| <select id="acceleration"> | |
| <option value="dbcache_faster" selected>DBCache faster</option> | |
| <option value="dbcache">DBCache fast</option> | |
| <option value="exact">Exact 8-step</option> | |
| </select> | |
| </div> | |
| </section> | |
| <button class="run-btn" id="run-btn">Generate video</button> | |
| </aside> | |
| <div class="stage-col"> | |
| <figure class="doc"> | |
| <figcaption>Result · ~5 s @ 25 fps<span class="meta" id="result-meta">—</span></figcaption> | |
| <div class="stage" id="stage"> | |
| <div class="hint" id="result-hint"><span class="big">🎬</span>Upload a portrait and an audio clip,<br/>then hit <b>Generate video</b>.</div> | |
| <video id="result-video" controls loop autoplay muted hidden playsinline></video> | |
| </div> | |
| </figure> | |
| <div class="history-strip" id="history-strip"><span class="hlabel">History</span></div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="examples" id="examples"></div> | |
| <footer class="statusbar" id="statusbar"> | |
| <span class="pulse"></span><span id="status">Idle</span> | |
| </footer> | |
| <script type="module"> | |
| import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client@2.5.0/dist/index.min.js"; | |
| const $ = (id) => document.getElementById(id); | |
| const state = { imagePath: null, audioPath: null, app: null, history: [] }; | |
| const EXAMPLES = [ | |
| { label: "Studio presenter", prompt: "A photorealistic person speaking naturally to the camera in a clean studio portrait, soft neutral background, realistic facial expression." }, | |
| { label: "Cartoon character", prompt: "A friendly cartoon character speaking to the camera against a soft blue background, simple flat illustration style." }, | |
| { label: "Fantasy warrior", prompt: "A fantasy warrior portrait speaking directly to the camera, cinematic studio lighting, detailed armor, expressive face, smoky neutral backdrop." }, | |
| { label: "Podcast host", prompt: "A podcast host talking into a microphone, warm desk lamp lighting, bookshelf softly blurred behind them, natural hand gestures." }, | |
| ]; | |
| 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 ---------- | |
| const themeBtn = $("theme-toggle"); | |
| function applyTheme(mode) { | |
| document.body.classList.toggle("dark", mode === "dark"); | |
| themeBtn.dataset.mode = mode; | |
| const label = mode === "dark" ? "Switch to light mode" : "Switch to dark mode"; | |
| themeBtn.setAttribute("aria-label", label); | |
| themeBtn.setAttribute("title", label); | |
| try { localStorage.setItem("longcat-theme", mode); } catch (e) {} | |
| } | |
| themeBtn.onclick = () => applyTheme(document.body.classList.contains("dark") ? "light" : "dark"); | |
| (function initTheme() { | |
| let mode = "light"; | |
| try { if (localStorage.getItem("longcat-theme") === "dark") mode = "dark"; } catch (e) {} | |
| applyTheme(mode); | |
| })(); | |
| // ---------- view tabs ---------- | |
| function setMode(mode) { | |
| $("mode-studio").classList.toggle("active", mode === "studio"); | |
| $("mode-workflow").classList.toggle("active", mode === "workflow"); | |
| $("workflow-view").hidden = mode !== "workflow"; | |
| $("workspace").style.display = mode === "workflow" ? "none" : ""; | |
| $("examples").style.display = mode === "workflow" ? "none" : ""; | |
| } | |
| $("mode-studio").onclick = () => setMode("studio"); | |
| $("mode-workflow").onclick = () => setMode("workflow"); | |
| // ---------- uploads ---------- | |
| function wireUpload(dropId, inputId, accept, onFile) { | |
| const drop = $(dropId), input = $(inputId); | |
| drop.addEventListener("click", (e) => { | |
| if (e.target.closest("audio") || e.target.closest("img")) return; | |
| input.click(); | |
| }); | |
| input.onchange = async (e) => { | |
| const file = e.target.files[0]; | |
| e.target.value = ""; | |
| if (file) await handleFile(file); | |
| }; | |
| drop.addEventListener("dragover", (e) => e.preventDefault()); | |
| drop.addEventListener("drop", async (e) => { | |
| e.preventDefault(); | |
| const file = e.dataTransfer.files[0]; | |
| if (file) await handleFile(file); | |
| }); | |
| async function handleFile(file) { | |
| if (accept === "image" && !file.type.startsWith("image/")) { setStatus("That file is not an image."); return; } | |
| if (accept === "audio" && !file.type.startsWith("audio/") && !/\.(wav|mp3|m4a|flac|ogg|aac)$/i.test(file.name)) { | |
| setStatus("That file is not audio."); return; | |
| } | |
| setStatus("Uploading…", true); | |
| try { | |
| const path = await uploadFile(file); | |
| onFile(path, file); | |
| setStatus("Idle"); | |
| } catch (err) { | |
| setStatus(String(err)); | |
| } | |
| } | |
| } | |
| wireUpload("image-drop", "image-input", "image", (path, file) => { | |
| state.imagePath = path; | |
| const img = $("image-preview"); | |
| img.src = URL.createObjectURL(file); | |
| img.hidden = false; | |
| $("image-hint").style.display = "none"; | |
| }); | |
| wireUpload("audio-drop", "audio-input", "audio", (path, file) => { | |
| state.audioPath = path; | |
| const el = $("audio-preview"); | |
| el.src = URL.createObjectURL(file); | |
| el.hidden = false; | |
| $("audio-hint").style.display = "none"; | |
| }); | |
| // ---------- history ---------- | |
| function renderHistory() { | |
| const strip = $("history-strip"); | |
| strip.innerHTML = '<span class="hlabel">History</span>'; | |
| state.history.forEach((h) => { | |
| const chip = document.createElement("div"); | |
| chip.className = "history-chip"; | |
| chip.title = h.prompt || ""; | |
| const vid = document.createElement("video"); | |
| vid.src = h.url; | |
| vid.muted = true; | |
| vid.loop = true; | |
| vid.onmouseenter = () => vid.play(); | |
| vid.onmouseleave = () => vid.pause(); | |
| const tag = document.createElement("div"); | |
| tag.className = "hseed"; | |
| tag.textContent = h.seed ?? ""; | |
| chip.appendChild(vid); | |
| chip.appendChild(tag); | |
| chip.onclick = () => { | |
| $("prompt").value = h.prompt; | |
| $("seed").value = h.seed ?? 42; | |
| $("randomize").checked = false; | |
| showVideo(h.url, h.info || "", h.seed); | |
| }; | |
| strip.appendChild(chip); | |
| }); | |
| } | |
| function pushHistory(url, seed, prompt, info) { | |
| state.history.unshift({ url, seed, prompt, info }); | |
| if (state.history.length > 8) state.history.pop(); | |
| renderHistory(); | |
| } | |
| // ---------- result ---------- | |
| function showVideo(url, info, seed) { | |
| const video = $("result-video"); | |
| video.src = url; | |
| video.hidden = false; | |
| video.muted = false; | |
| $("result-hint").style.display = "none"; | |
| $("result-meta").textContent = info || "Done"; | |
| video.play().catch(() => {}); | |
| } | |
| function unwrap(result) { | |
| const data = Array.isArray(result?.data) ? result.data[0] : result?.data; | |
| return data ?? {}; | |
| } | |
| // ---------- examples ---------- | |
| const exRow = $("examples"); | |
| EXAMPLES.forEach((ex) => { | |
| const chip = document.createElement("button"); | |
| chip.className = "ex-chip"; | |
| chip.textContent = ex.label; | |
| chip.onclick = () => { | |
| $("prompt").value = ex.prompt; | |
| setStatus("Example prompt loaded — upload a portrait and audio, then hit Generate"); | |
| }; | |
| exRow.appendChild(chip); | |
| }); | |
| // ---------- run ---------- | |
| $("run-btn").onclick = async () => { | |
| if (!state.imagePath) { setStatus("Upload a reference portrait first."); return; } | |
| if (!state.audioPath) { setStatus("Upload a driving audio clip first."); return; } | |
| const prompt = $("prompt").value.trim(); | |
| if (!prompt) { setStatus("Write a prompt first."); return; } | |
| const app = await getApp(); | |
| setStatus("Generating — this takes a few minutes on the GPU…", true); | |
| try { | |
| const result = await app.predict("/generate", { | |
| image: state.imagePath, | |
| audio: state.audioPath, | |
| prompt, | |
| resolution: $("resolution").value, | |
| seed: parseInt($("seed").value, 10) || 0, | |
| randomize: $("randomize").checked, | |
| vocal_mode: $("vocal-mode").value, | |
| acceleration: $("acceleration").value, | |
| }); | |
| const payload = unwrap(result); | |
| if (!payload.video_url) { setStatus("Run finished but no video came back (see console)."); return; } | |
| showVideo(payload.video_url, payload.info, payload.seed); | |
| pushHistory(payload.video_url, payload.seed, prompt, payload.info); | |
| setStatus("Done"); | |
| } catch (err) { | |
| setStatus(err?.message || String(err)); | |
| } | |
| }; | |
| </script> | |
| </body> | |
| </html> | |