Spaces:
Running
Running
Update index.html
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012021 unmodified line2042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632 unmodified lines2662672682692702712723 unmodified lines2762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303311 unmodified line3333343353363373383393403416 unmodified lines3483493503513523533543553563573581 unmodified line3603613623633643653663673683 unmodified lines37237337437537637737837938038138238338438538638738838914 unmodified lines4044054064074084094104114124139 unmodified lines4234244254264274284294 unmodified lines43443543643743843944044144210 unmodified lines45345445545645745845946046146246346446546646746810 unmodified lines47948048148248348448548648748848949049149249349449549649749849950050150228 unmodified lines5315325335345355365373 unmodified lines5415425435445455465475485492 unmodified lines5525535545555565575585595605 unmodified lines56656756856957057157257357457522 unmodified lines5985996006016026036046056066076086096106116126131 unmodified line6156166176186196206215 unmodified lines6276286296306316326336346356 unmodified lines6426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736749 unmodified lines6846856866876886896906916929 unmodified lines7027037047057067077087097102 unmodified lines71371471571671771871972072136 unmodified lines758759760761762763764765766767768769770771<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><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; }}</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 --><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><inputid="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></div><p class="note">Paste a Hugging Face /blob/ URL. It will automatically be convertedto the raw /resolve/ URL.</p><p id="status" class="status" role="status">Initializing HDF5 reader...</p></section><!-- Demonstration Selection --><section class="card"><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 --><section class="card"><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 --><div class="controls"><button id="prev" disabled>←</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><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.</p></section><!-- Robot State Information --><section class="card"><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;let h5;let demos = [];let currentDemo = '';let lastFrame = 0;let playback = null;// --------------------------------------// Status Messages// --------------------------------------function status(message, error = false) {$('status').textContent = message;1 unmodified line}// --------------------------------------// Hugging Face URL Handling// --------------------------------------function normalizeUrl(input) {const url = new URL(input.trim());6 unmodified linesthrow 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.');}url.hash = '';1 unmodified line}// --------------------------------------// HDF5 File Validation// --------------------------------------function validHdf5(bytes) {const magic = [137, 72, 68, 70, 13, 10, 26, 10];3 unmodified linesoffset + 8 <= bytes.length && offset <= 65536;offset = offset === 0 ? 512 : offset * 2) {if (magic.every((v, i) => bytes[offset + i] === v)) {return true;}}return false;}// --------------------------------------// HDF5 Utilities// --------------------------------------function keys(path) {try {14 unmodified linesfunction getFrame(path, t) {const ds = getDataset(path);if (!ds || !ds.shape.length || t >= ds.shape[0]) {return null;}return {values: ds.slice([9 unmodified linesif (!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// --------------------------------------function selectOptions(id, options) {const element = $(id);10 unmodified lines}// --------------------------------------// Image Visualization// --------------------------------------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(', ')}]`);}const raw = result.values;if (raw.length !== width * height * channels) {throw new Error('Invalid image data shape');}let scale = 1;let shift = 0;if (!(raw instanceof Uint8Array) &&!(raw instanceof Uint8ClampedArray)) {let min = Infinity;let 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 linesdrawImage('image2', 'empty2', 'name2', $('cam2').value, t);const fields = [...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 linegetDataset(`${obsPath}/${firstObs}`)?.shape[0] ?? 0;lastFrame = Math.max(0, count - 1);$('frame').max = lastFrame;$('frame').value = 0;5 unmodified linesselectOptions('cam1', cameras);selectOptions('cam2', ['', ...cameras]);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// --------------------------------------async function loadDataset() {stopPlayback();$('load').disabled = true;try {const url = normalizeUrl($('url').value);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());if (!validHdf5(bytes)) {throw new Error('The URL did not return valid HDF5 content.');}if (h5) h5.close();try {9 unmodified linesdemos = keys('data').filter(name => /^demo_\d+$/.test(name)).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.': `Unable to load dataset: ${err.message}`;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.');} catch (err) {status(`Unable to initialize HDF5 reader: ${err.message}`, true);}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970711 unmodified line7374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321332 unmodified lines1361371381391401413 unmodified lines1451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831 unmodified line1851861871881891901911921936 unmodified lines2002012022032042052062072082091 unmodified line2112122132142152162172182193 unmodified lines22322422522622722822923023123223323423523623723814 unmodified lines2532542552562572582599 unmodified lines2692702712722732744 unmodified lines27928028128228328428528628710 unmodified lines29829930030130230330430530630730830931031131210 unmodified lines32332432532632732832933033133233333433533633733833934028 unmodified lines3693703713723733743 unmodified lines3783793803813823833843853862 unmodified lines3893903913923933943953963975 unmodified lines40340440540640740840922 unmodified lines4324334344354364374384394404414424434444454461 unmodified line4484494504514524535 unmodified lines4594604614624634644656 unmodified lines4724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945959 unmodified lines6056066076086096106119 unmodified lines6216226236246256266276286296302 unmodified lines63363463563663763863964064136 unmodified lines678679680681682683684685686687688689690691692<!doctype html><html lang="en"><head><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:#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 loading --><section class="card"><h2>1. Load dataset from Hugging Face</h2><div class="row"><div class="grow"><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></div><p class="note">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…</p></section><!-- Demonstration selector --><section class="card"><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 observations --><section class="card"><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 navigation --><div class="controls"><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 aria-label="Frame"><button id="next" disabled aria-label="Next frame">→</button><output id="frameLabel">0 / 0</output></div><p class="note">Playback is for browsing only (4 frames/second), not the original recording rate.</p></section><!-- Robot observations --><section class="card"><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;// ----------------------------------------// Status// ----------------------------------------function status(message, error = false) {$('status').textContent = message;1 unmodified line}// ----------------------------------------// Hugging Face URL// ----------------------------------------function normalizeUrl(input) {const url = new URL(input.trim());6 unmodified linesthrow new Error('This must be a Hugging Face dataset file link.');}url.pathname = url.pathname.replace('/blob/', '/resolve/');if (!url.pathname.includes('/resolve/')) {throw new Error('Copy a link to a specific HDF5 file, not the dataset homepage.');}url.hash = '';1 unmodified line}// ----------------------------------------// HDF5 Validation// ----------------------------------------function validHdf5(bytes) {const magic = [137, 72, 68, 70, 13, 10, 26, 10];3 unmodified linesoffset + 8 <= bytes.length && offset <= 65536;offset = offset === 0 ? 512 : offset * 2) {if (magic.every((v, i) => bytes[offset + i] === v)) return true;}return false;}// ----------------------------------------// HDF5 Utilities// ----------------------------------------function keys(path) {try {14 unmodified linesfunction getFrame(path, t) {const ds = getDataset(path);if (!ds || !ds.shape.length || t >= ds.shape[0]) return null;return {values: ds.slice([9 unmodified linesif (!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}// ----------------------------------------// Dropdowns// ----------------------------------------function selectOptions(id, options) {const element = $(id);10 unmodified lines}// ----------------------------------------// 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 shape: [${result.shape.join(', ')}]`);}const raw = result.values;if (raw.length !== width * height * channels) {throw new Error('Invalid image data shape');}let scale = 1, shift = 0;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 linesdrawImage('image2', 'empty2', 'name2', $('cam2').value, t);const fields = [...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 linegetDataset(`${obsPath}/${firstObs}`)?.shape[0] ?? 0;lastFrame = Math.max(0, count - 1);$('frame').max = lastFrame;$('frame').value = 0;5 unmodified linesselectOptions('cam1', cameras);selectOptions('cam2', ['', ...cameras]);if (cameras.length > 1) $('cam2').value = cameras[1];for (const id of ['frame', 'prev', 'next', 'play']) {$(id).disabled = count < 2;6 unmodified lines}// ----------------------------------------// 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 lengthbar.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 streamupdateProgress(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…');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 linesdemos = keys('data').filter(name => /^demo_\d+$/.test(name)).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 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 dataset link and click Load dataset.');} catch (err) {status(`Unable to initialize HDF5 reader: ${err.message}`, true);}
index.html+232-311