command.py 1.8 KB

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