Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse filesFiles changed (4)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465"use server";
import { getDatasetVersionAndInfo } from "@/utils/versionUtils";import type { DatasetMetadata } from "@/utils/parquetUtils";import { loadAllEpisodeLengthsV3, loadAllEpisodeFrameInfo, loadCrossEpisodeActionVariance, loadEpisodeFlatChartData, type EpisodeLengthStats, type EpisodeFramesData, type CrossEpisodeVarianceData,} from "./fetch-data";
export async function fetchEpisodeLengthStats( org: string, dataset: string,): Promise<EpisodeLengthStats | null> { const repoId = `${org}/${dataset}`; const { version, info } = await getDatasetVersionAndInfo(repoId); if (version !== "v3.0") return null; return loadAllEpisodeLengthsV3(repoId, version, info.fps);}
export async function fetchEpisodeFrames( org: string, dataset: string,): Promise<EpisodeFramesData> { const repoId = `${org}/${dataset}`; const { version, info } = await getDatasetVersionAndInfo(repoId); return loadAllEpisodeFrameInfo( repoId, version, info as unknown as DatasetMetadata, );}
export async function fetchCrossEpisodeVariance( org: string, dataset: string,): Promise<CrossEpisodeVarianceData | null> { const repoId = `${org}/${dataset}`; const { version, info } = await getDatasetVersionAndInfo(repoId); return loadCrossEpisodeActionVariance( repoId, version, info as unknown as DatasetMetadata, info.fps, );}
export async function fetchEpisodeChartData( org: string, dataset: string, episodeId: number,): Promise<Record<string, number>[]> { const repoId = `${org}/${dataset}`; const { version, info } = await getDatasetVersionAndInfo(repoId); return loadEpisodeFlatChartData( repoId, version, info as unknown as DatasetMetadata, episodeId, );}21 unmodified lines22232425262728332 unmodified lines36136236336436536636736836937021 unmodified linesimport {computeColumnMinMax,getEpisodeDataSafe,loadAllEpisodeLengthsV3,loadAllEpisodeFrameInfo,loadCrossEpisodeActionVariance,type EpisodeData,332 unmodified linesif (org && dataset) {const repoId = `${org}/${dataset}`;getDatasetVersionAndInfo(repoId).then(({ version, info }) => {if (version !== "v3.0") return null;return loadAllEpisodeLengthsV3(repoId, version, info.fps);}).then((result) => {if (!mountedRef.current) return;setEpisodeLengthStats(result);21 unmodified lines22232425262728332 unmodified lines36136236336436536636721 unmodified linesimport {computeColumnMinMax,getEpisodeDataSafe,loadAllEpisodeLengths,loadAllEpisodeFrameInfo,loadCrossEpisodeActionVariance,type EpisodeData,332 unmodified linesif (org && dataset) {const repoId = `${org}/${dataset}`;getDatasetVersionAndInfo(repoId).then(({ info }) => loadAllEpisodeLengths(repoId, info.fps)).then((result) => {if (!mountedRef.current) return;setEpisodeLengthStats(result);
130 unmodified lines131132133134135136137326 unmodified lines46446546646746846947047147247347447526 unmodified lines502503504505506507508128 unmodified lines637638639640641642643417 unmodified lines106110621063106410651066106710681069130 unmodified linesrobot_type: string | null;codebase_version: string;total_tasks: number;dataset_size_mb: number;cameras: CameraInfo[];};326 unmodified linesrobot_type: rawInfo.robot_type ?? null,codebase_version: rawInfo.codebase_version,total_tasks: rawInfo.total_tasks ?? 0,dataset_size_mb:Math.round(((rawInfo.data_files_size_in_mb ?? 0) +(rawInfo.video_files_size_in_mb ?? 0)) *10,) / 10,cameras,};26 unmodified linesrobot_type: null,codebase_version: version,total_tasks: 0,dataset_size_mb: 0,cameras: [],};128 unmodified linesrobot_type: null,codebase_version: version,total_tasks: 0,dataset_size_mb: 0,cameras: [],};417 unmodified lines* Load all episode lengths from the episodes metadata parquet files (v3.0).* Returns min/max/mean/median/std and a histogram, or null if unavailable.*/export async function loadAllEpisodeLengthsV3(repoId: string,version: string,fps: number,): Promise<EpisodeLengthStats | null> {try {130 unmodified lines131132133134135136326 unmodified lines46346446546646746826 unmodified lines495496497498499500128 unmodified lines629630631632633634417 unmodified lines105210531054105510561057105810591060130 unmodified linesrobot_type: string | null;codebase_version: string;total_tasks: number;cameras: CameraInfo[];};326 unmodified linesrobot_type: rawInfo.robot_type ?? null,codebase_version: rawInfo.codebase_version,total_tasks: rawInfo.total_tasks ?? 0,cameras,};26 unmodified linesrobot_type: null,codebase_version: version,total_tasks: 0,cameras: [],};128 unmodified linesrobot_type: null,codebase_version: version,total_tasks: 0,cameras: [],};417 unmodified lines* Load all episode lengths from the episodes metadata parquet files (v3.0).* Returns min/max/mean/median/std and a histogram, or null if unavailable.*//** Works for every version: the package reads v2's episodes.jsonl and v3's episode index alike. */export async function loadAllEpisodeLengths(repoId: string,fps: number,): Promise<EpisodeLengthStats | null> {try {
12 unmodified lines131415161718192021222338 unmodified lines62636465666768142 unmodified lines21121221321421521621721821922022122222322422512 unmodified lines}function formatTotalTime(totalFrames: number, fps: number): string {const totalSec = totalFrames / fps;const hours = Math.floor(totalSec / 3600);const minutes = Math.floor((totalSec % 3600) / 60);if (hours > 0) return `${hours}h ${minutes}m`;return `${minutes}m`;}/** SVG bar chart for the episode-length histogram */38 unmodified linesy={y}width={barWidth}height={barH}className="fill-orange-500/80 hover:fill-orange-400 transition-colors"rx={Math.min(2, barWidth / 4)}/>{bin.count > 0 && barWidth >= 8 && (142 unmodified lines<div className="grid grid-cols-3 md:grid-cols-5 gap-4 mb-4"><Cardlabel="Shortest"value={`${els.shortestEpisodes[0]?.lengthSeconds ?? "–"}s`}/><Cardlabel="Longest"value={`${els.longestEpisodes[els.longestEpisodes.length - 1]?.lengthSeconds ?? "–"}s`}/><Card label="Mean" value={`${els.meanEpisodeLength}s`} /><Card label="Median" value={`${els.medianEpisodeLength}s`} /><Card label="Std Dev" value={`${els.stdEpisodeLength}s`} /></div></div>12 unmodified lines131415161718192021222324252627282938 unmodified lines68697071727374142 unmodified lines21721821922022122222322422522622722822923023123223323423523623723812 unmodified lines}function formatTotalTime(totalFrames: number, fps: number): string {const totalSec = Math.round(totalFrames / fps);const hours = Math.floor(totalSec / 3600);const minutes = Math.floor((totalSec % 3600) / 60);const seconds = totalSec % 60;if (hours > 0) return `${hours}h ${minutes}m`;if (minutes > 0) return `${minutes}m ${seconds}s`;return `${seconds}s`;}function formatSeconds(value: number | undefined): string {return value === undefined ? "–" : `${value.toFixed(2)}s`;}/** SVG bar chart for the episode-length histogram */38 unmodified linesy={y}width={barWidth}height={barH}className="fill-cyan-400/70 hover:fill-cyan-300 transition-colors"rx={Math.min(2, barWidth / 4)}/>{bin.count > 0 && barWidth >= 8 && (142 unmodified lines<div className="grid grid-cols-3 md:grid-cols-5 gap-4 mb-4"><Cardlabel="Shortest"value={formatSeconds(els.shortestEpisodes[0]?.lengthSeconds)}/>{/* longestEpisodes is sorted longest first. */}<Cardlabel="Longest"value={formatSeconds(els.longestEpisodes[0]?.lengthSeconds)}/><Card label="Mean" value={formatSeconds(els.meanEpisodeLength)} /><Cardlabel="Median"value={formatSeconds(els.medianEpisodeLength)}/><Cardlabel="Std Dev"value={formatSeconds(els.stdEpisodeLength)}/></div></div>
src/app/[org]/[dataset]/[episode]/actions.tsDeleted-65
src/app/[org]/[dataset]/[episode]/episode-viewer.tsx+2-5
src/app/[org]/[dataset]/[episode]/fetch-data.ts+2-11
src/components/stats-panel.tsx+21-8