| <!doctype html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <title>Eval Image Comparison Viewer</title> |
| <style> |
| :root { |
| --bg: #11161d; |
| --panel: #1a212b; |
| --panel2: #232d3a; |
| --fg: #e6edf3; |
| --muted: #9aa7b5; |
| --accent: #4f8cff; |
| --na: #2b333f; |
| --border: #344355; |
| } |
| * { box-sizing: border-box; } |
| body { |
| margin: 0; |
| background: var(--bg); |
| color: var(--fg); |
| font: 14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; |
| } |
| .container { |
| max-width: 1280px; |
| margin: 0 auto; |
| padding: 18px; |
| } |
| .panel { |
| background: var(--panel); |
| border: 1px solid var(--border); |
| border-radius: 10px; |
| padding: 12px; |
| margin-bottom: 12px; |
| } |
| .controls { |
| display: grid; |
| grid-template-columns: repeat(4, minmax(160px, 1fr)); |
| gap: 10px; |
| align-items: end; |
| } |
| label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; } |
| select, input[type="range"], button { |
| width: 100%; |
| background: var(--panel2); |
| color: var(--fg); |
| border: 1px solid var(--border); |
| border-radius: 8px; |
| min-height: 34px; |
| padding: 6px 10px; |
| } |
| button { |
| cursor: pointer; |
| font-weight: 600; |
| } |
| button:hover { border-color: var(--accent); } |
| .row { |
| display: grid; |
| grid-template-columns: repeat(4, 1fr); |
| gap: 8px; |
| margin-top: 8px; |
| } |
| .grid { |
| display: grid; |
| grid-template-columns: repeat(2, 1fr); |
| gap: 10px; |
| } |
| .cell { |
| background: var(--panel2); |
| border: 1px solid var(--border); |
| border-radius: 8px; |
| overflow: hidden; |
| } |
| .cell-hd { |
| padding: 8px 10px; |
| border-bottom: 1px solid var(--border); |
| color: var(--muted); |
| font-size: 12px; |
| } |
| .img-wrap { |
| aspect-ratio: 1 / 1; |
| display: grid; |
| place-items: center; |
| background: #151b23; |
| position: relative; |
| } |
| .img-wrap img { |
| width: 100%; |
| height: 100%; |
| object-fit: contain; |
| display: block; |
| cursor: zoom-in; |
| } |
| .na { |
| width: 100%; |
| height: 100%; |
| display: grid; |
| place-items: center; |
| color: var(--muted); |
| background: var(--na); |
| font-weight: 600; |
| } |
| .prompt { |
| white-space: pre-wrap; |
| color: var(--fg); |
| background: var(--panel2); |
| border: 1px solid var(--border); |
| border-radius: 8px; |
| padding: 10px; |
| min-height: 56px; |
| } |
| .stats { |
| color: var(--muted); |
| font-size: 12px; |
| margin-top: 8px; |
| } |
| .badge { |
| display: inline-block; |
| border: 1px solid var(--border); |
| border-radius: 999px; |
| padding: 2px 8px; |
| margin-right: 6px; |
| margin-bottom: 4px; |
| background: var(--panel2); |
| } |
| .modal { |
| position: fixed; |
| inset: 0; |
| background: rgba(0, 0, 0, 0.85); |
| display: none; |
| align-items: center; |
| justify-content: center; |
| padding: 24px; |
| z-index: 999; |
| } |
| .modal img { |
| max-width: min(96vw, 1400px); |
| max-height: 92vh; |
| object-fit: contain; |
| border: 1px solid var(--border); |
| border-radius: 8px; |
| background: #000; |
| } |
| .hint { color: var(--muted); font-size: 12px; margin-top: 8px; } |
| .error { |
| background: #351b1b; |
| border: 1px solid #864040; |
| color: #ffb4b4; |
| border-radius: 8px; |
| padding: 10px; |
| display: none; |
| margin-bottom: 10px; |
| } |
| </style> |
| </head> |
| <body> |
| <div class="container"> |
| <h2 style="margin:0 0 10px 0;">Cross-Run Eval Image Comparison</h2> |
| <div id="error" class="error"></div> |
| <div class="panel"> |
| <div class="controls"> |
| <div> |
| <label for="evalType">Eval Type</label> |
| <select id="evalType"></select> |
| </div> |
| <div> |
| <label for="promptIdx">Prompt Index</label> |
| <select id="promptIdx"></select> |
| </div> |
| <div> |
| <label for="stepSlider">Step</label> |
| <input id="stepSlider" type="range" min="0" max="0" value="0" /> |
| </div> |
| <div> |
| <label for="speed">Playback Speed</label> |
| <select id="speed"> |
| <option value="1500">0.5x</option> |
| <option value="1000" selected>1x</option> |
| <option value="500">2x</option> |
| </select> |
| </div> |
| </div> |
| <div class="row"> |
| <button id="prevStep">Prev Step</button> |
| <button id="playPause">Play</button> |
| <button id="nextStep">Next Step</button> |
| <button id="copyLink">Copy Deep Link</button> |
| </div> |
| <div class="hint"> |
| Keyboard: Left/Right = step, Up/Down = prompt, Space = play/pause |
| </div> |
| </div> |
|
|
| <div class="panel"> |
| <div id="grid" class="grid"></div> |
| <div style="margin-top:10px;"> |
| <label>Prompt</label> |
| <div id="promptText" class="prompt"></div> |
| </div> |
| <div id="stats" class="stats"></div> |
| </div> |
| </div> |
|
|
| <div id="modal" class="modal"> |
| <img id="modalImg" alt="zoom" /> |
| </div> |
|
|
| <script> |
| const state = { |
| manifest: null, |
| evalType: null, |
| promptIdx: null, |
| stepIdx: 0, |
| playing: false, |
| timer: null, |
| }; |
| |
| const el = { |
| error: document.getElementById("error"), |
| evalType: document.getElementById("evalType"), |
| promptIdx: document.getElementById("promptIdx"), |
| stepSlider: document.getElementById("stepSlider"), |
| speed: document.getElementById("speed"), |
| prevStep: document.getElementById("prevStep"), |
| playPause: document.getElementById("playPause"), |
| nextStep: document.getElementById("nextStep"), |
| copyLink: document.getElementById("copyLink"), |
| grid: document.getElementById("grid"), |
| promptText: document.getElementById("promptText"), |
| stats: document.getElementById("stats"), |
| modal: document.getElementById("modal"), |
| modalImg: document.getElementById("modalImg"), |
| }; |
| |
| function showError(message) { |
| el.error.textContent = message; |
| el.error.style.display = "block"; |
| } |
| |
| function parseQuery() { |
| const q = new URLSearchParams(window.location.search); |
| return { |
| eval: q.get("eval"), |
| idx: q.get("idx"), |
| step: q.get("step"), |
| }; |
| } |
| |
| function updateQuery() { |
| if (!state.manifest) return; |
| const evalData = state.manifest.eval_types[state.evalType]; |
| const steps = evalData.steps; |
| const step = steps[state.stepIdx]; |
| const q = new URLSearchParams(window.location.search); |
| q.set("eval", state.evalType); |
| q.set("idx", String(state.promptIdx)); |
| q.set("step", String(step)); |
| const url = `${window.location.pathname}?${q.toString()}`; |
| window.history.replaceState(null, "", url); |
| } |
| |
| function deepLink() { |
| return window.location.href; |
| } |
| |
| function loadImageCell(label, src) { |
| const cell = document.createElement("div"); |
| cell.className = "cell"; |
| |
| const hd = document.createElement("div"); |
| hd.className = "cell-hd"; |
| hd.textContent = label; |
| cell.appendChild(hd); |
| |
| const wrap = document.createElement("div"); |
| wrap.className = "img-wrap"; |
| |
| if (src) { |
| const img = document.createElement("img"); |
| img.loading = "lazy"; |
| img.src = src; |
| img.alt = label; |
| img.addEventListener("click", () => { |
| el.modalImg.src = src; |
| el.modal.style.display = "flex"; |
| }); |
| img.addEventListener("error", () => { |
| wrap.innerHTML = `<div class="na">Load failed</div>`; |
| }); |
| wrap.appendChild(img); |
| } else { |
| wrap.innerHTML = `<div class="na">N/A</div>`; |
| } |
| cell.appendChild(wrap); |
| return cell; |
| } |
| |
| function getCurrentFrame() { |
| const evalData = state.manifest.eval_types[state.evalType]; |
| const idxKey = String(state.promptIdx); |
| const steps = evalData.steps; |
| const step = steps[state.stepIdx]; |
| const row = ((evalData.grid[idxKey] || {})[String(step)] || {}); |
| return { evalData, step, row }; |
| } |
| |
| function render() { |
| if (!state.manifest) return; |
| const { evalData, step, row } = getCurrentFrame(); |
| |
| const runOrder = state.manifest.metadata.run_order; |
| el.grid.innerHTML = ""; |
| let missing = 0; |
| for (const label of runOrder) { |
| const src = row[label] || null; |
| if (!src) missing += 1; |
| el.grid.appendChild(loadImageCell(label, src)); |
| } |
| |
| const idxKey = String(state.promptIdx); |
| el.promptText.textContent = evalData.prompts[idxKey] || "(no prompt)"; |
| el.stats.innerHTML = ` |
| <span class="badge">eval: ${state.evalType}</span> |
| <span class="badge">idx: ${idxKey}</span> |
| <span class="badge">step: ${step}</span> |
| <span class="badge">missing: ${missing}/${runOrder.length}</span> |
| `; |
| updateQuery(); |
| } |
| |
| function refreshSelectors() { |
| const evalData = state.manifest.eval_types[state.evalType]; |
| const indices = evalData.indices; |
| const steps = evalData.steps; |
| |
| el.promptIdx.innerHTML = ""; |
| for (const idx of indices) { |
| const option = document.createElement("option"); |
| option.value = String(idx); |
| option.textContent = String(idx).padStart(3, "0"); |
| if (String(idx) === String(state.promptIdx)) option.selected = true; |
| el.promptIdx.appendChild(option); |
| } |
| |
| el.stepSlider.min = "0"; |
| el.stepSlider.max = String(Math.max(0, steps.length - 1)); |
| el.stepSlider.value = String(state.stepIdx); |
| } |
| |
| function setEvalType(evalType, promptIdx = null, step = null) { |
| const evalData = state.manifest.eval_types[evalType]; |
| if (!evalData) { |
| throw new Error(`unknown eval type: ${evalType}`); |
| } |
| state.evalType = evalType; |
| |
| const indices = evalData.indices; |
| if (!indices.length) { |
| throw new Error(`eval type has no indices: ${evalType}`); |
| } |
| state.promptIdx = promptIdx !== null && indices.includes(promptIdx) |
| ? promptIdx |
| : indices[0]; |
| |
| const steps = evalData.steps; |
| if (!steps.length) { |
| throw new Error(`eval type has no steps: ${evalType}`); |
| } |
| const idx = step !== null ? steps.indexOf(step) : 0; |
| state.stepIdx = idx >= 0 ? idx : 0; |
| refreshSelectors(); |
| render(); |
| } |
| |
| function nextStep(delta) { |
| const evalData = state.manifest.eval_types[state.evalType]; |
| const maxIdx = evalData.steps.length - 1; |
| state.stepIdx = Math.max(0, Math.min(maxIdx, state.stepIdx + delta)); |
| el.stepSlider.value = String(state.stepIdx); |
| render(); |
| } |
| |
| function nextPrompt(delta) { |
| const evalData = state.manifest.eval_types[state.evalType]; |
| const indices = evalData.indices; |
| const pos = indices.indexOf(state.promptIdx); |
| const nextPos = Math.max(0, Math.min(indices.length - 1, pos + delta)); |
| state.promptIdx = indices[nextPos]; |
| el.promptIdx.value = String(state.promptIdx); |
| render(); |
| } |
| |
| function stopPlay() { |
| if (state.timer) { |
| clearInterval(state.timer); |
| state.timer = null; |
| } |
| state.playing = false; |
| el.playPause.textContent = "Play"; |
| } |
| |
| function togglePlay() { |
| if (state.playing) { |
| stopPlay(); |
| return; |
| } |
| const ms = Number(el.speed.value); |
| if (!Number.isFinite(ms) || ms <= 0) { |
| showError(`invalid playback speed: ${el.speed.value}`); |
| return; |
| } |
| state.playing = true; |
| el.playPause.textContent = "Pause"; |
| state.timer = setInterval(() => { |
| const evalData = state.manifest.eval_types[state.evalType]; |
| if (state.stepIdx >= evalData.steps.length - 1) { |
| stopPlay(); |
| return; |
| } |
| nextStep(1); |
| }, ms); |
| } |
| |
| async function init() { |
| try { |
| const res = await fetch("./manifest.json", { cache: "no-store" }); |
| if (!res.ok) { |
| throw new Error(`failed to fetch manifest.json: HTTP ${res.status}`); |
| } |
| state.manifest = await res.json(); |
| if (!state.manifest || !state.manifest.eval_types) { |
| throw new Error("invalid manifest: missing eval_types"); |
| } |
| const evalTypes = Object.keys(state.manifest.eval_types); |
| if (!evalTypes.length) { |
| throw new Error("invalid manifest: eval_types is empty"); |
| } |
| |
| el.evalType.innerHTML = ""; |
| for (const key of evalTypes) { |
| const option = document.createElement("option"); |
| option.value = key; |
| option.textContent = key; |
| el.evalType.appendChild(option); |
| } |
| |
| const q = parseQuery(); |
| const evalType = q.eval && evalTypes.includes(q.eval) ? q.eval : evalTypes[0]; |
| const idx = q.idx !== null ? Number(q.idx) : null; |
| const step = q.step !== null ? Number(q.step) : null; |
| setEvalType(evalType, Number.isFinite(idx) ? idx : null, Number.isFinite(step) ? step : null); |
| |
| el.evalType.addEventListener("change", () => { |
| setEvalType(el.evalType.value); |
| }); |
| el.promptIdx.addEventListener("change", () => { |
| state.promptIdx = Number(el.promptIdx.value); |
| render(); |
| }); |
| el.stepSlider.addEventListener("input", () => { |
| state.stepIdx = Number(el.stepSlider.value); |
| render(); |
| }); |
| el.prevStep.addEventListener("click", () => nextStep(-1)); |
| el.nextStep.addEventListener("click", () => nextStep(1)); |
| el.playPause.addEventListener("click", () => togglePlay()); |
| el.speed.addEventListener("change", () => { |
| if (state.playing) { |
| stopPlay(); |
| togglePlay(); |
| } |
| }); |
| el.copyLink.addEventListener("click", async () => { |
| const url = deepLink(); |
| try { |
| await navigator.clipboard.writeText(url); |
| el.copyLink.textContent = "Copied"; |
| setTimeout(() => { el.copyLink.textContent = "Copy Deep Link"; }, 1200); |
| } catch (err) { |
| showError(`failed to copy link: ${err}`); |
| } |
| }); |
| |
| el.modal.addEventListener("click", () => { |
| el.modal.style.display = "none"; |
| el.modalImg.src = ""; |
| }); |
| |
| document.addEventListener("keydown", (event) => { |
| if (event.key === "ArrowLeft") { |
| event.preventDefault(); |
| nextStep(-1); |
| } else if (event.key === "ArrowRight") { |
| event.preventDefault(); |
| nextStep(1); |
| } else if (event.key === "ArrowUp") { |
| event.preventDefault(); |
| nextPrompt(-1); |
| } else if (event.key === "ArrowDown") { |
| event.preventDefault(); |
| nextPrompt(1); |
| } else if (event.key === " ") { |
| event.preventDefault(); |
| togglePlay(); |
| } |
| }); |
| } catch (err) { |
| showError(String(err)); |
| } |
| } |
| |
| init(); |
| </script> |
| </body> |
| </html> |
|
|