Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse files- bun.lock +5 -0
- package.json +1 -0
- src/app/[org]/[dataset]/[episode]/fetch-data.ts +97 -173
bun.lock
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
"name": "lerobot-viewer",
|
| 7 |
"dependencies": {
|
| 8 |
"@huggingface/hub": "^2.11.0",
|
|
|
|
| 9 |
"@react-three/drei": "^10.7.7",
|
| 10 |
"@react-three/fiber": "^9.5.0",
|
| 11 |
"hyparquet": "^1.12.1",
|
|
@@ -66,6 +67,8 @@
|
|
| 66 |
|
| 67 |
"@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=="],
|
| 68 |
|
|
|
|
|
|
|
| 69 |
"@huggingface/tasks": ["@huggingface/tasks@0.19.90", "", {}, "sha512-nfV9luJbvwGQ/5oKXkKhCV9h4X7mwh1YaGG3ORd6UMLDSwr1OFSSatcBX0O9OtBtmNK19aGSjbLFqqgcIR6+IA=="],
|
| 70 |
|
| 71 |
"@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="],
|
|
@@ -996,6 +999,8 @@
|
|
| 996 |
|
| 997 |
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
|
| 998 |
|
|
|
|
|
|
|
| 999 |
"@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=="],
|
| 1000 |
|
| 1001 |
"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
|
|
|
|
| 6 |
"name": "lerobot-viewer",
|
| 7 |
"dependencies": {
|
| 8 |
"@huggingface/hub": "^2.11.0",
|
| 9 |
+
"@huggingface/lerobot": "^0.0.3",
|
| 10 |
"@react-three/drei": "^10.7.7",
|
| 11 |
"@react-three/fiber": "^9.5.0",
|
| 12 |
"hyparquet": "^1.12.1",
|
|
|
|
| 67 |
|
| 68 |
"@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=="],
|
| 69 |
|
| 70 |
+
"@huggingface/lerobot": ["@huggingface/lerobot@0.0.3", "", { "dependencies": { "hyparquet": "^1.25.1" } }, "sha512-/N9JKXAuIz7Gc8DcWfU1+AyYJZshoZpOBDXs8qGHi2oSP4xxV3/xrW0EvLA5nwXlY3NyxqB3HDS0B6fj+yJ3Jw=="],
|
| 71 |
+
|
| 72 |
"@huggingface/tasks": ["@huggingface/tasks@0.19.90", "", {}, "sha512-nfV9luJbvwGQ/5oKXkKhCV9h4X7mwh1YaGG3ORd6UMLDSwr1OFSSatcBX0O9OtBtmNK19aGSjbLFqqgcIR6+IA=="],
|
| 73 |
|
| 74 |
"@humanfs/core": ["@humanfs/core@0.19.1", "", {}, "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA=="],
|
|
|
|
| 999 |
|
| 1000 |
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
|
| 1001 |
|
| 1002 |
+
"@huggingface/lerobot/hyparquet": ["hyparquet@1.31.1", "", {}, "sha512-tF9580Xb+41+Eb+mH0av1k7m1PWl+PSKrX66Yd7UOZ760cwEXP9/enwHRMSCeVncaubRI8XPb3v580/ujYKK5w=="],
|
| 1003 |
+
|
| 1004 |
"@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=="],
|
| 1005 |
|
| 1006 |
"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/runtime@1.8.1", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
|
package.json
CHANGED
|
@@ -16,6 +16,7 @@
|
|
| 16 |
},
|
| 17 |
"dependencies": {
|
| 18 |
"@huggingface/hub": "^2.11.0",
|
|
|
|
| 19 |
"@react-three/drei": "^10.7.7",
|
| 20 |
"@react-three/fiber": "^9.5.0",
|
| 21 |
"hyparquet": "^1.12.1",
|
|
|
|
| 16 |
},
|
| 17 |
"dependencies": {
|
| 18 |
"@huggingface/hub": "^2.11.0",
|
| 19 |
+
"@huggingface/lerobot": "^0.0.3",
|
| 20 |
"@react-three/drei": "^10.7.7",
|
| 21 |
"@react-three/fiber": "^9.5.0",
|
| 22 |
"hyparquet": "^1.12.1",
|
src/app/[org]/[dataset]/[episode]/fetch-data.ts
CHANGED
|
@@ -15,11 +15,7 @@ import {
|
|
| 15 |
processChartDataGroups,
|
| 16 |
groupRowBySuffix,
|
| 17 |
} from "@/utils/dataProcessing";
|
| 18 |
-
import {
|
| 19 |
-
buildV3VideoPath,
|
| 20 |
-
buildV3DataPath,
|
| 21 |
-
buildV3EpisodesMetadataPath,
|
| 22 |
-
} from "@/utils/stringFormatting";
|
| 23 |
import { bigIntToNumber } from "@/utils/typeGuards";
|
| 24 |
import {
|
| 25 |
isGrayscaleShape,
|
|
@@ -27,9 +23,86 @@ import {
|
|
| 27 |
depthEncodingFromFeature,
|
| 28 |
} from "@/utils/colormaps";
|
| 29 |
import type { VideoInfo, AdjacentEpisodeVideos } from "@/types";
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
const SERIES_NAME_DELIMITER = CHART_CONFIG.SERIES_NAME_DELIMITER;
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
export type CameraInfo = { name: string; width: number; height: number };
|
| 34 |
|
| 35 |
export type DatasetDisplayInfo = {
|
|
@@ -424,45 +497,10 @@ export async function getAdjacentEpisodesVideoInfo(
|
|
| 424 |
const episodeId = currentEpisodeId + offset;
|
| 425 |
if (episodeId >= 0 && episodeId < totalEpisodes) {
|
| 426 |
try {
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
repoId,
|
| 432 |
-
version,
|
| 433 |
-
episodeId,
|
| 434 |
-
);
|
| 435 |
-
videosInfo = extractVideoInfoV3WithSegmentation(
|
| 436 |
-
repoId,
|
| 437 |
-
version,
|
| 438 |
-
info,
|
| 439 |
-
episodeMetadata,
|
| 440 |
-
);
|
| 441 |
-
} else {
|
| 442 |
-
// For v2.x, use simpler video info extraction
|
| 443 |
-
if (info.video_path) {
|
| 444 |
-
const chunkSize = Math.max(1, info.chunks_size || 1000);
|
| 445 |
-
const episode_chunk = Math.floor(episodeId / chunkSize);
|
| 446 |
-
videosInfo = Object.entries(info.features)
|
| 447 |
-
.filter(([, value]) => value.dtype === "video")
|
| 448 |
-
.map(([key, value]) => {
|
| 449 |
-
const videoPath = formatStringWithVars(info.video_path!, {
|
| 450 |
-
video_key: key,
|
| 451 |
-
episode_chunk: episode_chunk
|
| 452 |
-
.toString()
|
| 453 |
-
.padStart(PADDING.CHUNK_INDEX, "0"),
|
| 454 |
-
episode_index: episodeId
|
| 455 |
-
.toString()
|
| 456 |
-
.padStart(PADDING.EPISODE_INDEX, "0"),
|
| 457 |
-
});
|
| 458 |
-
return {
|
| 459 |
-
filename: key,
|
| 460 |
-
url: buildVersionedUrl(repoId, version, videoPath),
|
| 461 |
-
isGrayscale: isGrayscaleShape(value.shape),
|
| 462 |
-
};
|
| 463 |
-
});
|
| 464 |
-
}
|
| 465 |
-
}
|
| 466 |
|
| 467 |
adjacentVideos.push({ episodeId, videosInfo });
|
| 468 |
} catch {
|
|
@@ -515,24 +553,7 @@ async function getEpisodeDataV2(
|
|
| 515 |
// Videos information
|
| 516 |
const videosInfo =
|
| 517 |
info.video_path !== null
|
| 518 |
-
?
|
| 519 |
-
.filter(([, value]) => value.dtype === "video")
|
| 520 |
-
.map(([key, value]) => {
|
| 521 |
-
const videoPath = formatStringWithVars(info.video_path!, {
|
| 522 |
-
video_key: key,
|
| 523 |
-
episode_chunk: episode_chunk
|
| 524 |
-
.toString()
|
| 525 |
-
.padStart(PADDING.CHUNK_INDEX, "0"),
|
| 526 |
-
episode_index: episodeId
|
| 527 |
-
.toString()
|
| 528 |
-
.padStart(PADDING.EPISODE_INDEX, "0"),
|
| 529 |
-
});
|
| 530 |
-
return {
|
| 531 |
-
filename: key,
|
| 532 |
-
url: buildVersionedUrl(repoId, version, videoPath),
|
| 533 |
-
isGrayscale: isGrayscaleShape(value.shape),
|
| 534 |
-
};
|
| 535 |
-
})
|
| 536 |
: [];
|
| 537 |
|
| 538 |
// Column data
|
|
@@ -760,20 +781,9 @@ async function getEpisodeDataV3(
|
|
| 760 |
|
| 761 |
const episodes = Array.from({ length: info.total_episodes }, (_, i) => i);
|
| 762 |
|
| 763 |
-
|
| 764 |
-
const episodeMetadata =
|
| 765 |
-
|
| 766 |
-
version,
|
| 767 |
-
episodeId,
|
| 768 |
-
);
|
| 769 |
-
|
| 770 |
-
// Create video info with segmentation using the metadata
|
| 771 |
-
const videosInfo = extractVideoInfoV3WithSegmentation(
|
| 772 |
-
repoId,
|
| 773 |
-
version,
|
| 774 |
-
info,
|
| 775 |
-
episodeMetadata,
|
| 776 |
-
);
|
| 777 |
|
| 778 |
// Load episode data for charts
|
| 779 |
const {
|
|
@@ -783,7 +793,13 @@ async function getEpisodeDataV3(
|
|
| 783 |
task,
|
| 784 |
languageAtoms,
|
| 785 |
frameTimestamps,
|
| 786 |
-
} = await loadEpisodeDataV3(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
|
| 788 |
const duration = episodeMetadata.length
|
| 789 |
? episodeMetadata.length / info.fps
|
|
@@ -810,6 +826,7 @@ async function loadEpisodeDataV3(
|
|
| 810 |
version: string,
|
| 811 |
info: DatasetMetadata,
|
| 812 |
episodeMetadata: EpisodeMetadataV3,
|
|
|
|
| 813 |
): Promise<{
|
| 814 |
chartDataGroups: ChartRow[][];
|
| 815 |
flatChartData: Record<string, number>[];
|
|
@@ -818,13 +835,7 @@ async function loadEpisodeDataV3(
|
|
| 818 |
languageAtoms?: import("@/types/language.types").LanguageAtom[];
|
| 819 |
frameTimestamps?: number[];
|
| 820 |
}> {
|
| 821 |
-
// Build data file path using chunk and file indices
|
| 822 |
-
const dataChunkIndex = bigIntToNumber(episodeMetadata.data_chunk_index, 0);
|
| 823 |
-
const dataFileIndex = bigIntToNumber(episodeMetadata.data_file_index, 0);
|
| 824 |
-
const dataPath = buildV3DataPath(dataChunkIndex, dataFileIndex);
|
| 825 |
-
|
| 826 |
try {
|
| 827 |
-
const dataUrl = buildVersionedUrl(repoId, version, dataPath);
|
| 828 |
const parquetFile = await fetchParquetFile(dataUrl);
|
| 829 |
const v3DataColumns = Array.from(
|
| 830 |
new Set([
|
|
@@ -1300,75 +1311,6 @@ function processEpisodeDataForCharts(
|
|
| 1300 |
return { chartDataGroups, flatChartData: chartData, ignoredColumns };
|
| 1301 |
}
|
| 1302 |
|
| 1303 |
-
// Video info extraction with segmentation for v3.0
|
| 1304 |
-
function extractVideoInfoV3WithSegmentation(
|
| 1305 |
-
repoId: string,
|
| 1306 |
-
version: string,
|
| 1307 |
-
info: DatasetMetadata,
|
| 1308 |
-
episodeMetadata: EpisodeMetadataV3,
|
| 1309 |
-
): VideoInfo[] {
|
| 1310 |
-
// Get video features from dataset info
|
| 1311 |
-
const videoFeatures = Object.entries(info.features).filter(
|
| 1312 |
-
([, value]) => value.dtype === "video",
|
| 1313 |
-
);
|
| 1314 |
-
|
| 1315 |
-
const videosInfo = videoFeatures.map(([videoKey, videoFeature]) => {
|
| 1316 |
-
// Check if we have per-camera metadata in the episode row
|
| 1317 |
-
const cameraSpecificKeys = Object.keys(episodeMetadata).filter((key) =>
|
| 1318 |
-
key.startsWith(`videos/${videoKey}/`),
|
| 1319 |
-
);
|
| 1320 |
-
|
| 1321 |
-
let chunkIndex: number,
|
| 1322 |
-
fileIndex: number,
|
| 1323 |
-
segmentStart: number,
|
| 1324 |
-
segmentEnd: number;
|
| 1325 |
-
|
| 1326 |
-
const toNum = (v: string | number | string[] | undefined): number => {
|
| 1327 |
-
if (typeof v === "string") return parseFloat(v) || 0;
|
| 1328 |
-
if (typeof v === "number") return v;
|
| 1329 |
-
return 0;
|
| 1330 |
-
};
|
| 1331 |
-
|
| 1332 |
-
if (cameraSpecificKeys.length > 0) {
|
| 1333 |
-
chunkIndex = toNum(episodeMetadata[`videos/${videoKey}/chunk_index`]);
|
| 1334 |
-
fileIndex = toNum(episodeMetadata[`videos/${videoKey}/file_index`]);
|
| 1335 |
-
segmentStart =
|
| 1336 |
-
toNum(episodeMetadata[`videos/${videoKey}/from_timestamp`]) || 0;
|
| 1337 |
-
segmentEnd =
|
| 1338 |
-
toNum(episodeMetadata[`videos/${videoKey}/to_timestamp`]) || 30;
|
| 1339 |
-
} else {
|
| 1340 |
-
chunkIndex = episodeMetadata.video_chunk_index || 0;
|
| 1341 |
-
fileIndex = episodeMetadata.video_file_index || 0;
|
| 1342 |
-
segmentStart = episodeMetadata.video_from_timestamp || 0;
|
| 1343 |
-
segmentEnd = episodeMetadata.video_to_timestamp || 30;
|
| 1344 |
-
}
|
| 1345 |
-
|
| 1346 |
-
// Convert BigInt to number for timestamps
|
| 1347 |
-
const startNum = bigIntToNumber(segmentStart);
|
| 1348 |
-
const endNum = bigIntToNumber(segmentEnd);
|
| 1349 |
-
|
| 1350 |
-
const videoPath = buildV3VideoPath(
|
| 1351 |
-
videoKey,
|
| 1352 |
-
bigIntToNumber(chunkIndex, 0),
|
| 1353 |
-
bigIntToNumber(fileIndex, 0),
|
| 1354 |
-
);
|
| 1355 |
-
const fullUrl = buildVersionedUrl(repoId, version, videoPath);
|
| 1356 |
-
|
| 1357 |
-
return {
|
| 1358 |
-
filename: videoKey,
|
| 1359 |
-
url: fullUrl,
|
| 1360 |
-
// Enable segmentation with timestamps from metadata
|
| 1361 |
-
isSegmented: true,
|
| 1362 |
-
segmentStart: startNum,
|
| 1363 |
-
segmentEnd: endNum,
|
| 1364 |
-
segmentDuration: endNum - startNum,
|
| 1365 |
-
isGrayscale: isGrayscaleShape(videoFeature.shape),
|
| 1366 |
-
};
|
| 1367 |
-
});
|
| 1368 |
-
|
| 1369 |
-
return videosInfo;
|
| 1370 |
-
}
|
| 1371 |
-
|
| 1372 |
// Walks v3.0 episode-metadata parquet files across chunks/files. A new chunk
|
| 1373 |
// begins when the current chunk's files run out (404 or empty); iteration ends
|
| 1374 |
// when file-000 of the next chunk 404s. `chunks_size` caps files per chunk, so
|
|
@@ -1407,21 +1349,6 @@ async function* iterateEpisodeMetadataFilesV3(
|
|
| 1407 |
}
|
| 1408 |
|
| 1409 |
// Metadata loading for v3.0 episodes
|
| 1410 |
-
async function loadEpisodeMetadataV3Simple(
|
| 1411 |
-
repoId: string,
|
| 1412 |
-
version: string,
|
| 1413 |
-
episodeId: number,
|
| 1414 |
-
): Promise<EpisodeMetadataV3> {
|
| 1415 |
-
for await (const rows of iterateEpisodeMetadataFilesV3(repoId, version)) {
|
| 1416 |
-
for (const row of rows) {
|
| 1417 |
-
if (parseEpisodeRowSimple(row).episode_index === episodeId) {
|
| 1418 |
-
return parseEpisodeRowSimple(row);
|
| 1419 |
-
}
|
| 1420 |
-
}
|
| 1421 |
-
}
|
| 1422 |
-
throw new Error(`Episode ${episodeId} not found in metadata`);
|
| 1423 |
-
}
|
| 1424 |
-
|
| 1425 |
// Simple parser for episode row - focuses on key fields for episodes
|
| 1426 |
function parseEpisodeRowSimple(
|
| 1427 |
row: Record<string, unknown>,
|
|
@@ -2541,16 +2468,13 @@ export async function loadEpisodeFlatChartData(
|
|
| 2541 |
info: DatasetMetadata,
|
| 2542 |
episodeId: number,
|
| 2543 |
): Promise<Record<string, number>[]> {
|
| 2544 |
-
const
|
| 2545 |
-
repoId,
|
| 2546 |
-
version,
|
| 2547 |
-
episodeId,
|
| 2548 |
-
);
|
| 2549 |
const { flatChartData } = await loadEpisodeDataV3(
|
| 2550 |
repoId,
|
| 2551 |
version,
|
| 2552 |
info,
|
| 2553 |
-
|
|
|
|
| 2554 |
);
|
| 2555 |
return flatChartData;
|
| 2556 |
}
|
|
|
|
| 15 |
processChartDataGroups,
|
| 16 |
groupRowBySuffix,
|
| 17 |
} from "@/utils/dataProcessing";
|
| 18 |
+
import { buildV3EpisodesMetadataPath } from "@/utils/stringFormatting";
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
import { bigIntToNumber } from "@/utils/typeGuards";
|
| 20 |
import {
|
| 21 |
isGrayscaleShape,
|
|
|
|
| 23 |
depthEncodingFromFeature,
|
| 24 |
} from "@/utils/colormaps";
|
| 25 |
import type { VideoInfo, AdjacentEpisodeVideos } from "@/types";
|
| 26 |
+
import { LeRobotDataset } from "@huggingface/lerobot";
|
| 27 |
+
import type { LeRobotEpisode } from "@huggingface/lerobot";
|
| 28 |
+
import { authHeaders } from "@/utils/auth";
|
| 29 |
|
| 30 |
const SERIES_NAME_DELIMITER = CHART_CONFIG.SERIES_NAME_DELIMITER;
|
| 31 |
|
| 32 |
+
/** `DATASET_URL` points at `<endpoint>/datasets`; the package wants the endpoint. */
|
| 33 |
+
const HUB_ENDPOINT = (
|
| 34 |
+
process.env.DATASET_URL || "https://huggingface.co/datasets"
|
| 35 |
+
).replace(/\/datasets\/?$/, "");
|
| 36 |
+
|
| 37 |
+
function leRobotDataset(repoId: string): LeRobotDataset {
|
| 38 |
+
return new LeRobotDataset(repoId, {
|
| 39 |
+
endpoint: HUB_ENDPOINT,
|
| 40 |
+
additionalFetchHeaders: authHeaders(),
|
| 41 |
+
});
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Locates a single episode: which video files hold it, where inside them, and which parquet rows
|
| 46 |
+
* are its frames. `@huggingface/lerobot` normalizes the v2.x and v3.0 layouts behind one shape, and
|
| 47 |
+
* reads the v3 index by row range instead of scanning every shard for a matching episode_index.
|
| 48 |
+
*/
|
| 49 |
+
async function loadLeRobotEpisode(
|
| 50 |
+
repoId: string,
|
| 51 |
+
episodeId: number,
|
| 52 |
+
): Promise<LeRobotEpisode> {
|
| 53 |
+
const [episode] = await leRobotDataset(repoId).episodes({
|
| 54 |
+
offset: episodeId,
|
| 55 |
+
limit: 1,
|
| 56 |
+
});
|
| 57 |
+
if (!episode) {
|
| 58 |
+
throw new Error(`Episode ${episodeId} not found in ${repoId}`);
|
| 59 |
+
}
|
| 60 |
+
return episode;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
/**
|
| 64 |
+
* v3.0 concatenates episodes into shared files, so each camera carries a time range; v2.x gives every
|
| 65 |
+
* episode its own file and the range simply spans it.
|
| 66 |
+
*/
|
| 67 |
+
function toVideosInfo(
|
| 68 |
+
episode: LeRobotEpisode,
|
| 69 |
+
info: DatasetMetadata,
|
| 70 |
+
segmented: boolean,
|
| 71 |
+
): VideoInfo[] {
|
| 72 |
+
return episode.videos.map((video) => ({
|
| 73 |
+
filename: video.cameraKey,
|
| 74 |
+
url: video.url,
|
| 75 |
+
isGrayscale: isGrayscaleShape(info.features[video.cameraKey]?.shape ?? []),
|
| 76 |
+
...(segmented
|
| 77 |
+
? {
|
| 78 |
+
isSegmented: true,
|
| 79 |
+
segmentStart: video.fromSec,
|
| 80 |
+
segmentEnd: video.toSec,
|
| 81 |
+
segmentDuration: video.toSec - video.fromSec,
|
| 82 |
+
}
|
| 83 |
+
: {}),
|
| 84 |
+
}));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/** Adapts the package's episode onto the shape the chart loader already consumes. */
|
| 88 |
+
function toEpisodeMetadataV3(episode: LeRobotEpisode): EpisodeMetadataV3 {
|
| 89 |
+
const primary = episode.videos[0];
|
| 90 |
+
return {
|
| 91 |
+
episode_index: episode.index,
|
| 92 |
+
data_chunk_index: 0,
|
| 93 |
+
data_file_index: 0,
|
| 94 |
+
dataset_from_index: episode.data.fromRow,
|
| 95 |
+
dataset_to_index: episode.data.toRow,
|
| 96 |
+
/// Unused downstream: the package resolves the video URL itself.
|
| 97 |
+
video_chunk_index: 0,
|
| 98 |
+
video_file_index: 0,
|
| 99 |
+
video_from_timestamp: primary?.fromSec ?? 0,
|
| 100 |
+
video_to_timestamp: primary?.toSec ?? episode.durationSec,
|
| 101 |
+
length: episode.length,
|
| 102 |
+
tasks: episode.tasks,
|
| 103 |
+
};
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
export type CameraInfo = { name: string; width: number; height: number };
|
| 107 |
|
| 108 |
export type DatasetDisplayInfo = {
|
|
|
|
| 497 |
const episodeId = currentEpisodeId + offset;
|
| 498 |
if (episodeId >= 0 && episodeId < totalEpisodes) {
|
| 499 |
try {
|
| 500 |
+
const episode = await loadLeRobotEpisode(repoId, episodeId);
|
| 501 |
+
const videosInfo = info.video_path
|
| 502 |
+
? toVideosInfo(episode, info, version === "v3.0")
|
| 503 |
+
: [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
|
| 505 |
adjacentVideos.push({ episodeId, videosInfo });
|
| 506 |
} catch {
|
|
|
|
| 553 |
// Videos information
|
| 554 |
const videosInfo =
|
| 555 |
info.video_path !== null
|
| 556 |
+
? toVideosInfo(await loadLeRobotEpisode(repoId, episodeId), info, false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
: [];
|
| 558 |
|
| 559 |
// Column data
|
|
|
|
| 781 |
|
| 782 |
const episodes = Array.from({ length: info.total_episodes }, (_, i) => i);
|
| 783 |
|
| 784 |
+
const leRobotEpisode = await loadLeRobotEpisode(repoId, episodeId);
|
| 785 |
+
const episodeMetadata = toEpisodeMetadataV3(leRobotEpisode);
|
| 786 |
+
const videosInfo = toVideosInfo(leRobotEpisode, info, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 787 |
|
| 788 |
// Load episode data for charts
|
| 789 |
const {
|
|
|
|
| 793 |
task,
|
| 794 |
languageAtoms,
|
| 795 |
frameTimestamps,
|
| 796 |
+
} = await loadEpisodeDataV3(
|
| 797 |
+
repoId,
|
| 798 |
+
version,
|
| 799 |
+
info,
|
| 800 |
+
episodeMetadata,
|
| 801 |
+
leRobotEpisode.data.url,
|
| 802 |
+
);
|
| 803 |
|
| 804 |
const duration = episodeMetadata.length
|
| 805 |
? episodeMetadata.length / info.fps
|
|
|
|
| 826 |
version: string,
|
| 827 |
info: DatasetMetadata,
|
| 828 |
episodeMetadata: EpisodeMetadataV3,
|
| 829 |
+
dataUrl: string,
|
| 830 |
): Promise<{
|
| 831 |
chartDataGroups: ChartRow[][];
|
| 832 |
flatChartData: Record<string, number>[];
|
|
|
|
| 835 |
languageAtoms?: import("@/types/language.types").LanguageAtom[];
|
| 836 |
frameTimestamps?: number[];
|
| 837 |
}> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
try {
|
|
|
|
| 839 |
const parquetFile = await fetchParquetFile(dataUrl);
|
| 840 |
const v3DataColumns = Array.from(
|
| 841 |
new Set([
|
|
|
|
| 1311 |
return { chartDataGroups, flatChartData: chartData, ignoredColumns };
|
| 1312 |
}
|
| 1313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1314 |
// Walks v3.0 episode-metadata parquet files across chunks/files. A new chunk
|
| 1315 |
// begins when the current chunk's files run out (404 or empty); iteration ends
|
| 1316 |
// when file-000 of the next chunk 404s. `chunks_size` caps files per chunk, so
|
|
|
|
| 1349 |
}
|
| 1350 |
|
| 1351 |
// Metadata loading for v3.0 episodes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1352 |
// Simple parser for episode row - focuses on key fields for episodes
|
| 1353 |
function parseEpisodeRowSimple(
|
| 1354 |
row: Record<string, unknown>,
|
|
|
|
| 2468 |
info: DatasetMetadata,
|
| 2469 |
episodeId: number,
|
| 2470 |
): Promise<Record<string, number>[]> {
|
| 2471 |
+
const episode = await loadLeRobotEpisode(repoId, episodeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2472 |
const { flatChartData } = await loadEpisodeDataV3(
|
| 2473 |
repoId,
|
| 2474 |
version,
|
| 2475 |
info,
|
| 2476 |
+
toEpisodeMetadataV3(episode),
|
| 2477 |
+
episode.data.url,
|
| 2478 |
);
|
| 2479 |
return flatChartData;
|
| 2480 |
}
|