File size: 793 Bytes
1cd137c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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 |