kiyoonkim commited on
Commit
6059fae
·
1 Parent(s): 77d904f

Upload hfhub.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. hfhub.py +15 -8
hfhub.py CHANGED
@@ -1,23 +1,20 @@
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_name = "test2"
14
  repo_dir = Path("hfhub")
15
  token = os.environ["HF_TOKEN"]
 
16
 
17
  (Path(repo_dir) / "checkpoints").mkdir(parents=True, exist_ok=True)
18
 
19
  hf_api = HfApi(token=token)
 
 
20
  repo_name = hf_api.get_full_repo_name(repo_name)
 
21
  repo_url = hf_api.create_repo(
22
  repo_id=repo_name, repo_type="model", exist_ok=True, private=True
23
  )
@@ -28,3 +25,13 @@ hf_api.upload_file(
28
  path_or_fileobj="hfhub.py",
29
  path_in_repo="hfhub.py",
30
  )
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  from pathlib import Path
3
 
4
+ from huggingface_hub import HfApi, Repository, hf_hub_download, snapshot_download
 
 
 
 
 
 
 
5
 
6
  repo_name = "test2"
7
  repo_dir = Path("hfhub")
8
  token = os.environ["HF_TOKEN"]
9
+ download_checkpoint_with_name = "test_checkpoint"
10
 
11
  (Path(repo_dir) / "checkpoints").mkdir(parents=True, exist_ok=True)
12
 
13
  hf_api = HfApi(token=token)
14
+
15
+ # username/repo_name
16
  repo_name = hf_api.get_full_repo_name(repo_name)
17
+
18
  repo_url = hf_api.create_repo(
19
  repo_id=repo_name, repo_type="model", exist_ok=True, private=True
20
  )
 
25
  path_or_fileobj="hfhub.py",
26
  path_in_repo="hfhub.py",
27
  )
28
+
29
+ ckpt_filepath = hf_hub_download(
30
+ repo_id=repo_name,
31
+ repo_type="model",
32
+ cache_dir=Path(repo_dir),
33
+ resume_download=True,
34
+ subfolder="checkpoints",
35
+ filename=download_checkpoint_with_name,
36
+ )
37
+ print(ckpt_filepath)