transformers_cli.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import warnings
  16. from transformers import HfArgumentParser
  17. from transformers.commands.add_fast_image_processor import AddFastImageProcessorCommand
  18. from transformers.commands.add_new_model_like import AddNewModelLikeCommand
  19. from transformers.commands.chat import ChatCommand
  20. from transformers.commands.convert import ConvertCommand
  21. from transformers.commands.download import DownloadCommand
  22. from transformers.commands.env import EnvironmentCommand
  23. from transformers.commands.run import RunCommand
  24. from transformers.commands.serving import ServeCommand
  25. def main_cli():
  26. warnings.warn(
  27. "`transformers-cli` is deprecated in favour of `transformers` directly and will be removed in v5.",
  28. DeprecationWarning,
  29. )
  30. main()
  31. def main():
  32. parser = HfArgumentParser(prog="Transformers CLI tool", usage="transformers <command> [<args>]")
  33. commands_parser = parser.add_subparsers(help="transformers command helpers")
  34. # Register commands
  35. ChatCommand.register_subcommand(commands_parser)
  36. ConvertCommand.register_subcommand(commands_parser)
  37. DownloadCommand.register_subcommand(commands_parser)
  38. EnvironmentCommand.register_subcommand(commands_parser)
  39. RunCommand.register_subcommand(commands_parser)
  40. ServeCommand.register_subcommand(commands_parser)
  41. AddNewModelLikeCommand.register_subcommand(commands_parser)
  42. AddFastImageProcessorCommand.register_subcommand(commands_parser)
  43. # Let's go
  44. args = parser.parse_args()
  45. if not hasattr(args, "func"):
  46. parser.print_help()
  47. exit(1)
  48. # Run
  49. service = args.func(args)
  50. service.run()
  51. if __name__ == "__main__":
  52. main()