Spaces:
Running
Running
Update index.html
Browse files1223456567889111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219310111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667681996970711 unmodified line7374752077677787980812132142152162172188283842208586878822422589909192939495969798991001011021032291041051061072331081092352361101111121131141152421161171181192471201211221231242531251261272571281292592601301311321332 unmodified lines1361371382691391401413 unmodified lines1451461472791481492811501512832841521531541552871562892901571581591602941611622961631641651661673011681691703051711721731741751763103113123133143153163173183193203213223231773253263273281781791801811821831 unmodified line1851861873363373381881891901911921936 unmodified lines2002012023512032042053552062072082091 unmodified line2112122133633643652142152162172182193 unmodified lines22322422537537637722622722822923023123238423323438623523623723814 unmodified lines2532542554074082564094102572582599 unmodified lines2692702714262722732744 unmodified lines27928028143743843928228328428528628710 unmodified lines29829930045645745830130230330430530630730830946531031131210 unmodified lines32332432548232632732832948633033133233349149233433549449549649749849933633733833934028 unmodified lines3693703715343723733743 unmodified lines3783793805443813825463833843853862 unmodified lines3893903915553923935573943953963975 unmodified lines40340440556957057157240640740840922 unmodified lines4324334346014354366034374384394404414424436104444454461 unmodified line4484494506184514524535 unmodified lines4594604616306316324624634644656 unmodified lines4724734746456466474754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815826565835846586596606616626636646656665855865875885895905915925935945959 unmodified lines6056066076876886896086096106119 unmodified lines6216226237056246256266276286296302 unmodified lines63363463571663663771863863964064136 unmodified lines678679680761681682763683684685686687768688689690691692
<!DOCTYPE html><!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>UR5e GELLO Dataset Viewer</title>
<style> :root { --bg: #f5f7fb; --card: #ffffff; --ink: #1c2940; --muted: #66758c; --line: #dfe5ef; --blue: #2757bb; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, sans-serif; }
header { background: #162f59; color: white; padding: 20px max(18px, calc((100vw - 1160px)/2)); }
h1 { font-size: 23px; margin: 0 0 4px; } header p { color: #d8e3f5; margin: 0; }
main { max-width: 1160px; margin: 22px auto 45px; padding: 0 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
h2 { font-size: 17px; margin: 0 0 13px; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 5px; }
input[type=url], select, button { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 8px; min-height: 44px; }
input[type=url], select { width: 100%; background: white; min-width: 0; }
button { cursor: pointer; background: white; font-weight: 600; }
button:disabled, select:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; } .note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.status { font-size: 13px; color: #20613f; margin: 10px 0 0; overflow-wrap: anywhere; }
.status.error { color: #ad3039; }
.views { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.view { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #101a2b; }
.view-title { background: white; padding: 10px 12px; font-weight: 600; font-size: 13px; }
.image-wrap { min-height: 240px; padding: 10px; display: grid; place-items: center; }
canvas { display: block; max-width: 100%; max-height: 420px; object-fit: contain; }
.placeholder { color: #cbd6e8; font-size: 13px; }
.controls { display: flex; align-items: center; gap: 10px; margin-top: 15px; }
#frame { width: 100%; accent-color: var(--blue); }
#frameLabel { white-space: nowrap; font-size: 13px; color: var(--muted); }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { background: #fafbff; border: 1px solid var(--line); padding: 11px; border-radius: 8px; min-width: 0; }
.field b { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.field pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 12px; }
@media (max-width: 700px) { .views, .fields { grid-template-columns: 1fr; } .image-wrap { min-height: 170px; } --bg:#f5f7fb; --card:#fff; --ink:#1c2940; --muted:#66758c; --line:#dfe5ef; --blue:#2757bb; } * {box-sizing:border-box} body {margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 system-ui,sans-serif} header {background:#162f59;color:white;padding:20px max(18px,calc((100vw - 1160px)/2))} h1 {font-size:23px;margin:0 0 4px} header p {color:#d8e3f5;margin:0} main {max-width:1160px;margin:22px auto 45px;padding:0 16px;display:grid;gap:16px} .card {background:var(--card);border:1px solid var(--line);border-radius:12px;padding:20px} h2 {font-size:17px;margin:0 0 13px} label {display:block;color:var(--muted);font-size:12px;font-weight:700;margin-bottom:5px} input[type=url],select,button {font:inherit;padding:10px;border:1px solid var(--line);border-radius:8px;min-height:44px} input[type=url],select {width:100%;background:white;min-width:0} button {cursor:pointer;background:white;font-weight:600} button:disabled,select:disabled {opacity:.45;cursor:not-allowed} .row {display:flex;gap:10px;align-items:end;flex-wrap:wrap} .grow {flex:1;min-width:200px} .note {font-size:12px;color:var(--muted);margin:10px 0 0} .status {font-size:13px;color:#20613f;margin:10px 0 0;overflow-wrap:anywhere} .status.error {color:#ad3039} [hidden] {display:none !important}
/* Download progress */ .download-progress {margin-top:12px} .progress-head {display:flex;justify-content:space-between;gap:12px;font-size:13px;font-weight:600} #downloadBar {display:block;width:100%;height:16px;margin-top:6px;accent-color:var(--blue)}
/* Camera views */ .views {display:grid;grid-template-columns:1fr 1fr;gap:12px} .view {border:1px solid var(--line);border-radius:9px;overflow:hidden;background:#101a2b} .view-title {background:white;padding:10px 12px;font-weight:600;font-size:13px} .image-wrap {min-height:240px;padding:10px;display:grid;place-items:center} canvas {display:block;max-width:100%;max-height:420px;object-fit:contain} .placeholder {color:#cbd6e8;font-size:13px}
/* Timeline */ .controls {display:flex;align-items:center;gap:10px;margin-top:15px} #frame {width:100%;accent-color:var(--blue)} #frameLabel {white-space:nowrap;font-size:13px;color:var(--muted)}
/* Robot observations */ .fields {display:grid;grid-template-columns:1fr 1fr;gap:10px} .field {background:#fafbff;border:1px solid var(--line);padding:11px;border-radius:8px;min-width:0} .field b {display:block;color:var(--muted);font-size:12px;margin-bottom:6px} .field pre {white-space:pre-wrap;overflow-wrap:anywhere;margin:0;font-size:12px}
@media(max-width:700px){ .views,.fields {grid-template-columns:1fr} .image-wrap {min-height:170px} } </style></head>
<body>
<header> <h1>UR5e GELLO · HDF5 Demonstration Viewer</h1> <p>Peg-in-hole insertion dataset · Browser-based, read-only</p>1 unmodified line
<main>
<!-- Dataset URL --> <!-- Dataset loading --> <section class="card"> <h2>1. Load dataset from Hugging Face</h2>
<div class="row"> <div class="grow"> <label for="url">Hugging Face HDF5 file URL</label> <input id="url" type="url" value="https://huggingface.co/datasets/ns69956/UR5e-PegInsertion/blob/main/square_hole_box.hdf5" > <label for="url">Hugging Face file URL (paste the usual /blob/ link)</label> <input id="url" type="url" value="https://huggingface.co/datasets/ns69956/UR5e-PegInsertion/blob/main/square_hole_box.hdf5"> </div> <button id="load" type="button" disabled>Load Dataset</button> <button id="load" type="button" disabled>Load dataset</button> </div>
<p class="note"> Paste a Hugging Face /blob/ URL. It will automatically be converted to the raw /resolve/ URL. The viewer automatically changes /blob/ into /resolve/. It requires a public HDF5 file and browser-permitted cross-origin access. </p>
<!-- Download progress --> <div id="downloadBox" class="download-progress" hidden> <div class="progress-head"> <span id="downloadTitle">Downloading…</span> <span id="downloadPercent">0%</span> </div> <progress id="downloadBar" max="100" value="0"></progress> <p id="downloadDetail" class="note">0 MB downloaded</p> </div>
<p id="status" class="status" role="status"> Initializing HDF5 reader... Initializing HDF5 reader… </p> </section>
<!-- Demonstration Selection --> <!-- Demonstration selector --> <section class="card"> <h2>2. Select Demonstration and Cameras</h2>
<h2>2. Select demonstration and cameras</h2> <div class="row"> <div class="grow"> <label for="demo">Demonstration</label> <select id="demo" disabled></select> </div>
<div class="grow"> <label for="cam1">Camera 1</label> <select id="cam1" disabled></select> </div>
<div class="grow"> <label for="cam2">Camera 2</label> <select id="cam2" disabled></select> </div> </div>
<p id="meta" class="note">No dataset loaded</p> </section>
<!-- Camera Visualization --> <!-- Camera observations --> <section class="card"> <h2>3. Camera Observations</h2>
<h2>3. Camera observations</h2> <div class="views"> <div class="view"> <div id="name1" class="view-title">Camera 1</div>2 unmodified lines <span id="empty1" class="placeholder">No image loaded</span> </div> </div>
<div class="view"> <div id="name2" class="view-title">Camera 2</div> <div class="image-wrap">3 unmodified lines </div> </div>
<!-- Frame Controls --> <!-- Frame navigation --> <div class="controls"> <button id="prev" disabled>←</button> <button id="prev" disabled aria-label="Previous frame">←</button> <button id="play" disabled>Play</button> <input id="frame" type="range" min="0" max="0" value="0" step="1" disabled> <button id="next" disabled>→</button> <input id="frame" type="range" min="0" max="0" value="0" step="1" disabled aria-label="Frame"> <button id="next" disabled aria-label="Next frame">→</button> <output id="frameLabel">0 / 0</output> </div>
<p class="note"> Playback runs at 4 frames per second for visualization, independent of the original recording rate. Playback is for browsing only (4 frames/second), not the original recording rate. </p> </section>
<!-- Robot State Information --> <!-- Robot observations --> <section class="card"> <h2>4. Robot States and Actions</h2> <h2>4. Robot states and actions</h2> <div id="fields" class="fields"> <div class="field">Load a dataset to view observations.</div> </div> </section>
</main>
<script type="module">
import h5wasm from 'https://cdn.jsdelivr.net/npm/h5wasm@0.10.3/dist/esm/hdf5_hl.js';
const $ = id => document.getElementById(id);const obsFields = ['tcp_pos', 'tcp_quat', 'joints', 'gripper_position', 'wrench'];let FS, h5, demos = [], currentDemo = '', lastFrame = 0, playback = null;
const obsFields = [ 'tcp_pos', 'tcp_quat', 'joints', 'gripper_position', 'wrench'];
let FS;let h5;let demos = [];let currentDemo = '';let lastFrame = 0;let playback = null;
// --------------------------------------// Status Messages// --------------------------------------// ----------------------------------------// Status// ----------------------------------------
function status(message, error = false) { $('status').textContent = message;1 unmodified line}
// --------------------------------------// Hugging Face URL Handling// --------------------------------------// ----------------------------------------// Hugging Face URL// ----------------------------------------
function normalizeUrl(input) { const url = new URL(input.trim());6 unmodified lines throw new Error('This must be a Hugging Face dataset file link.'); }
// Automatically convert /blob/ to /resolve/ url.pathname = url.pathname.replace('/blob/', '/resolve/');
if (!url.pathname.includes('/resolve/')) { throw new Error('Provide a link to a specific HDF5 file.'); throw new Error('Copy a link to a specific HDF5 file, not the dataset homepage.'); }
url.hash = '';1 unmodified line}
// --------------------------------------// HDF5 File Validation// --------------------------------------// ----------------------------------------// HDF5 Validation// ----------------------------------------
function validHdf5(bytes) { const magic = [137, 72, 68, 70, 13, 10, 26, 10];3 unmodified lines offset + 8 <= bytes.length && offset <= 65536; offset = offset === 0 ? 512 : offset * 2 ) { if (magic.every((v, i) => bytes[offset + i] === v)) { return true; } if (magic.every((v, i) => bytes[offset + i] === v)) return true; }
return false;}
// --------------------------------------// ----------------------------------------// HDF5 Utilities// --------------------------------------// ----------------------------------------
function keys(path) { try {14 unmodified lines
function getFrame(path, t) { const ds = getDataset(path);
if (!ds || !ds.shape.length || t >= ds.shape[0]) { if (!ds || !ds.shape.length || t >= ds.shape[0]) return null; return null; }
return { values: ds.slice([9 unmodified lines if (!result) return 'N/A';
const values = Array.from(result.values);
const shown = values.slice(0, 80).map(v => typeof v === 'number' && Number.isFinite(v) ? Number(v.toFixed(5))4 unmodified lines}
// --------------------------------------// Dropdown Utilities// --------------------------------------// ----------------------------------------// Dropdowns// ----------------------------------------
function selectOptions(id, options) { const element = $(id);10 unmodified lines}
// --------------------------------------// Image Visualization// --------------------------------------// ----------------------------------------// Image Rendering// ----------------------------------------
function drawImage(canvasId, emptyId, titleId, key, t) { const canvas = $(canvasId); const empty = $(emptyId);
$(titleId).textContent = key || 'No camera';
canvas.hidden = true; empty.hidden = false; empty.textContent = key ? 'Image unavailable' : 'No camera selected';10 unmodified lines ![2, 3].includes(result.shape.length) || ![1, 3, 4].includes(channels) ) { throw new Error(`Unsupported image shape: [${result.shape.join(', ')}]`); throw new Error(`Unsupported shape: [${result.shape.join(', ')}]`); }
const raw = result.values;
if (raw.length !== width * height * channels) { throw new Error('Invalid image data shape'); }
let scale = 1; let shift = 0; let scale = 1, shift = 0;
if ( !(raw instanceof Uint8Array) && !(raw instanceof Uint8ClampedArray) ) { let min = Infinity; let max = -Infinity; if (!(raw instanceof Uint8Array || raw instanceof Uint8ClampedArray)) { let min = Infinity, max = -Infinity;
for (const v of raw) { if (Number.isFinite(v)) {28 unmodified lines }
ctx.putImageData(img, 0, 0);
canvas.hidden = false; empty.hidden = true;
3 unmodified lines}
// --------------------------------------// ----------------------------------------// Playback// --------------------------------------// ----------------------------------------
function stopPlayback() { if (playback) clearInterval(playback);2 unmodified lines}
// --------------------------------------// ----------------------------------------// Render Selected Frame// --------------------------------------// ----------------------------------------
function render() { if (!h5 || !currentDemo) return;5 unmodified lines drawImage('image2', 'empty2', 'name2', $('cam2').value, t);
const fields = [ ...obsFields.map(key => [ key, `data/${currentDemo}/obs/${key}` ]), ...obsFields.map(key => [key, `data/${currentDemo}/obs/${key}`]), ['actions', `data/${currentDemo}/actions`], ['rewards', `data/${currentDemo}/rewards`], ['dones', `data/${currentDemo}/dones`]22 unmodified lines}
// --------------------------------------// ----------------------------------------// Demonstration Selection// --------------------------------------// ----------------------------------------
function chooseDemo(name) { stopPlayback(); currentDemo = name;
const obsPath = `data/${name}/obs`;
const actionCount = getDataset(`data/${name}/actions`)?.shape[0]; const firstObs = keys(obsPath)[0];
1 unmodified line getDataset(`${obsPath}/${firstObs}`)?.shape[0] ?? 0;
lastFrame = Math.max(0, count - 1);
$('frame').max = lastFrame; $('frame').value = 0;
5 unmodified lines selectOptions('cam1', cameras); selectOptions('cam2', ['', ...cameras]);
if (cameras.length > 1) { $('cam2').value = cameras[1]; } if (cameras.length > 1) $('cam2').value = cameras[1];
for (const id of ['frame', 'prev', 'next', 'play']) { $(id).disabled = count < 2;6 unmodified lines}
// --------------------------------------// Download Dataset from Hugging Face// --------------------------------------// ----------------------------------------// Download Progress Utilities// ----------------------------------------
function mb(bytes) { return (bytes / (1024 * 1024)).toFixed(1) + ' MB';}
function updateProgress(received, total, startTime) { const bar = $('downloadBar'); const elapsed = Math.max((performance.now() - startTime) / 1000, 0.1); const speed = mb(received / elapsed) + '/s';
if (total) { const pct = Math.min(100, (received / total) * 100);
bar.value = pct; $('downloadPercent').textContent = pct.toFixed(1) + '%'; $('downloadDetail').textContent = `${mb(received)} / ${mb(total)} · ${speed}`; } else { // Unknown content length bar.removeAttribute('value'); $('downloadPercent').textContent = 'Downloading…'; $('downloadDetail').textContent = `${mb(received)} downloaded · ${speed}`; }}
// ----------------------------------------// Stream Download With Progress// ----------------------------------------
async function downloadWithProgress(url) { $('downloadBox').hidden = false; $('downloadTitle').textContent = 'Downloading HDF5 file'; $('downloadBar').value = 0; $('downloadPercent').textContent = '0%'; $('downloadDetail').textContent = 'Connecting to Hugging Face…';
const response = await fetch(url, { redirect: 'follow' });
if (!response.ok) { throw new Error( `HTTP ${response.status}: verify that the dataset and file are public.` ); }
const contentLength = Number(response.headers.get('content-length')); const total = Number.isFinite(contentLength) && contentLength > 0 ? contentLength : null;
const startTime = performance.now(); let received = 0; let bytes;
if (response.body && typeof response.body.getReader === 'function') { const reader = response.body.getReader(); const chunks = [];
while (true) { const { done, value } = await reader.read(); if (done) break; if (!value || !value.length) continue;
chunks.push(value); received += value.length; updateProgress(received, total, startTime); }
bytes = new Uint8Array(received); let offset = 0;
for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.length; }
} else { // Fallback if browser does not expose a readable stream updateProgress(0, null, startTime); bytes = new Uint8Array(await response.arrayBuffer()); received = bytes.length; }
$('downloadBar').value = 100; $('downloadPercent').textContent = '100%'; $('downloadTitle').textContent = 'Download complete'; $('downloadDetail').textContent = `${mb(received)} downloaded`;
return bytes;}
// ----------------------------------------// Load Dataset// ----------------------------------------
async function loadDataset() { stopPlayback(); $('load').disabled = true; $('downloadBox').hidden = true;
try { const url = normalizeUrl($('url').value);
status('Downloading HDF5 file from Hugging Face...'); status('Downloading HDF5 file from Hugging Face…');
const response = await fetch(url, { redirect: 'follow' });
if (!response.ok) { throw new Error( `HTTP ${response.status}: verify that the dataset and file are public.` ); }
const bytes = new Uint8Array(await response.arrayBuffer()); const bytes = await downloadWithProgress(url);
if (!validHdf5(bytes)) { throw new Error('The URL did not return valid HDF5 content.'); }
status('Download complete. Opening HDF5 dataset…');
if (h5) h5.close();
try {9 unmodified lines
demos = keys('data') .filter(name => /^demo_\d+$/.test(name)) .sort((a, b) => Number(a.slice(5)) - Number(b.slice(5)) ); .sort((a, b) => Number(a.slice(5)) - Number(b.slice(5)));
if (!demos.length) { throw new Error('No demo_* trajectories found under /data.');9 unmodified lines
} catch (err) { const message = err instanceof TypeError ? 'Browser download failed. The file may be private, unavailable, or blocked by CORS.' ? 'Browser download failed. The file may be private, unavailable, or blocked by CORS on a Hugging Face storage redirect.' : `Unable to load dataset: ${err.message}`;
$('downloadTitle').textContent = 'Download interrupted'; status(message, true);
} finally {2 unmodified lines}
// --------------------------------------// ----------------------------------------// Event Listeners// --------------------------------------// ----------------------------------------
$('load').addEventListener('click', loadDataset);
36 unmodified lines});
// --------------------------------------// ----------------------------------------// Initialize HDF5 Reader// --------------------------------------// ----------------------------------------
try { FS = (await h5wasm.ready).FS; $('load').disabled = false; status('Ready. Paste a Hugging Face /blob/ link and click Load Dataset.');
status('Ready. Paste a dataset link and click Load dataset.');} catch (err) { status(`Unable to initialize HDF5 reader: ${err.message}`, true);}index.html+232-311