client.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # Copyright (c) 2025 PaddlePaddle Authors. 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 argparse
  16. import sys
  17. from paddlex_hps_client import triton_request, utils
  18. from tritonclient import grpc as triton_grpc
  19. def main():
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument("--file", type=str, required=True)
  22. parser.add_argument("--file-type", type=int, choices=[0, 1])
  23. parser.add_argument("--no-visualization", action="store_true")
  24. parser.add_argument("--url", type=str, default="localhost:8001")
  25. args = parser.parse_args()
  26. client = triton_grpc.InferenceServerClient(args.url)
  27. input_ = {"file": utils.prepare_input_file(args.file)}
  28. if args.file_type is not None:
  29. input_["fileType"] = args.file_type
  30. if args.no_visualization:
  31. input_["visualize"] = False
  32. output = triton_request(client, "layout-parsing", input_)
  33. if output["errorCode"] != 0:
  34. print(f"Error code: {output['errorCode']}", file=sys.stderr)
  35. print(f"Error message: {output['errorMsg']}", file=sys.stderr)
  36. sys.exit(1)
  37. result = output["result"]
  38. for i, res in enumerate(result["layoutParsingResults"]):
  39. print(res["prunedResult"])
  40. for img_name, img in res["outputImages"].items():
  41. img_path = f"{img_name}_{i}.jpg"
  42. utils.save_output_file(img, img_path)
  43. print(f"Output image saved at {img_path}")
  44. if __name__ == "__main__":
  45. main()