Download __init__.py from agibot-world/GenieSimAssets: direct link, hf CLI and curl.
- Browser
- Download file 4.95 kB
-
https://huggingface.co/datasets/agibot-world/GenieSimAssets/resolve/a0813aad7c16165daffbe6c2737754e0344809ee/__init__.py
- Command line
-
hf download hf://datasets/agibot-world/GenieSimAssets@a0813aad7c16165daffbe6c2737754e0344809ee/__init__.py
-
curl -L -o __init__.py https://huggingface.co/datasets/agibot-world/GenieSimAssets/resolve/a0813aad7c16165daffbe6c2737754e0344809ee/__init__.py
4.95 kB
| import os, ast, hashlib | |
| from pathlib import Path | |
| import json | |
| ASSETS_PATH = Path(__file__).parent | |
| ASSETS_PATH_ABS = Path(__file__).parent.resolve() | |
| def extract_item_dict(file_path): | |
| try: | |
| with open(file_path, "r", encoding="utf-8") as f: | |
| content = f.read() | |
| tree = ast.parse(content) | |
| if len(tree.body) == 1 and isinstance(tree.body[0], ast.Expr) and isinstance(tree.body[0].value, ast.Dict): | |
| return ast.literal_eval(tree.body[0].value) | |
| return None | |
| except Exception as e: | |
| print(f"Error processing {file_path}: {e}") | |
| return None | |
| def collect_all_items(item_file_list, base_path="."): | |
| """Collect ITEM dicts from all item.py files""" | |
| combined_dict = {} | |
| num = 0 | |
| visualization_path = ASSETS_PATH / "extra" / "visualization" | |
| has_visualization = visualization_path.exists() | |
| for item_path in item_file_list: | |
| # Assuming item_path is a file path like "objects/carton/benchmark_carton_003/item.py" | |
| file_path = Path(base_path) / item_path | |
| usda_path = (Path(item_path).parent / "Aligned.usda").relative_to(ASSETS_PATH).as_posix() | |
| desc_path = (Path(base_path) / item_path).parent / "description.py" | |
| # Use the directory name as key, or customize as needed | |
| key = file_path.parent.name | |
| interaction_path = ASSETS_PATH / "interaction" / key / "interaction.json" | |
| # visualization paths (similar to interaction) | |
| visualization_video_path = visualization_path / key / "video" / "merged.mp4" | |
| visualization_snapshot_dir_path = visualization_path / key / "snapshot" | |
| if file_path.exists(): | |
| item_dict = extract_item_dict(file_path) | |
| if item_dict: | |
| if key in combined_dict: | |
| print("ERROR!!! Duplicated object detected!", file_path) | |
| print(" ", usda_path) | |
| combined_dict[key] = item_dict | |
| combined_dict[key]["url"] = str(usda_path) | |
| if desc_path.exists(): | |
| desc_dict = extract_item_dict(desc_path) | |
| if desc_dict: | |
| combined_dict[key]["description"] = desc_dict | |
| else: | |
| combined_dict[key]["description"] = {} | |
| print("WARN !!! Empty LLM description!", file_path) | |
| # video path - from visualization folder | |
| if visualization_video_path.exists(): | |
| combined_dict[key]["video"] = str(visualization_video_path) | |
| else: | |
| combined_dict[key]["video"] = "" | |
| if has_visualization: | |
| print("WARN !!! Empty video!", visualization_video_path) | |
| # snapshot dir path - from visualization folder | |
| if visualization_snapshot_dir_path.exists(): | |
| snapshot_files = list(visualization_snapshot_dir_path.glob("*")) | |
| combined_dict[key]["snapshot"] = snapshot_files | |
| else: | |
| combined_dict[key]["snapshot"] = [] | |
| if len(combined_dict[key]["snapshot"]) == 0: | |
| if has_visualization: | |
| print("WARN !!! Empty snapshot!", visualization_snapshot_dir_path) | |
| # interaction | |
| if interaction_path.exists(): | |
| try: | |
| interaction_dict = json.load(open(interaction_path)) | |
| combined_dict[key]["interaction"] = interaction_dict["interaction"] | |
| except Exception as e: | |
| # print(f"Error loading interaction.json: {e}") | |
| combined_dict[key]["interaction"] = {} | |
| else: | |
| combined_dict[key]["interaction"] = {} | |
| # print("WARN !!! Empty interaction.json!", interaction_path) | |
| else: | |
| print(f"No ITEM dict found in {file_path}") | |
| else: | |
| print(f"File not found: {file_path}") | |
| num += 1 | |
| if num != len(combined_dict): | |
| error = f"ERROR! there're items using the same name!!! {num} != {len(combined_dict)}" | |
| print(error) | |
| # raise Exception(error) | |
| return combined_dict | |
| def find_all_items(): | |
| base = Path(__file__).parent / "objects" | |
| for root, dirs, files in os.walk(base, followlinks=True): | |
| if "object_parameters.json" in files: | |
| yield Path(root) / "item.py" | |
| ######## | |
| print(f"Initializing GenieSim Asset Lib at", Path(__file__).parent) | |
| # Collect all ITEM dicts | |
| ASSETS_INDEX = collect_all_items(find_all_items()) | |
| ASSETS_PAYLOAD = "".join(f"{k}={v}\n" for k, v in sorted(ASSETS_INDEX.items())).encode("utf-8") | |
| ASSETS_INDEX_HASH = hashlib.sha256(ASSETS_PAYLOAD).hexdigest() | |
| print(f"Initialized GenieSim Asset Lib, Found {len(ASSETS_INDEX)} items, hash: {ASSETS_INDEX_HASH}") | |