Upload hfhub.py with huggingface_hub
Browse files
hfhub.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
from huggingface_hub import (
|
| 5 |
+
HfApi,
|
| 6 |
+
Repository,
|
| 7 |
+
create_repo,
|
| 8 |
+
hf_hub_download,
|
| 9 |
+
login,
|
| 10 |
+
snapshot_download,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
repo_path = "kiyoonkim/test2"
|
| 14 |
+
repo_dir = Path("hfhub")
|
| 15 |
+
token = os.environ["HF_TOKEN"]
|
| 16 |
+
# login(token=token)
|
| 17 |
+
# repo_url = create_repo(repo_id=repo_path, repo_type="model", exist_ok=True)
|
| 18 |
+
# print(repo_url)
|
| 19 |
+
|
| 20 |
+
(Path(repo_dir) / "checkpoints").mkdir(parents=True, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
hf_api = HfApi(token=token)
|
| 23 |
+
repo_url = hf_api.create_repo(
|
| 24 |
+
repo_id=repo_path, repo_type="model", exist_ok=True, private=True
|
| 25 |
+
)
|
| 26 |
+
print(repo_url)
|
| 27 |
+
|
| 28 |
+
hf_api.upload_file(
|
| 29 |
+
repo_id=repo_path,
|
| 30 |
+
repo_type="model",
|
| 31 |
+
path_or_fileobj="hfhub.py",
|
| 32 |
+
path_in_repo="hfhub.py",
|
| 33 |
+
)
|