simverse2026 / example_load.py
simver
Add files using upload-large-folder tool
0a0af24 verified
"""Minimal demo of loading SimVerse from HuggingFace and verifying a record.
Run from inside the dataset directory:
cd hf_dataset
python example_load.py
Or after `huggingface-cli download <org>/simverse --local-dir ./simverse`:
python simverse/example_load.py
This script:
1. Loads each of the 5 task configs via `datasets.load_dataset(...)`.
2. Prints the first record's prompt + answer + media path.
3. Verifies the referenced image/video file is reachable on disk.
"""
from __future__ import annotations
import json
import os
from pathlib import Path
CONFIGS = ("voi", "cube1", "cube2", "lamp", "cutrope")
ROOT = Path(__file__).resolve().parent
def _resolve_media_path(record: dict, config: str) -> tuple[str, list[Path]]:
"""Pick the canonical media field per config and return (label, list of paths)."""
if config == "voi":
rel = record.get("images_relative_to_config", {}) or {}
target = rel.get("target")
shapes = list((rel.get("shapes") or {}).values())
return ("target image + shape images", [
ROOT / config / target if target else None,
*(ROOT / config / s for s in shapes if s),
])
if config == "cube1":
ip = record.get("image_paths", {}) or {}
return ("blank net + path sequence", [
ROOT / config / ip.get("blank_net_image", ""),
ROOT / config / ip.get("path_sequence_image", ""),
])
if config == "cube2":
rel = record.get("images_relative_to_config", {}) or {}
return ("initial net + target top face", [
ROOT / config / rel.get("initialNetImage", ""),
ROOT / config / rel.get("targetTopFaceImage", ""),
])
if config == "lamp":
rel = record.get("images_relative_to_config", {}) or {}
return ("workspace image", [
ROOT / config / rel.get("image", ""),
])
if config == "cutrope":
rel = record.get("video_relative_to_config", {}) or {}
return ("gameplay video", [
ROOT / config / rel.get("path", ""),
])
return ("?", [])
def main() -> None:
for config in CONFIGS:
path = ROOT / config / "test.jsonl"
if not path.exists():
print(f"[{config}] missing {path}")
continue
with path.open(encoding="utf-8") as fh:
first = json.loads(fh.readline())
total = sum(1 for _ in fh) + 1
sample_id = first.get("__sample_id__")
prompt_sys = (first.get("prompt") or {}).get("system", "")
prompt_usr = (first.get("prompt") or {}).get("user", "")
answer = first.get("answer")
label, media_paths = _resolve_media_path(first, config)
print(f"=== {config} ===")
print(f" records: {total}")
print(f" sample_id: {sample_id}")
print(f" prompt.system: {len(prompt_sys)} chars")
print(f" prompt.user: {len(prompt_usr)} chars")
print(f" answer keys: {sorted((answer or {}).keys())}")
print(f" {label}:")
for media in media_paths:
if media is None:
continue
ok = "OK" if media.is_file() else "MISSING"
print(f" {ok} {media.relative_to(ROOT)}")
print()
if __name__ == "__main__":
main()