hf.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright 2020 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from argparse import ArgumentParser
  15. from huggingface_hub.cli.auth import AuthCommands
  16. from huggingface_hub.cli.cache import CacheCommand
  17. from huggingface_hub.cli.download import DownloadCommand
  18. from huggingface_hub.cli.jobs import JobsCommands
  19. from huggingface_hub.cli.lfs import LfsCommands
  20. from huggingface_hub.cli.repo import RepoCommands
  21. from huggingface_hub.cli.repo_files import RepoFilesCommand
  22. from huggingface_hub.cli.system import EnvironmentCommand, VersionCommand
  23. from huggingface_hub.cli.upload import UploadCommand
  24. from huggingface_hub.cli.upload_large_folder import UploadLargeFolderCommand
  25. def main():
  26. parser = ArgumentParser("hf", usage="hf <command> [<args>]")
  27. commands_parser = parser.add_subparsers(help="hf command helpers")
  28. # Register commands
  29. AuthCommands.register_subcommand(commands_parser)
  30. CacheCommand.register_subcommand(commands_parser)
  31. DownloadCommand.register_subcommand(commands_parser)
  32. JobsCommands.register_subcommand(commands_parser)
  33. RepoCommands.register_subcommand(commands_parser)
  34. RepoFilesCommand.register_subcommand(commands_parser)
  35. UploadCommand.register_subcommand(commands_parser)
  36. UploadLargeFolderCommand.register_subcommand(commands_parser)
  37. # System commands
  38. EnvironmentCommand.register_subcommand(commands_parser)
  39. VersionCommand.register_subcommand(commands_parser)
  40. # LFS commands (hidden in --help)
  41. LfsCommands.register_subcommand(commands_parser)
  42. # Let's go
  43. args = parser.parse_args()
  44. if not hasattr(args, "func"):
  45. parser.print_help()
  46. exit(1)
  47. # Run
  48. service = args.func(args)
  49. if service is not None:
  50. service.run()
  51. if __name__ == "__main__":
  52. main()