Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

storage.py 1.8 KB

You have to be logged in to leave a comment. Sign In
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
36
37
38
39
40
41
42
  1. from huggingface_hub import Repository, repository
  2. import argparse
  3. import os
  4. DEFAULT_REPO = 'utensil/storage'
  5. DEFAULT_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument('REPO', type=str, default=DEFAULT_REPO, nargs='?', help="The HF repo to upload to: <user_name>/<repo_name>")
  8. parser.add_argument('ROOT', type=str, default=DEFAULT_ROOT, nargs='?', help="The local repo will clone to ROOT/<repo_name>")
  9. parser.add_argument('-m', '--model', type=bool, nargs='?', default=False, const=True, help='Set repo type to model (default: dataset)')
  10. parser.add_argument('-p', '--pull', type=bool, nargs='?', default=False, const=True, help='Whether to pull before push')
  11. parser.add_argument('-u', '--upload', type=bool, nargs='?', default=False, const=True, help='Whether to upload local changes')
  12. parser.add_argument('-l', '--lfs', type=bool, nargs='?', default=False, const=True, help='Whether to pull LFS files')
  13. args = parser.parse_args()
  14. if __name__ == '__main__':
  15. HF_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
  16. ROOT = args.ROOT
  17. os.chdir(ROOT)
  18. remote_repo = args.REPO
  19. local_repo = remote_repo.split('/')[-1]
  20. repo_type = 'model' if args.model else 'dataset'
  21. repo = Repository(local_dir=local_repo, clone_from=remote_repo, repo_type=repo_type, skip_lfs_files=not args.lfs, use_auth_token=HF_TOKEN)
  22. if args.pull:
  23. repo.git_pull(args.lfs)
  24. if args.upload:
  25. if not repo.is_repo_clean():
  26. repo.git_add(auto_lfs_track=True)
  27. # print(f'Files to be uploaded:\n\n{repository.files_to_be_staged(local_repo)}')
  28. repo.push_to_hub()
  29. print('Upload succeeded.')
  30. else:
  31. print('Nothing to upload, exiting...')
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...