command.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # copyright (c) 2021 PaddlePaddle Authors. 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 six import text_type as _text_type
  15. import argparse
  16. import sys
  17. def arg_parser():
  18. parser = argparse.ArgumentParser()
  19. parser.add_argument(
  20. "--start_restful",
  21. "-sr",
  22. action="store_true",
  23. default=False,
  24. help="start paddlex restful server")
  25. parser.add_argument(
  26. "--port",
  27. "--pt",
  28. type=_text_type,
  29. default=None,
  30. help="set the port of restful server")
  31. parser.add_argument(
  32. "--workspace_dir",
  33. "--wd",
  34. type=_text_type,
  35. default=None,
  36. help="set the workspace dir of restful server")
  37. return parser
  38. def main():
  39. if len(sys.argv) < 2:
  40. print(
  41. "Use command 'paddlex_restful -h` to print the help information\n")
  42. return
  43. parser = arg_parser()
  44. args = parser.parse_args()
  45. if args.start_restful:
  46. import paddlex_restful as pdxr
  47. assert args.port is not None, "--port should be defined while start restful server"
  48. assert args.workspace_dir, "--workspace_dir should be define while start restful server"
  49. port = args.port
  50. workspace_dir = args.workspace_dir
  51. pdxr.restful.app.run(port, workspace_dir)
  52. if __name__ == "__main__":
  53. main()