Spaces:
Running
Running
Download scripts/create_and_push.py from RDS777/TARGET_SPACE: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/spaces/RDS777/TARGET_SPACE/resolve/main/scripts/create_and_push.py
- Command line
-
hf download hf://spaces/RDS777/TARGET_SPACE/scripts/create_and_push.py
-
curl -L -o create_and_push.py https://huggingface.co/spaces/RDS777/TARGET_SPACE/resolve/main/scripts/create_and_push.py
3 kB
| #!/usr/bin/env python3 | |
| """Crée (si besoin) le dépôt Dataset PRIVÉ et y pousse README + données validées. | |
| Par défaut : simulation (dry-run). Ajouter --yes pour agir. | |
| Le jeton est lu dans HF_TOKEN (droits « write »), jamais passé en argument. | |
| export HF_TOKEN=hf_xxx | |
| python scripts/create_and_push.py # simulation | |
| python scripts/create_and_push.py --yes # crée le dépôt vide + README | |
| python scripts/create_and_push.py --yes --data data/ # + pousse les JSONL validés | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| DEFAULT_REPO = "RDS777/sky-trajectories" | |
| def main(argv: list[str] | None = None) -> int: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--repo", default=DEFAULT_REPO) | |
| ap.add_argument("--data", type=Path, default=None, help="dossier de JSONL à pousser (validés d'abord)") | |
| ap.add_argument("--hidden-dir", type=Path, default=None) | |
| ap.add_argument("--yes", action="store_true") | |
| a = ap.parse_args(argv) | |
| files = sorted(a.data.glob("*.jsonl")) if a.data else [] | |
| if files: | |
| cmd = [sys.executable, str(ROOT / "scripts" / "validate.py"), *map(str, files)] | |
| if a.hidden_dir: | |
| cmd += ["--hidden-dir", str(a.hidden_dir)] | |
| if subprocess.run(cmd, stdout=subprocess.DEVNULL).returncode != 0: | |
| print("Validation échouée : rien n'est poussé. Lancez validate.py pour le détail.", file=sys.stderr) | |
| return 1 | |
| if not a.hidden_dir: | |
| print("AVERTISSEMENT : fuite de tests cachés non contrôlée (pas de --hidden-dir).", file=sys.stderr) | |
| print(f"Dépôt cible : datasets/{a.repo} (privé)") | |
| print(f"Carte du dataset : {ROOT / 'DATASET_CARD.md'} (publiée comme README.md du dépôt Dataset)") | |
| print(f"JSONL à pousser : {[f.name for f in files] or 'aucun (dépôt vide + README)'}") | |
| if not a.yes: | |
| print("Simulation seulement. Relancez avec --yes pour agir.") | |
| return 0 | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| print("HF_TOKEN absent de l'environnement.", file=sys.stderr) | |
| return 2 | |
| from huggingface_hub import HfApi | |
| api = HfApi(token=token) | |
| api.create_repo(a.repo, repo_type="dataset", private=True, exist_ok=True) | |
| api.upload_file(path_or_fileobj=str(ROOT / "DATASET_CARD.md"), path_in_repo="README.md", | |
| repo_id=a.repo, repo_type="dataset", commit_message="Carte du dataset") | |
| for f in files: | |
| api.upload_file(path_or_fileobj=str(f), path_in_repo=f"data/{f.name}", repo_id=a.repo, | |
| repo_type="dataset", commit_message=f"Ajout {f.name}") | |
| info = api.repo_info(a.repo, repo_type="dataset") | |
| print(f"OK — https://huggingface.co/datasets/{a.repo} (private={info.private})") | |
| return 0 if info.private else 3 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |