pp_chatocrv3_doc.py 4.0 KB

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