test2 / hfhub.py
kiyoonkim's picture
Upload hfhub.py with huggingface_hub
002c29c
import os
from pathlib import Path
from huggingface_hub import (
HfApi,
Repository,
create_repo,
get_full_repo_name,
hf_hub_download,
login,
logout,
snapshot_download,
upload_file,
)
repo_name = "test2"
repo_dir = Path("hfhub")
token = os.environ["HF_TOKEN"]
download_checkpoint_with_name = "test_checkpoint"
(Path(repo_dir) / "checkpoints").mkdir(parents=True, exist_ok=True)
login(token=token)
hf_api = HfApi(token=token)
# username/repo_name
repo_name = get_full_repo_name(repo_name)
repo_url = create_repo(
repo_id=repo_name, repo_type="model", exist_ok=True, private=True
)
upload_file(
repo_id=repo_name,
repo_type="model",
path_or_fileobj="hfhub.py",
path_in_repo="hfhub.py",
)
ckpt_filepath = hf_hub_download(
repo_id=repo_name,
repo_type="model",
# cache_dir=Path(repo_dir),
resume_download=True,
# subfolder="checkpoints",
filename="hfhub.py",
local_dir=Path(repo_dir) / "checkpoints",
)
print(ckpt_filepath)
snapshot_download(
repo_id="kiyoonkim/hmdb51-gulprgb",
repo_type="dataset",
resume_download=True,
local_dir=Path(repo_dir) / "datasets",
allow_patterns="splits_gulp_rgb/*",
)
logout()