transformers_cli.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. # Copyright 2020 The HuggingFace Team. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from argparse import ArgumentParser
  16. from .add_new_model_like import AddNewModelLikeCommand
  17. from .convert import ConvertCommand
  18. from .download import DownloadCommand
  19. from .env import EnvironmentCommand
  20. from .lfs import LfsCommands
  21. from .pt_to_tf import PTtoTFCommand
  22. from .run import RunCommand
  23. from .serving import ServeCommand
  24. from .user import UserCommands
  25. def main():
  26. parser = ArgumentParser("Transformers CLI tool", usage="transformers-cli <command> [<args>]")
  27. commands_parser = parser.add_subparsers(help="transformers-cli command helpers")
  28. # Register commands
  29. ConvertCommand.register_subcommand(commands_parser)
  30. DownloadCommand.register_subcommand(commands_parser)
  31. EnvironmentCommand.register_subcommand(commands_parser)
  32. RunCommand.register_subcommand(commands_parser)
  33. ServeCommand.register_subcommand(commands_parser)
  34. UserCommands.register_subcommand(commands_parser)
  35. AddNewModelLikeCommand.register_subcommand(commands_parser)
  36. LfsCommands.register_subcommand(commands_parser)
  37. PTtoTFCommand.register_subcommand(commands_parser)
  38. # Let's go
  39. args = parser.parse_args()
  40. if not hasattr(args, "func"):
  41. parser.print_help()
  42. exit(1)
  43. # Run
  44. service = args.func(args)
  45. service.run()
  46. if __name__ == "__main__":
  47. main()