// script.js -- renders the Leaderboard and Episode replay tabs from // data.json (built ahead of time by generate_data.py from a real // milo_benchmark results JSON -- see that file's docstring for why // this is a build step rather than a live server call). No network // calls beyond fetching this Space's own data.json/screenshots. function escapeHtml(s) { if (s === null || s === undefined) return ""; return String(s) .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">"); } function setupTabs() { const buttons = document.querySelectorAll(".tab-btn"); buttons.forEach((btn) => { btn.addEventListener("click", () => { buttons.forEach((b) => { b.classList.remove("active"); b.setAttribute("aria-selected", "false"); }); btn.classList.add("active"); btn.setAttribute("aria-selected", "true"); document.querySelectorAll(".tab-panel").forEach((p) => p.classList.remove("active")); document.getElementById(`tab-${btn.dataset.tab}`).classList.add("active"); }); }); } function renderLeaderboard(data) { const wrap = document.getElementById("leaderboard-table-wrap"); const cols = data.leaderboard_columns; const headers = data.leaderboard_headers; let html = ""; for (const c of cols) { html += ``; } html += ""; for (const row of data.leaderboard_rows) { html += ""; for (const c of cols) { html += ``; } html += ""; } html += "
${escapeHtml(headers[c] || c)}
${escapeHtml(row[c] ?? "—")}
"; wrap.innerHTML = html; document.getElementById("source-caption").textContent = data.source_caption; } function renderEpisodeSelect(data) { const select = document.getElementById("episode-select"); select.innerHTML = ""; data.episodes.forEach((ep, i) => { const opt = document.createElement("option"); opt.value = String(i); opt.textContent = ep.title; select.appendChild(opt); }); select.addEventListener("change", () => renderEpisodeDetail(data, Number(select.value))); if (data.episodes.length > 0) renderEpisodeDetail(data, 0); } function renderEpisodeDetail(data, index) { const ep = data.episodes[index]; const container = document.getElementById("episode-detail"); if (!ep) { container.innerHTML = "

No episode selected.

"; return; } const outcomeBadge = ep.goal_success ? 'SUCCESS' : 'FAILED'; let html = `

${outcomeBadge} ${escapeHtml(ep.instruction)}

`; html += `

Why this episode was picked: ${escapeHtml(ep.reason_picked)}

`; html += '
'; html += `
Planner / model
${escapeHtml(ep.model_label)}
`; html += `
Scene
${escapeHtml(ep.scene)} (${escapeHtml(ep.room_type)}) · tier: ${escapeHtml(ep.difficulty_tier)}
`; html += `
Task spec (logged)
goal=${escapeHtml(ep.goal)}, object=${escapeHtml(ep.object)}, target=${escapeHtml(ep.target)}
`; html += `
Task ID
${escapeHtml(ep.task_id)}
`; html += `
Outcome
goal_success=${ep.goal_success}, execution_success=${ep.execution_success}, plan_success=${ep.plan_success}
`; if (ep.failure_cause) { html += `
Failure cause (logged)
${escapeHtml(ep.failure_cause)}
`; } if (ep.planner === "react") { html += `
LLM retry attempts (logged)
${ep.llm_retry_attempts}
`; } html += `
Wall-clock time (logged)
${Math.round(ep.wall_clock_ms)} ms
`; html += "
"; html += "

Reconstructed plan trace (illustration only — not a literal log)

"; html += `

The source results JSON records aggregate counts per episode (action_count, plan_step_count), not a literal per-step action log. The steps below are reconstructed from this task's goal/object/target and this project's documented, deterministic planner behavior (see the Space README and phase_e_milo_benchmark_report.md in the origin repository) — they illustrate the shape of what ran, not a captured trace.

`; html += `
${escapeHtml(ep.plan_trace.join("\n"))}
`; if (ep.screenshots && ep.screenshots.length > 0) { html += `

Screenshots below are generic, illustrative product UI captures from docs/screenshots/demo/ in the origin repository — a single walkthrough, not per-episode captures. They are shown alongside this episode as an example of what the live UI looks like during an instruction/task-in-progress/task-complete flow, not a screenshot of this literal episode's run.

`; html += '
'; for (const shot of ep.screenshots) { html += `Illustrative product UI screenshot: ${escapeHtml(shot)}`; } html += "
"; } container.innerHTML = html; } async function main() { setupTabs(); try { const resp = await fetch("data.json"); if (!resp.ok) throw new Error(`HTTP ${resp.status}`); const data = await resp.json(); renderLeaderboard(data); renderEpisodeSelect(data); } catch (err) { document.getElementById("leaderboard-table-wrap").innerHTML = `

Failed to load data.json: ${escapeHtml(err.message)}

`; } } main();