"""Hugging Face Hub Dataset Uploader for E-Waste PCB Component Purity Index. Uploads the 8,190-image YOLO/COCO object detection dataset directly to Hugging Face Hub. Usage: .venv/bin/python push_to_hf.py --repo-id /ewaste-pcb-component-purity """ from __future__ import annotations import argparse import os import shutil import sys from pathlib import Path def prepare_hf_export_folder(export_dir: Path) -> Path: """Stage dataset files and metadata into Hugging Face export directory.""" export_dir.mkdir(parents=True, exist_ok=True) root_dir = Path(__file__).resolve().parent splits_src = root_dir / "splits" if not splits_src.exists(): raise FileNotFoundError(f"Splits directory not found at {splits_src}. Run 'python scraper.py split' first.") # Copy splits folder (train, val, test, data.yaml) dst_splits = export_dir / "data" if dst_splits.exists(): shutil.rmtree(dst_splits) shutil.copytree(splits_src, dst_splits) # Write Hugging Face Dataset Card README.md dataset_card_content = """--- language: - en license: cc-by-4.0 tags: - computer-vision - object-detection - yolo - ewaste - pcb - recycling - hardware-fraud size_categories: - 1K