Spaces:
Running
Running
Download scripts/prepare_samples.py from fffiloni/openusd-explorer: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/fffiloni/openusd-explorer/resolve/main/scripts/prepare_samples.py
- Command line
-
hf download hf://spaces/fffiloni/openusd-explorer/scripts/prepare_samples.py
-
curl -L -o prepare_samples.py https://huggingface.co/spaces/fffiloni/openusd-explorer/resolve/main/scripts/prepare_samples.py
1.84 kB
| """Download a small, real validation set. Not the catalogue limit.""" | |
| import json, urllib.request, concurrent.futures | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| manifest_path=ROOT/'.cache/media-manifest.json' | |
| if manifest_path.exists():manifest=json.loads(manifest_path.read_text()) | |
| else: | |
| manifest=json.load(urllib.request.urlopen('https://nvidia-simready-central.hf.space/library_media/usdsearch-dev/manifest.json',timeout=60)) | |
| manifest_path.parent.mkdir(exist_ok=True);manifest_path.write_text(json.dumps(manifest)) | |
| terms = ['food_produce_banana_m01/', 'chair_office_fabric_manager_a01/', 'Robotiq_2F_140/simready_usd/Robotiq_2F_140.usda', 'dishwasher_ldfn4542b/', 'cooking_ldgl6924s/', 'chest_of_drawers/'] | |
| samples = [] | |
| for term in terms: | |
| source, asset = next((k, v) for k, v in manifest['assets'].items() if term in k and v.get('usd')) | |
| base = 'https://nvidia-simready-central.hf.space/library_media/usdsearch-dev/' + asset['id'] + '/' | |
| name = source.split('/blob/')[1].split('/')[1] | |
| samples.append(dict(id=asset['id'], name=name, source=source, url=base+asset['usd']['files']['asset'], meta=base+asset['usd']['files']['articulation'], compact=asset['usd'].get('compact'), moving=asset.get('moving', 0))) | |
| (ROOT/'public/samples.json').write_text(json.dumps(samples, indent=2)) | |
| def get(sample): | |
| folder = ROOT / '.cache/samples' / sample['id']; folder.mkdir(parents=True, exist_ok=True) | |
| for url, name in [(sample['url'], 'asset.usdc'), (sample['meta'], 'articulation.json')]: | |
| dest = folder / name | |
| if not dest.exists(): | |
| dest.write_bytes(urllib.request.urlopen(url, timeout=60).read()) | |
| print(sample['name'], (folder/'asset.usdc').stat().st_size, flush=True) | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=4) as pool: | |
| list(pool.map(get, samples)) | |