huggingface_cli.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.commands._cli_utils import show_deprecation_warning
  16. from huggingface_hub.commands.delete_cache import DeleteCacheCommand
  17. from huggingface_hub.commands.download import DownloadCommand
  18. from huggingface_hub.commands.env import EnvironmentCommand
  19. from huggingface_hub.commands.lfs import LfsCommands
  20. from huggingface_hub.commands.repo import RepoCommands
  21. from huggingface_hub.commands.repo_files import RepoFilesCommand
  22. from huggingface_hub.commands.scan_cache import ScanCacheCommand
  23. from huggingface_hub.commands.tag import TagCommands
  24. from huggingface_hub.commands.upload import UploadCommand
  25. from huggingface_hub.commands.upload_large_folder import UploadLargeFolderCommand
  26. from huggingface_hub.commands.user import UserCommands
  27. from huggingface_hub.commands.version import VersionCommand
  28. def main():
  29. parser = ArgumentParser("huggingface-cli", usage="huggingface-cli <command> [<args>]")
  30. commands_parser = parser.add_subparsers(help="huggingface-cli command helpers")
  31. # Register commands
  32. DownloadCommand.register_subcommand(commands_parser)
  33. UploadCommand.register_subcommand(commands_parser)
  34. RepoFilesCommand.register_subcommand(commands_parser)
  35. EnvironmentCommand.register_subcommand(commands_parser)
  36. UserCommands.register_subcommand(commands_parser)
  37. RepoCommands.register_subcommand(commands_parser)
  38. LfsCommands.register_subcommand(commands_parser)
  39. ScanCacheCommand.register_subcommand(commands_parser)
  40. DeleteCacheCommand.register_subcommand(commands_parser)
  41. TagCommands.register_subcommand(commands_parser)
  42. VersionCommand.register_subcommand(commands_parser)
  43. # Experimental
  44. UploadLargeFolderCommand.register_subcommand(commands_parser)
  45. # Let's go
  46. args = parser.parse_args()
  47. if not hasattr(args, "func"):
  48. show_deprecation_warning("huggingface-cli", "hf")
  49. parser.print_help()
  50. exit(1)
  51. # Run
  52. service = args.func(args)
  53. service.run()
  54. if __name__ == "__main__":
  55. main()