Spaces:
Runtime error
Runtime error
| from pathlib import Path | |
| import json | |
| import os | |
| from huggingface_hub import hf_hub_download | |
| DATASET_REPO = "noodbox/sv_territorial_master_dataset_v1" | |
| BOOTSTRAP_FLAG = Path(".bootstrap_complete") | |
| RUNTIME_DIR = Path("runtime_data") | |
| MANIFEST_PATH = RUNTIME_DIR / "manifest.json" | |
| REQUIRED_FILES = [ | |
| "data/geo/sv_geo_44.geojson", | |
| "data/geo/sv_geo_distritos.geojson", | |
| "data/territorial/territories_master.csv", | |
| "data/territorial/capitals.csv", | |
| "data/socioeconomic/indicators.csv", | |
| "data/electoral/elections_results.csv", | |
| "data/political/parties.csv", | |
| "data/political/candidates.csv", | |
| "data/game/campaign_effects.csv", | |
| ] | |
| def run_bootstrap(force: bool = False): | |
| RUNTIME_DIR.mkdir(exist_ok=True) | |
| if MANIFEST_PATH.exists() and BOOTSTRAP_FLAG.exists() and not force: | |
| return | |
| token = os.getenv("HF_TOKEN") | |
| downloaded = {} | |
| for file_path in REQUIRED_FILES: | |
| local_path = hf_hub_download( | |
| repo_id=DATASET_REPO, | |
| repo_type="dataset", | |
| filename=file_path, | |
| token=token, | |
| ) | |
| downloaded[file_path] = local_path | |
| manifest = { | |
| "dataset_repo": DATASET_REPO, | |
| "files": downloaded, | |
| "status": "ready", | |
| } | |
| with open(MANIFEST_PATH, "w", encoding="utf-8") as f: | |
| json.dump(manifest, f, ensure_ascii=False, indent=2) | |
| BOOTSTRAP_FLAG.write_text("ok", encoding="utf-8") |