pp_structurev3.py 2.9 KB

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