Spaces:
Running
Running
Download scripts/push_to_hub.py from RDS777/TARGET_SPACE: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/spaces/RDS777/TARGET_SPACE/resolve/main/scripts/push_to_hub.py
- Command line
-
hf download hf://spaces/RDS777/TARGET_SPACE/scripts/push_to_hub.py
-
curl -L -o push_to_hub.py https://huggingface.co/spaces/RDS777/TARGET_SPACE/resolve/main/scripts/push_to_hub.py
2.31 kB
| """Publie le code (Space Docker) ou un checkpoint (modèle) sur le Hub via huggingface_hub. | |
| HF_TOKEN=... python scripts/push_to_hub.py --repo-id RDS777/mouh --kind space | |
| HF_TOKEN=... python scripts/push_to_hub.py --repo-id RDS777/mouh-1.5b --kind model --folder checkpoints/final | |
| python scripts/push_to_hub.py --repo-id x/y --kind space --dry-run # liste les fichiers sans rien envoyer | |
| """ | |
| import argparse | |
| import os | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| IGNORE = ["__pycache__", "*.pyc", ".git", ".git/*", ".pytest_cache", "checkpoints", "checkpoints/*", "*.egg-info", ".env", "audit"] | |
| def main() -> None: | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--repo-id", required=True) | |
| ap.add_argument("--kind", choices=["space", "model"], default="space") | |
| ap.add_argument("--folder", default=str(ROOT)) | |
| ap.add_argument("--private", action="store_true") | |
| ap.add_argument("--dry-run", action="store_true") | |
| ap.add_argument("--message", default="M.O.U.H. — mise à jour") | |
| a = ap.parse_args() | |
| folder = Path(a.folder) | |
| files = [p for p in folder.rglob("*") if p.is_file() and not any( | |
| part in {"__pycache__", ".git", ".pytest_cache", "checkpoints", "audit"} or part.endswith(".egg-info") | |
| for part in p.relative_to(folder).parts) and p.suffix != ".pyc" and p.name != ".env"] | |
| if a.dry_run: | |
| for p in sorted(files): | |
| print(p.relative_to(folder)) | |
| print(f"{len(files)} fichier(s) seraient envoyés vers {a.kind} {a.repo_id}") | |
| return | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| sys.exit("HF_TOKEN absent : définissez un jeton avec droit d'écriture") | |
| from huggingface_hub import HfApi | |
| api = HfApi(token=token) | |
| if a.kind == "space": | |
| api.create_repo(a.repo_id, repo_type="space", space_sdk="docker", exist_ok=True, private=a.private) | |
| else: | |
| api.create_repo(a.repo_id, repo_type="model", exist_ok=True, private=a.private) | |
| info = api.upload_folder(folder_path=str(folder), repo_id=a.repo_id, repo_type=a.kind, | |
| ignore_patterns=IGNORE, commit_message=a.message) | |
| print(info) | |
| if __name__ == "__main__": | |
| main() | |