Download scripts/push_prepared_artifacts.py from Sami94/hf-deep-rl-course-certification: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/Sami94/hf-deep-rl-course-certification/resolve/main/scripts/push_prepared_artifacts.py
- Command line
-
hf download hf://Sami94/hf-deep-rl-course-certification/scripts/push_prepared_artifacts.py
-
curl -L -o push_prepared_artifacts.py https://huggingface.co/Sami94/hf-deep-rl-course-certification/resolve/main/scripts/push_prepared_artifacts.py
1.67 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| USERNAME = "Sami94" | |
| ROOT = Path(__file__).resolve().parents[1] | |
| MODEL_REPOS = { | |
| f"{USERNAME}/ppo-LunarLander-v2": ROOT / "artifacts/unit1/ppo-LunarLander-v2", | |
| f"{USERNAME}/q-FrozenLake-v1-4x4-noSlippery": ROOT / "artifacts/unit2/q-FrozenLake-v1-4x4-noSlippery", | |
| f"{USERNAME}/q-Taxi-v3": ROOT / "artifacts/unit2/q-Taxi-v3", | |
| } | |
| COURSE_REPO = f"{USERNAME}/hf-deep-rl-course-certification" | |
| def upload_model_repo(api: HfApi, repo_id: str, folder: Path) -> None: | |
| if not folder.exists(): | |
| print(f"SKIP {repo_id}: missing folder {folder}") | |
| return | |
| api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True) | |
| api.upload_folder(repo_id=repo_id, repo_type="model", folder_path=folder, path_in_repo=".") | |
| print(f"Uploaded model repo: https://huggingface.co/{repo_id}") | |
| def upload_course_folder(api: HfApi) -> None: | |
| api.create_repo(repo_id=COURSE_REPO, repo_type="model", exist_ok=True) | |
| api.upload_folder( | |
| repo_id=COURSE_REPO, | |
| repo_type="model", | |
| folder_path=ROOT, | |
| path_in_repo=".", | |
| ignore_patterns=[ | |
| ".git/*", | |
| "__pycache__/*", | |
| "*.pyc", | |
| ], | |
| ) | |
| print(f"Uploaded course folder: https://huggingface.co/{COURSE_REPO}") | |
| def main() -> None: | |
| api = HfApi() | |
| whoami = api.whoami() | |
| print(f"Authenticated as: {whoami.get('name')} ({whoami.get('fullname')})") | |
| for repo_id, folder in MODEL_REPOS.items(): | |
| upload_model_repo(api, repo_id, folder) | |
| upload_course_folder(api) | |
| if __name__ == "__main__": | |
| main() | |