Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse filesFiles changed (2)
263 unmodified lines26426526626726826923 unmodified lines2932942952962972982993003013029 unmodified lines312313314315316317263 unmodified lines}) {const [data, setData] = useState<EpisodeData | null>(null);const [error, setError] = useState<string | null>(null);const requestIdRef = useRef(0);// Opening straight onto 3D Replay: start the robot meshes downloading now,23 unmodified lines}const requestId = ++requestIdRef.current;setError(null);setData(null);getEpisodeDataSafe(org, dataset, episodeId).then(({ data: loaded, error: loadError }) => {if (requestIdRef.current !== requestId) return;if (loadError) {setError(loadError);setData(null);9 unmodified lines});}, [org, dataset, episodeId]);if (error) {return (<div className="flex h-screen items-center justify-center bg-[var(--bg)] text-red-600 dark:text-red-300">263 unmodified lines26426526626726826927023 unmodified lines2942952962972982993003013023033043053063073089 unmodified lines318319320321322323324325326327328329330331332333334335336337338339340341342343344345263 unmodified lines}) {const [data, setData] = useState<EpisodeData | null>(null);const [error, setError] = useState<string | null>(null);const [noEpisodes, setNoEpisodes] = useState(false);const requestIdRef = useRef(0);// Opening straight onto 3D Replay: start the robot meshes downloading now,23 unmodified lines}const requestId = ++requestIdRef.current;setError(null);setNoEpisodes(false);setData(null);getEpisodeDataSafe(org, dataset, episodeId).then(({ data: loaded, error: loadError, noEpisodes: empty }) => {if (requestIdRef.current !== requestId) return;if (empty) {setNoEpisodes(true);return;}if (loadError) {setError(loadError);setData(null);9 unmodified lines});}, [org, dataset, episodeId]);if (noEpisodes) {return (<div className="flex h-screen items-center justify-center bg-[var(--bg)]"><div className="panel-raised max-w-xl p-6"><h2 className="text-xl font-medium text-fg mb-2">No episodes yet</h2><p className="text-sm text-fg-muted"><ahref={`https://huggingface.co/datasets/${org}/${dataset}`}target="_blank"rel="noopener noreferrer"className="font-mono text-fg hover:text-accent-fg transition-colors">{org}/{dataset}</a>{" "}has a <code className="font-mono">meta/info.json</code> but norecorded episodes, so there is nothing to play.</p></div></div>);}if (error) {return (<div className="flex h-screen items-center justify-center bg-[var(--bg)] text-red-600 dark:text-red-300">
399 unmodified lines4004014024034044056 unmodified lines41241341441541641757 unmodified lines4754764774784794804811503 unmodified lines19851986198719881989199019911992199319941995399 unmodified linesreturn new Set(evenlySampleIndices(totalEpisodes, maxEpisodes));}export async function getEpisodeData(org: string,dataset: string,6 unmodified linesconsole.timeEnd(`[perf] getDatasetVersionAndInfo`);const info = rawInfo as unknown as DatasetMetadata;if (info.video_path === null) {throw new Error("Only videos datasets are supported in this visualizer.\nPlease use Rerun visualizer for images datasets.",57 unmodified linesreturn result;} catch (err) {console.error("Error loading episode data:", err);throw err;}}1503 unmodified linesorg: string,dataset: string,episodeId: number,): Promise<{ data?: EpisodeData; error?: string }> {try {const data = await getEpisodeData(org, dataset, episodeId);return { data };} catch (err: unknown) {const message = err instanceof Error ? err.message : String(err);return { error: message || "Unknown error" };}399 unmodified lines4004014024034044054064074086 unmodified lines41541641741841942042142242342457 unmodified lines4824834844854864874884894901503 unmodified lines19941995199619971998199920002001200220032004200520062007399 unmodified linesreturn new Set(evenlySampleIndices(totalEpisodes, maxEpisodes));}/** `meta/info.json` lists no episodes: the recording was pushed before any episode was saved. */export class NoEpisodesError extends Error {}export async function getEpisodeData(org: string,dataset: string,6 unmodified linesconsole.timeEnd(`[perf] getDatasetVersionAndInfo`);const info = rawInfo as unknown as DatasetMetadata;if (info.total_episodes === 0) {throw new NoEpisodesError(`${repoId} has no episodes`);}if (info.video_path === null) {throw new Error("Only videos datasets are supported in this visualizer.\nPlease use Rerun visualizer for images datasets.",57 unmodified linesreturn result;} catch (err) {if (!(err instanceof NoEpisodesError)) {console.error("Error loading episode data:", err);}throw err;}}1503 unmodified linesorg: string,dataset: string,episodeId: number,): Promise<{ data?: EpisodeData; error?: string; noEpisodes?: boolean }> {try {const data = await getEpisodeData(org, dataset, episodeId);return { data };} catch (err: unknown) {if (err instanceof NoEpisodesError) {return { noEpisodes: true };}const message = err instanceof Error ? err.message : String(err);return { error: message || "Unknown error" };}
src/app/[org]/[dataset]/[episode]/episode-viewer.tsx+29-1
src/app/[org]/[dataset]/[episode]/fetch-data.ts+14-2