pp_structurev3.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (c) 2024 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 typing import Dict, Final, List, Optional, Tuple, Union
  15. from pydantic import BaseModel
  16. from ..infra.models import DataInfo, PrimaryOperations
  17. from .shared import ocr
  18. __all__ = [
  19. "INFER_ENDPOINT",
  20. "InferRequest",
  21. "LayoutParsingResult",
  22. "InferResult",
  23. "PRIMARY_OPERATIONS",
  24. ]
  25. INFER_ENDPOINT: Final[str] = "/layout-parsing"
  26. class InferRequest(ocr.BaseInferRequest):
  27. useDocOrientationClassify: Optional[bool] = False
  28. useDocUnwarping: Optional[bool] = False
  29. useTextlineOrientation: Optional[bool] = None
  30. useSealRecognition: Optional[bool] = None
  31. useTableRecognition: Optional[bool] = None
  32. useFormulaRecognition: Optional[bool] = None
  33. useChartRecognition: Optional[bool] = False
  34. useRegionDetection: Optional[bool] = None
  35. layoutThreshold: Optional[Union[float, dict]] = None
  36. layoutNms: Optional[bool] = None
  37. layoutUnclipRatio: Optional[Union[float, Tuple[float, float], dict]] = None
  38. layoutMergeBboxesMode: Optional[Union[str, dict]] = None
  39. textDetLimitSideLen: Optional[int] = None
  40. textDetLimitType: Optional[str] = None
  41. textDetThresh: Optional[float] = None
  42. textDetBoxThresh: Optional[float] = None
  43. textDetUnclipRatio: Optional[float] = None
  44. textRecScoreThresh: Optional[float] = None
  45. sealDetLimitSideLen: Optional[int] = None
  46. sealDetLimitType: Optional[str] = None
  47. sealDetThresh: Optional[float] = None
  48. sealDetBoxThresh: Optional[float] = None
  49. sealDetUnclipRatio: Optional[float] = None
  50. sealRecScoreThresh: Optional[float] = None
  51. useWiredTableCellsTransToHtml: bool = False
  52. useWirelessTableCellsTransToHtml: bool = False
  53. useTableOrientationClassify: bool = True
  54. useOcrResultsWithTableCells: bool = True
  55. useE2eWiredTableRecModel: bool = False
  56. useE2eWirelessTableRecModel: bool = True
  57. visualize: Optional[bool] = None
  58. class LayoutParsingResult(BaseModel):
  59. prunedResult: dict
  60. markdown: ocr.MarkdownData
  61. outputImages: Optional[Dict[str, str]] = None
  62. inputImage: Optional[str] = None
  63. class InferResult(BaseModel):
  64. layoutParsingResults: List[LayoutParsingResult]
  65. dataInfo: DataInfo
  66. PRIMARY_OPERATIONS: Final[PrimaryOperations] = {
  67. "infer": (INFER_ENDPOINT, InferRequest, InferResult),
  68. }