kiyoonkim commited on
Commit
002c29c
·
1 Parent(s): 9c70686

Upload hfhub.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. hfhub.py +18 -5
hfhub.py CHANGED
@@ -1,7 +1,17 @@
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")
@@ -10,16 +20,18 @@ 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
  )
21
 
22
- hf_api.upload_file(
 
23
  repo_id=repo_name,
24
  repo_type="model",
25
  path_or_fileobj="hfhub.py",
@@ -43,5 +55,6 @@ snapshot_download(
43
  resume_download=True,
44
  local_dir=Path(repo_dir) / "datasets",
45
  allow_patterns="splits_gulp_rgb/*",
46
- token=token,
47
  )
 
 
 
1
  import os
2
  from pathlib import Path
3
 
4
+ from huggingface_hub import (
5
+ HfApi,
6
+ Repository,
7
+ create_repo,
8
+ get_full_repo_name,
9
+ hf_hub_download,
10
+ login,
11
+ logout,
12
+ snapshot_download,
13
+ upload_file,
14
+ )
15
 
16
  repo_name = "test2"
17
  repo_dir = Path("hfhub")
 
20
 
21
  (Path(repo_dir) / "checkpoints").mkdir(parents=True, exist_ok=True)
22
 
23
+ login(token=token)
24
  hf_api = HfApi(token=token)
25
 
26
  # username/repo_name
27
+ repo_name = get_full_repo_name(repo_name)
28
 
29
+ repo_url = create_repo(
30
  repo_id=repo_name, repo_type="model", exist_ok=True, private=True
31
  )
32
 
33
+
34
+ upload_file(
35
  repo_id=repo_name,
36
  repo_type="model",
37
  path_or_fileobj="hfhub.py",
 
55
  resume_download=True,
56
  local_dir=Path(repo_dir) / "datasets",
57
  allow_patterns="splits_gulp_rgb/*",
 
58
  )
59
+
60
+ logout()