Download src/reference_db/publishing/huggingface.py from offCanada/reference-db-system: direct link, hf CLI and curl.
- Browser
- Download file 793 Bytes
-
https://huggingface.co/offCanada/reference-db-system/resolve/main/src/reference_db/publishing/huggingface.py
- Command line
-
hf download hf://offCanada/reference-db-system/src/reference_db/publishing/huggingface.py
-
curl -L -o huggingface.py https://huggingface.co/offCanada/reference-db-system/resolve/main/src/reference_db/publishing/huggingface.py
793 Bytes
| from __future__ import annotations | |
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| def upload_files( | |
| repo_id: str, | |
| files: list[str | Path], | |
| path_prefix: str = "", | |
| commit_message: str = "Upload pipeline outputs", | |
| ) -> list[str]: | |
| api = HfApi() | |
| uploaded = [] | |
| for file in files: | |
| path = Path(file) | |
| if not path.exists(): | |
| raise FileNotFoundError(f"File not found: {path}") | |
| path_in_repo = f"{path_prefix.strip('/')}/{path.name}".lstrip("/") | |
| api.upload_file( | |
| path_or_fileobj=str(path), | |
| path_in_repo=path_in_repo, | |
| repo_id=repo_id, | |
| repo_type="dataset", | |
| commit_message=commit_message, | |
| ) | |
| uploaded.append(path_in_repo) | |
| return uploaded |