This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
/
document_processor_service.py
261 lines (223 loc) · 9.69 KB
/
document_processor_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore
from google.cloud.documentai_v1.types import document as gcd_document
from google.cloud.documentai_v1.types import document_io
from google.cloud.documentai_v1.types import operation_metadata
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
__protobuf__ = proto.module(
package="google.cloud.documentai.v1",
manifest={
"ProcessRequest",
"HumanReviewStatus",
"ProcessResponse",
"BatchProcessRequest",
"BatchProcessResponse",
"BatchProcessMetadata",
"ReviewDocumentRequest",
"ReviewDocumentResponse",
"ReviewDocumentOperationMetadata",
},
)
class ProcessRequest(proto.Message):
r"""Request message for the process document method.
Attributes:
inline_document (google.cloud.documentai_v1.types.Document):
An inline document proto.
raw_document (google.cloud.documentai_v1.types.RawDocument):
A raw document content (bytes).
name (str):
Required. The processor resource name.
skip_human_review (bool):
Whether Human Review feature should be
skipped for this request. Default to false.
"""
inline_document = proto.Field(
proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document,
)
raw_document = proto.Field(
proto.MESSAGE, number=5, oneof="source", message=document_io.RawDocument,
)
name = proto.Field(proto.STRING, number=1,)
skip_human_review = proto.Field(proto.BOOL, number=3,)
class HumanReviewStatus(proto.Message):
r"""The status of human review on a processed document.
Attributes:
state (google.cloud.documentai_v1.types.HumanReviewStatus.State):
The state of human review on the processing
request.
state_message (str):
A message providing more details about the
human review state.
human_review_operation (str):
The name of the operation triggered by the processed
document. This field is populated only when the [state] is
[HUMAN_REVIEW_IN_PROGRESS]. It has the same response type
and metadata as the long running operation returned by
[ReviewDocument] method.
"""
class State(proto.Enum):
r"""The final state of human review on a processed document."""
STATE_UNSPECIFIED = 0
SKIPPED = 1
VALIDATION_PASSED = 2
IN_PROGRESS = 3
ERROR = 4
state = proto.Field(proto.ENUM, number=1, enum=State,)
state_message = proto.Field(proto.STRING, number=2,)
human_review_operation = proto.Field(proto.STRING, number=3,)
class ProcessResponse(proto.Message):
r"""Response message for the process document method.
Attributes:
document (google.cloud.documentai_v1.types.Document):
The document payload, will populate fields
based on the processor's behavior.
human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus):
The status of human review on the processed
document.
"""
document = proto.Field(proto.MESSAGE, number=1, message=gcd_document.Document,)
human_review_status = proto.Field(
proto.MESSAGE, number=3, message="HumanReviewStatus",
)
class BatchProcessRequest(proto.Message):
r"""Request message for batch process document method.
Attributes:
name (str):
Required. The processor resource name.
input_documents (google.cloud.documentai_v1.types.BatchDocumentsInputConfig):
The input documents for batch process.
document_output_config (google.cloud.documentai_v1.types.DocumentOutputConfig):
The overall output config for batch process.
skip_human_review (bool):
Whether Human Review feature should be
skipped for this request. Default to false.
"""
name = proto.Field(proto.STRING, number=1,)
input_documents = proto.Field(
proto.MESSAGE, number=5, message=document_io.BatchDocumentsInputConfig,
)
document_output_config = proto.Field(
proto.MESSAGE, number=6, message=document_io.DocumentOutputConfig,
)
skip_human_review = proto.Field(proto.BOOL, number=4,)
class BatchProcessResponse(proto.Message):
r"""Response message for batch process document method. """
class BatchProcessMetadata(proto.Message):
r"""The long running operation metadata for batch process method.
Attributes:
state (google.cloud.documentai_v1.types.BatchProcessMetadata.State):
The state of the current batch processing.
state_message (str):
A message providing more details about the
current state of processing. For example, the
error message if the operation is failed.
create_time (google.protobuf.timestamp_pb2.Timestamp):
The creation time of the operation.
update_time (google.protobuf.timestamp_pb2.Timestamp):
The last update time of the operation.
individual_process_statuses (Sequence[google.cloud.documentai_v1.types.BatchProcessMetadata.IndividualProcessStatus]):
The list of response details of each
document.
"""
class State(proto.Enum):
r"""Possible states of the batch processing operation."""
STATE_UNSPECIFIED = 0
WAITING = 1
RUNNING = 2
SUCCEEDED = 3
CANCELLING = 4
CANCELLED = 5
FAILED = 6
class IndividualProcessStatus(proto.Message):
r"""The status of a each individual document in the batch
process.
Attributes:
input_gcs_source (str):
The source of the document, same as the [input_gcs_source]
field in the request when the batch process started. The
batch process is started by take snapshot of that document,
since a user can move or change that document during the
process.
status (google.rpc.status_pb2.Status):
The status of the processing of the document.
output_gcs_destination (str):
The output_gcs_destination (in the request as
'output_gcs_destination') of the processed document if it
was successful, otherwise empty.
human_review_status (google.cloud.documentai_v1.types.HumanReviewStatus):
The status of human review on the processed
document.
"""
input_gcs_source = proto.Field(proto.STRING, number=1,)
status = proto.Field(proto.MESSAGE, number=2, message=status_pb2.Status,)
output_gcs_destination = proto.Field(proto.STRING, number=3,)
human_review_status = proto.Field(
proto.MESSAGE, number=5, message="HumanReviewStatus",
)
state = proto.Field(proto.ENUM, number=1, enum=State,)
state_message = proto.Field(proto.STRING, number=2,)
create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,)
update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,)
individual_process_statuses = proto.RepeatedField(
proto.MESSAGE, number=5, message=IndividualProcessStatus,
)
class ReviewDocumentRequest(proto.Message):
r"""Request message for review document method.
Attributes:
inline_document (google.cloud.documentai_v1.types.Document):
An inline document proto.
human_review_config (str):
Required. The resource name of the
HumanReviewConfig that the document will be
reviewed with.
enable_schema_validation (bool):
Whether the validation should be performed on
the ad-hoc review request.
priority (google.cloud.documentai_v1.types.ReviewDocumentRequest.Priority):
The priority of the human review task.
"""
class Priority(proto.Enum):
r"""The priority level of the human review task."""
DEFAULT = 0
URGENT = 1
inline_document = proto.Field(
proto.MESSAGE, number=4, oneof="source", message=gcd_document.Document,
)
human_review_config = proto.Field(proto.STRING, number=1,)
enable_schema_validation = proto.Field(proto.BOOL, number=3,)
priority = proto.Field(proto.ENUM, number=5, enum=Priority,)
class ReviewDocumentResponse(proto.Message):
r"""Response message for review document method.
Attributes:
gcs_destination (str):
The Cloud Storage uri for the human reviewed
document.
"""
gcs_destination = proto.Field(proto.STRING, number=1,)
class ReviewDocumentOperationMetadata(proto.Message):
r"""The long running operation metadata for review document
method.
Attributes:
common_metadata (google.cloud.documentai_v1.types.CommonOperationMetadata):
The basic metadata of the long running
operation.
"""
common_metadata = proto.Field(
proto.MESSAGE, number=5, message=operation_metadata.CommonOperationMetadata,
)
__all__ = tuple(sorted(__protobuf__.manifest))