Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse filesFiles changed (3)
5 unmodified lines6789101154 unmodified lines666768697071924 unmodified lines996997998999100010015 unmodified lines"name": "lerobot-viewer","dependencies": {"@huggingface/hub": "^2.11.0","@react-three/drei": "^10.7.7","@react-three/fiber": "^9.5.0","hyparquet": "^1.12.1",54 unmodified lines"@huggingface/hub": ["@huggingface/hub@2.11.0", "", { "dependencies": { "@huggingface/tasks": "^0.19.90" }, "optionalDependencies": { "cli-progress": "^3.12.0" }, "bin": { "hfjs": "dist/cli.js" } }, "sha512-WS6QGaXYeBVFlaB4SOn6z4LGUpLB5kRZNL08uUni4izX353KxiwwZMK5+/AWX86MJh8SMZNa/JFcvFCcQsbszQ=="],"@huggingface/tasks": ["@huggingface/tasks@0.19.90", "", {}, "sha512-nfV9luJbvwGQ/5oKXkKhCV9h4X7mwh1YaGG3ORd6UMLDSwr1OFSSatcBX0O9OtBtmNK19aGSjbLFqqgcIR6+IA=="],"@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="],924 unmodified lines"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" }, "bundled": true }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="],"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],5 unmodified lines678910111254 unmodified lines6768697071727374924 unmodified lines99910001001100210031004100510065 unmodified lines"name": "lerobot-viewer","dependencies": {"@huggingface/hub": "^2.11.0","@huggingface/lerobot": "^0.0.3","@react-three/drei": "^10.7.7","@react-three/fiber": "^9.5.0","hyparquet": "^1.12.1",54 unmodified lines"@huggingface/hub": ["@huggingface/hub@2.11.0", "", { "dependencies": { "@huggingface/tasks": "^0.19.90" }, "optionalDependencies": { "cli-progress": "^3.12.0" }, "bin": { "hfjs": "dist/cli.js" } }, "sha512-WS6QGaXYeBVFlaB4SOn6z4LGUpLB5kRZNL08uUni4izX353KxiwwZMK5+/AWX86MJh8SMZNa/JFcvFCcQsbszQ=="],"@huggingface/lerobot": ["@huggingface/lerobot@0.0.3", "", { "dependencies": { "hyparquet": "^1.25.1" } }, "sha512-/N9JKXAuIz7Gc8DcWfU1+AyYJZshoZpOBDXs8qGHi2oSP4xxV3/xrW0EvLA5nwXlY3NyxqB3HDS0B6fj+yJ3Jw=="],"@huggingface/tasks": ["@huggingface/tasks@0.19.90", "", {}, "sha512-nfV9luJbvwGQ/5oKXkKhCV9h4X7mwh1YaGG3ORd6UMLDSwr1OFSSatcBX0O9OtBtmNK19aGSjbLFqqgcIR6+IA=="],"@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="],924 unmodified lines"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],"@huggingface/lerobot/hyparquet": ["hyparquet@1.31.1", "", {}, "sha512-tF9580Xb+41+Eb+mH0av1k7m1PWl+PSKrX66Yd7UOZ760cwEXP9/enwHRMSCeVncaubRI8XPb3v580/ujYKK5w=="],"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/core@1.8.1", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" }, "bundled": true }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="],"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
15 unmodified lines16171819202115 unmodified lines},"dependencies": {"@huggingface/hub": "^2.11.0","@react-three/drei": "^10.7.7","@react-three/fiber": "^9.5.0","hyparquet": "^1.12.1",15 unmodified lines1617181920212215 unmodified lines},"dependencies": {"@huggingface/hub": "^2.11.0","@huggingface/lerobot": "^0.0.3","@react-three/drei": "^10.7.7","@react-three/fiber": "^9.5.0","hyparquet": "^1.12.1",
14 unmodified lines15161718192021222324251 unmodified line272829303132333435388 unmodified lines42442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846 unmodified lines515516517518519520521522523524525526527528529530531532533534535536537538221 unmodified lines7607617627637647657667677687697707717727737747757767777787793 unmodified lines78378478578678778878920 unmodified lines8108118128138148152 unmodified lines818819820821822823824825826827828829830469 unmodified lines13001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137432 unmodified lines1407140814091410141114121413141414151416141714181419142014211422142314241425142614271113 unmodified lines254125422543254425452546254725482549255025512552255325542555255614 unmodified linesprocessChartDataGroups,groupRowBySuffix,} from "@/utils/dataProcessing";import {buildV3VideoPath,buildV3DataPath,buildV3EpisodesMetadataPath,} from "@/utils/stringFormatting";import { bigIntToNumber } from "@/utils/typeGuards";import {isGrayscaleShape,1 unmodified linedepthEncodingFromFeature,} from "@/utils/colormaps";import type { VideoInfo, AdjacentEpisodeVideos } from "@/types";const SERIES_NAME_DELIMITER = CHART_CONFIG.SERIES_NAME_DELIMITER;export type CameraInfo = { name: string; width: number; height: number };export type DatasetDisplayInfo = {388 unmodified linesconst episodeId = currentEpisodeId + offset;if (episodeId >= 0 && episodeId < totalEpisodes) {try {let videosInfo: VideoInfo[] = [];if (version === "v3.0") {const episodeMetadata = await loadEpisodeMetadataV3Simple(repoId,version,episodeId,);videosInfo = extractVideoInfoV3WithSegmentation(repoId,version,info,episodeMetadata,);} else {// For v2.x, use simpler video info extractionif (info.video_path) {const chunkSize = Math.max(1, info.chunks_size || 1000);const episode_chunk = Math.floor(episodeId / chunkSize);videosInfo = Object.entries(info.features).filter(([, value]) => value.dtype === "video").map(([key, value]) => {const videoPath = formatStringWithVars(info.video_path!, {video_key: key,episode_chunk: episode_chunk.toString().padStart(PADDING.CHUNK_INDEX, "0"),episode_index: episodeId.toString().padStart(PADDING.EPISODE_INDEX, "0"),});return {filename: key,url: buildVersionedUrl(repoId, version, videoPath),isGrayscale: isGrayscaleShape(value.shape),};});}}adjacentVideos.push({ episodeId, videosInfo });} catch {46 unmodified lines// Videos informationconst videosInfo =info.video_path !== null? Object.entries(info.features).filter(([, value]) => value.dtype === "video").map(([key, value]) => {const videoPath = formatStringWithVars(info.video_path!, {video_key: key,episode_chunk: episode_chunk.toString().padStart(PADDING.CHUNK_INDEX, "0"),episode_index: episodeId.toString().padStart(PADDING.EPISODE_INDEX, "0"),});return {filename: key,url: buildVersionedUrl(repoId, version, videoPath),isGrayscale: isGrayscaleShape(value.shape),};}): [];// Column data221 unmodified linesconst episodes = Array.from({ length: info.total_episodes }, (_, i) => i);// Load episode metadata to get timestamps for episode 0const episodeMetadata = await loadEpisodeMetadataV3Simple(repoId,version,episodeId,);// Create video info with segmentation using the metadataconst videosInfo = extractVideoInfoV3WithSegmentation(repoId,version,info,episodeMetadata,);// Load episode data for chartsconst {3 unmodified linestask,languageAtoms,frameTimestamps,} = await loadEpisodeDataV3(repoId, version, info, episodeMetadata);const duration = episodeMetadata.length? episodeMetadata.length / info.fps20 unmodified linesversion: string,info: DatasetMetadata,episodeMetadata: EpisodeMetadataV3,): Promise<{chartDataGroups: ChartRow[][];flatChartData: Record<string, number>[];2 unmodified lineslanguageAtoms?: import("@/types/language.types").LanguageAtom[];frameTimestamps?: number[];}> {// Build data file path using chunk and file indicesconst dataChunkIndex = bigIntToNumber(episodeMetadata.data_chunk_index, 0);const dataFileIndex = bigIntToNumber(episodeMetadata.data_file_index, 0);const dataPath = buildV3DataPath(dataChunkIndex, dataFileIndex);try {const dataUrl = buildVersionedUrl(repoId, version, dataPath);const parquetFile = await fetchParquetFile(dataUrl);const v3DataColumns = Array.from(new Set([469 unmodified linesreturn { chartDataGroups, flatChartData: chartData, ignoredColumns };}// Video info extraction with segmentation for v3.0function extractVideoInfoV3WithSegmentation(repoId: string,version: string,info: DatasetMetadata,episodeMetadata: EpisodeMetadataV3,): VideoInfo[] {// Get video features from dataset infoconst videoFeatures = Object.entries(info.features).filter(([, value]) => value.dtype === "video",);const videosInfo = videoFeatures.map(([videoKey, videoFeature]) => {// Check if we have per-camera metadata in the episode rowconst cameraSpecificKeys = Object.keys(episodeMetadata).filter((key) =>key.startsWith(`videos/${videoKey}/`),);let chunkIndex: number,fileIndex: number,segmentStart: number,segmentEnd: number;const toNum = (v: string | number | string[] | undefined): number => {if (typeof v === "string") return parseFloat(v) || 0;if (typeof v === "number") return v;return 0;};if (cameraSpecificKeys.length > 0) {chunkIndex = toNum(episodeMetadata[`videos/${videoKey}/chunk_index`]);fileIndex = toNum(episodeMetadata[`videos/${videoKey}/file_index`]);segmentStart =toNum(episodeMetadata[`videos/${videoKey}/from_timestamp`]) || 0;segmentEnd =toNum(episodeMetadata[`videos/${videoKey}/to_timestamp`]) || 30;} else {chunkIndex = episodeMetadata.video_chunk_index || 0;fileIndex = episodeMetadata.video_file_index || 0;segmentStart = episodeMetadata.video_from_timestamp || 0;segmentEnd = episodeMetadata.video_to_timestamp || 30;}// Convert BigInt to number for timestampsconst startNum = bigIntToNumber(segmentStart);const endNum = bigIntToNumber(segmentEnd);const videoPath = buildV3VideoPath(videoKey,bigIntToNumber(chunkIndex, 0),bigIntToNumber(fileIndex, 0),);const fullUrl = buildVersionedUrl(repoId, version, videoPath);return {filename: videoKey,url: fullUrl,// Enable segmentation with timestamps from metadataisSegmented: true,segmentStart: startNum,segmentEnd: endNum,segmentDuration: endNum - startNum,isGrayscale: isGrayscaleShape(videoFeature.shape),};});return videosInfo;}// Walks v3.0 episode-metadata parquet files across chunks/files. A new chunk// begins when the current chunk's files run out (404 or empty); iteration ends// when file-000 of the next chunk 404s. `chunks_size` caps files per chunk, so32 unmodified lines}// Metadata loading for v3.0 episodesasync function loadEpisodeMetadataV3Simple(repoId: string,version: string,episodeId: number,): Promise<EpisodeMetadataV3> {for await (const rows of iterateEpisodeMetadataFilesV3(repoId, version)) {for (const row of rows) {if (parseEpisodeRowSimple(row).episode_index === episodeId) {return parseEpisodeRowSimple(row);}}}throw new Error(`Episode ${episodeId} not found in metadata`);}// Simple parser for episode row - focuses on key fields for episodesfunction parseEpisodeRowSimple(row: Record<string, unknown>,1113 unmodified linesinfo: DatasetMetadata,episodeId: number,): Promise<Record<string, number>[]> {const episodeMetadata = await loadEpisodeMetadataV3Simple(repoId,version,episodeId,);const { flatChartData } = await loadEpisodeDataV3(repoId,version,info,episodeMetadata,);return flatChartData;}14 unmodified lines151617181920211 unmodified line2324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108388 unmodified lines49749849950050150250350450550646 unmodified lines553554555556557558559221 unmodified lines7817827837847857867877887893 unmodified lines79379479579679779879980080180280380480520 unmodified lines8268278288298308318322 unmodified lines835836837838839840841469 unmodified lines13111312131313141315131632 unmodified lines1349135013511352135313541113 unmodified lines246824692470247124722473247424752476247724782479248014 unmodified linesprocessChartDataGroups,groupRowBySuffix,} from "@/utils/dataProcessing";import { buildV3EpisodesMetadataPath } from "@/utils/stringFormatting";import { bigIntToNumber } from "@/utils/typeGuards";import {isGrayscaleShape,1 unmodified linedepthEncodingFromFeature,} from "@/utils/colormaps";import type { VideoInfo, AdjacentEpisodeVideos } from "@/types";import { LeRobotDataset } from "@huggingface/lerobot";import type { LeRobotEpisode } from "@huggingface/lerobot";import { authHeaders } from "@/utils/auth";const SERIES_NAME_DELIMITER = CHART_CONFIG.SERIES_NAME_DELIMITER;/** `DATASET_URL` points at `<endpoint>/datasets`; the package wants the endpoint. */const HUB_ENDPOINT = (process.env.DATASET_URL || "https://huggingface.co/datasets").replace(/\/datasets\/?$/, "");function leRobotDataset(repoId: string): LeRobotDataset {return new LeRobotDataset(repoId, {endpoint: HUB_ENDPOINT,additionalFetchHeaders: authHeaders(),});}/*** Locates a single episode: which video files hold it, where inside them, and which parquet rows* are its frames. `@huggingface/lerobot` normalizes the v2.x and v3.0 layouts behind one shape, and* reads the v3 index by row range instead of scanning every shard for a matching episode_index.*/async function loadLeRobotEpisode(repoId: string,episodeId: number,): Promise<LeRobotEpisode> {const [episode] = await leRobotDataset(repoId).episodes({offset: episodeId,limit: 1,});if (!episode) {throw new Error(`Episode ${episodeId} not found in ${repoId}`);}return episode;}/*** v3.0 concatenates episodes into shared files, so each camera carries a time range; v2.x gives every* episode its own file and the range simply spans it.*/function toVideosInfo(episode: LeRobotEpisode,info: DatasetMetadata,segmented: boolean,): VideoInfo[] {return episode.videos.map((video) => ({filename: video.cameraKey,url: video.url,isGrayscale: isGrayscaleShape(info.features[video.cameraKey]?.shape ?? []),...(segmented? {isSegmented: true,segmentStart: video.fromSec,segmentEnd: video.toSec,segmentDuration: video.toSec - video.fromSec,}: {}),}));}/** Adapts the package's episode onto the shape the chart loader already consumes. */function toEpisodeMetadataV3(episode: LeRobotEpisode): EpisodeMetadataV3 {const primary = episode.videos[0];return {episode_index: episode.index,data_chunk_index: 0,data_file_index: 0,dataset_from_index: episode.data.fromRow,dataset_to_index: episode.data.toRow,/// Unused downstream: the package resolves the video URL itself.video_chunk_index: 0,video_file_index: 0,video_from_timestamp: primary?.fromSec ?? 0,video_to_timestamp: primary?.toSec ?? episode.durationSec,length: episode.length,tasks: episode.tasks,};}export type CameraInfo = { name: string; width: number; height: number };export type DatasetDisplayInfo = {388 unmodified linesconst episodeId = currentEpisodeId + offset;if (episodeId >= 0 && episodeId < totalEpisodes) {try {const episode = await loadLeRobotEpisode(repoId, episodeId);const videosInfo = info.video_path? toVideosInfo(episode, info, version === "v3.0"): [];adjacentVideos.push({ episodeId, videosInfo });} catch {46 unmodified lines// Videos informationconst videosInfo =info.video_path !== null? toVideosInfo(await loadLeRobotEpisode(repoId, episodeId), info, false): [];// Column data221 unmodified linesconst episodes = Array.from({ length: info.total_episodes }, (_, i) => i);const leRobotEpisode = await loadLeRobotEpisode(repoId, episodeId);const episodeMetadata = toEpisodeMetadataV3(leRobotEpisode);const videosInfo = toVideosInfo(leRobotEpisode, info, true);// Load episode data for chartsconst {3 unmodified linestask,languageAtoms,frameTimestamps,} = await loadEpisodeDataV3(repoId,version,info,episodeMetadata,leRobotEpisode.data.url,);const duration = episodeMetadata.length? episodeMetadata.length / info.fps20 unmodified linesversion: string,info: DatasetMetadata,episodeMetadata: EpisodeMetadataV3,dataUrl: string,): Promise<{chartDataGroups: ChartRow[][];flatChartData: Record<string, number>[];2 unmodified lineslanguageAtoms?: import("@/types/language.types").LanguageAtom[];frameTimestamps?: number[];}> {try {const parquetFile = await fetchParquetFile(dataUrl);const v3DataColumns = Array.from(new Set([469 unmodified linesreturn { chartDataGroups, flatChartData: chartData, ignoredColumns };}// Walks v3.0 episode-metadata parquet files across chunks/files. A new chunk// begins when the current chunk's files run out (404 or empty); iteration ends// when file-000 of the next chunk 404s. `chunks_size` caps files per chunk, so32 unmodified lines}// Metadata loading for v3.0 episodes// Simple parser for episode row - focuses on key fields for episodesfunction parseEpisodeRowSimple(row: Record<string, unknown>,1113 unmodified linesinfo: DatasetMetadata,episodeId: number,): Promise<Record<string, number>[]> {const episode = await loadLeRobotEpisode(repoId, episodeId);const { flatChartData } = await loadEpisodeDataV3(repoId,version,info,toEpisodeMetadataV3(episode),episode.data.url,);return flatChartData;}
bun.lock+5
package.json+1
src/app/[org]/[dataset]/[episode]/fetch-data.ts+97-173