pp_chatocrv3_doc.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. "ANALYZE_IMAGES_ENDPOINT",
  20. "AnalyzeImagesRequest",
  21. "LayoutParsingResult",
  22. "AnalyzeImagesResult",
  23. "BUILD_VECTOR_STORE_ENDPOINT",
  24. "BuildVectorStoreRequest",
  25. "BuildVectorStoreResult",
  26. "CHAT_ENDPOINT",
  27. "ChatRequest",
  28. "ChatResult",
  29. "PRIMARY_OPERATIONS",
  30. ]
  31. ANALYZE_IMAGES_ENDPOINT: Final[str] = "/chatocr-visual"
  32. class AnalyzeImagesRequest(ocr.BaseInferRequest):
  33. useDocOrientationClassify: Optional[bool] = None
  34. useDocUnwarping: Optional[bool] = None
  35. useSealRecognition: Optional[bool] = None
  36. useTableRecognition: Optional[bool] = None
  37. layoutThreshold: Optional[Union[float, dict]] = None
  38. layoutNms: Optional[bool] = None
  39. layoutUnclipRatio: Optional[Union[float, Tuple[float, float], dict]] = None
  40. layoutMergeBboxesMode: Optional[Union[str, dict]] = None
  41. textDetLimitSideLen: Optional[int] = None
  42. textDetLimitType: Optional[str] = None
  43. textDetThresh: Optional[float] = None
  44. textDetBoxThresh: Optional[float] = None
  45. textDetUnclipRatio: Optional[float] = None
  46. textRecScoreThresh: Optional[float] = None
  47. sealDetLimitSideLen: Optional[int] = None
  48. sealDetLimitType: Optional[str] = None
  49. sealDetThresh: Optional[float] = None
  50. sealDetBoxThresh: Optional[float] = None
  51. sealDetUnclipRatio: Optional[float] = None
  52. sealRecScoreThresh: Optional[float] = None
  53. class LayoutParsingResult(BaseModel):
  54. prunedResult: dict
  55. outputImages: Optional[Dict[str, str]] = None
  56. inputImage: Optional[str] = None
  57. class AnalyzeImagesResult(BaseModel):
  58. layoutParsingResults: List[LayoutParsingResult]
  59. # `visualInfo` is made a separate field to facilitate its use in subsequent
  60. # steps.
  61. visualInfo: List[dict]
  62. dataInfo: DataInfo
  63. BUILD_VECTOR_STORE_ENDPOINT: Final[str] = "/chatocr-vector"
  64. class BuildVectorStoreRequest(BaseModel):
  65. visualInfo: List[dict]
  66. minCharacters: Optional[int] = None
  67. blockSize: Optional[int] = None
  68. retrieverConfig: Optional[dict] = None
  69. class BuildVectorStoreResult(BaseModel):
  70. vectorInfo: dict
  71. CHAT_ENDPOINT: Final[str] = "/chatocr-chat"
  72. class ChatRequest(BaseModel):
  73. keyList: List[str]
  74. visualInfo: List[dict]
  75. useVectorRetrieval: Optional[bool] = None
  76. vectorInfo: Optional[dict] = None
  77. minCharacters: Optional[int] = None
  78. textTaskDescription: Optional[str] = None
  79. textOutputFormat: Optional[str] = None
  80. # Is the "Str" in the name unnecessary? Keep the names consistent with the
  81. # parameters of the wrapped function though.
  82. textRulesStr: Optional[str] = None
  83. # Should this be just "text" instead of "text content", given that there is
  84. # no container?
  85. textFewShotDemoTextContent: Optional[str] = None
  86. textFewShotDemoKeyValueList: Optional[str] = None
  87. tableTaskDescription: Optional[str] = None
  88. tableOutputFormat: Optional[str] = None
  89. tableRulesStr: Optional[str] = None
  90. tableFewShotDemoTextContent: Optional[str] = None
  91. tableFewShotDemoKeyValueList: Optional[str] = None
  92. chatBotConfig: Optional[dict] = None
  93. retrieverConfig: Optional[dict] = None
  94. class ChatResult(BaseModel):
  95. chatResult: dict
  96. PRIMARY_OPERATIONS: Final[PrimaryOperations] = {
  97. "analyzeImages": (
  98. ANALYZE_IMAGES_ENDPOINT,
  99. AnalyzeImagesRequest,
  100. AnalyzeImagesResult,
  101. ),
  102. "buildVectorStore": (
  103. BUILD_VECTOR_STORE_ENDPOINT,
  104. BuildVectorStoreRequest,
  105. BuildVectorStoreResult,
  106. ),
  107. "chat": (CHAT_ENDPOINT, ChatRequest, ChatResult),
  108. }