"""Structure and format the 8,190-image dataset into standard Hugging Face Dataset format for CLI push. Outputs to `huggingface_dataset/`: huggingface_dataset/ ├── README.md # Dataset Card with YAML frontmatter metadata ├── data.yaml # YOLO dataset configuration ├── train/ # 5,733 images and .txt label pairs │ ├── images/ │ └── labels/ ├── val/ # 1,228 images and .txt label pairs │ ├── images/ │ └── labels/ └── test/ # 1,229 images and .txt label pairs ├── images/ └── labels/ """ from __future__ import annotations import json import shutil from pathlib import Path ROOT_DIR = Path(__file__).resolve().parent SPLITS_DIR = ROOT_DIR / "splits" HF_DATASET_DIR = ROOT_DIR / "huggingface_dataset" def build_huggingface_dataset(): if not SPLITS_DIR.exists(): raise FileNotFoundError(f"Splits directory not found at {SPLITS_DIR}. Run 'python scraper.py split' first.") print(f"Preparing Hugging Face dataset directory at {HF_DATASET_DIR}...") if HF_DATASET_DIR.exists(): shutil.rmtree(HF_DATASET_DIR) HF_DATASET_DIR.mkdir(parents=True, exist_ok=True) # Copy train, val, test splits for split_name in ["train", "val", "test"]: src_split = SPLITS_DIR / split_name dst_split = HF_DATASET_DIR / split_name if src_split.exists(): shutil.copytree(src_split, dst_split) # Copy data.yaml shutil.copy2(SPLITS_DIR / "data.yaml", HF_DATASET_DIR / "data.yaml") # Create Hugging Face Dataset Card README.md with YAML frontmatter readme_content = """--- language: - en license: cc-by-4.0 tags: - computer-vision - object-detection - yolo - ewaste - pcb - recycling - hardware-fraud size_categories: - 1K/ . --repo-type=dataset") if __name__ == "__main__": build_huggingface_dataset()