Skip to content

Commit e8164ea

Browse files
[CHANGE ME] Re-generated automl to pick up changes in the API or client library generator.
1 parent ba3668d commit e8164ea

File tree

74 files changed

+11683
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+11683
-378
lines changed

automl/google/cloud/automl_v1/gapic/auto_ml_client.py

Lines changed: 385 additions & 1 deletion
Large diffs are not rendered by default.

automl/google/cloud/automl_v1/gapic/auto_ml_client_config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
"retry_codes_name": "non_idempotent",
5353
"retry_params_name": "default",
5454
},
55+
"GetAnnotationSpec": {
56+
"timeout_millis": 5000,
57+
"retry_codes_name": "idempotent",
58+
"retry_params_name": "default",
59+
},
5560
"CreateModel": {
5661
"timeout_millis": 20000,
5762
"retry_codes_name": "non_idempotent",
@@ -77,6 +82,21 @@
7782
"retry_codes_name": "idempotent",
7883
"retry_params_name": "default",
7984
},
85+
"DeployModel": {
86+
"timeout_millis": 5000,
87+
"retry_codes_name": "non_idempotent",
88+
"retry_params_name": "default",
89+
},
90+
"UndeployModel": {
91+
"timeout_millis": 5000,
92+
"retry_codes_name": "non_idempotent",
93+
"retry_params_name": "default",
94+
},
95+
"ExportModel": {
96+
"timeout_millis": 5000,
97+
"retry_codes_name": "non_idempotent",
98+
"retry_params_name": "default",
99+
},
80100
"GetModelEvaluation": {
81101
"timeout_millis": 5000,
82102
"retry_codes_name": "idempotent",

automl/google/cloud/automl_v1/gapic/enums.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,80 @@
1919
import enum
2020

2121

22+
class ClassificationType(enum.IntEnum):
23+
"""
24+
Type of the classification problem.
25+
26+
Attributes:
27+
CLASSIFICATION_TYPE_UNSPECIFIED (int): An un-set value of this enum.
28+
MULTICLASS (int): At most one label is allowed per example.
29+
MULTILABEL (int): Multiple labels are allowed for one example.
30+
"""
31+
32+
CLASSIFICATION_TYPE_UNSPECIFIED = 0
33+
MULTICLASS = 1
34+
MULTILABEL = 2
35+
36+
37+
class Document(object):
38+
class Layout(object):
39+
class TextSegmentType(enum.IntEnum):
40+
"""
41+
The type of TextSegment in the context of the original document.
42+
43+
Attributes:
44+
TEXT_SEGMENT_TYPE_UNSPECIFIED (int): Should not be used.
45+
TOKEN (int): The text segment is a token. e.g. word.
46+
PARAGRAPH (int): The text segment is a paragraph.
47+
FORM_FIELD (int): The text segment is a form field.
48+
FORM_FIELD_NAME (int): The text segment is the name part of a form field. It will be treated as
49+
child of another FORM\_FIELD TextSegment if its span is subspan of
50+
another TextSegment with type FORM\_FIELD.
51+
FORM_FIELD_CONTENTS (int): The text segment is the text content part of a form field. It will be
52+
treated as child of another FORM\_FIELD TextSegment if its span is
53+
subspan of another TextSegment with type FORM\_FIELD.
54+
TABLE (int): The text segment is a whole table, including headers, and all rows.
55+
TABLE_HEADER (int): The text segment is a table's headers. It will be treated as child of
56+
another TABLE TextSegment if its span is subspan of another TextSegment
57+
with type TABLE.
58+
TABLE_ROW (int): The text segment is a row in table. It will be treated as child of
59+
another TABLE TextSegment if its span is subspan of another TextSegment
60+
with type TABLE.
61+
TABLE_CELL (int): The text segment is a cell in table. It will be treated as child of
62+
another TABLE\_ROW TextSegment if its span is subspan of another
63+
TextSegment with type TABLE\_ROW.
64+
"""
65+
66+
TEXT_SEGMENT_TYPE_UNSPECIFIED = 0
67+
TOKEN = 1
68+
PARAGRAPH = 2
69+
FORM_FIELD = 3
70+
FORM_FIELD_NAME = 4
71+
FORM_FIELD_CONTENTS = 5
72+
TABLE = 6
73+
TABLE_HEADER = 7
74+
TABLE_ROW = 8
75+
TABLE_CELL = 9
76+
77+
78+
class DocumentDimensions(object):
79+
class DocumentDimensionUnit(enum.IntEnum):
80+
"""
81+
Unit of the document dimension.
82+
83+
Attributes:
84+
DOCUMENT_DIMENSION_UNIT_UNSPECIFIED (int): Should not be used.
85+
INCH (int): Document dimension is measured in inches.
86+
CENTIMETER (int): Document dimension is measured in centimeters.
87+
POINT (int): Document dimension is measured in points. 72 points = 1 inch.
88+
"""
89+
90+
DOCUMENT_DIMENSION_UNIT_UNSPECIFIED = 0
91+
INCH = 1
92+
CENTIMETER = 2
93+
POINT = 3
94+
95+
2296
class Model(object):
2397
class DeploymentState(enum.IntEnum):
2498
"""

automl/google/cloud/automl_v1/gapic/prediction_service_client.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@
2626
import google.api_core.gapic_v1.method
2727
import google.api_core.gapic_v1.routing_header
2828
import google.api_core.grpc_helpers
29+
import google.api_core.operation
30+
import google.api_core.operations_v1
2931
import google.api_core.path_template
3032
import grpc
3133

3234
from google.cloud.automl_v1.gapic import enums
3335
from google.cloud.automl_v1.gapic import prediction_service_client_config
3436
from google.cloud.automl_v1.gapic.transports import prediction_service_grpc_transport
37+
from google.cloud.automl_v1.proto import annotation_spec_pb2
3538
from google.cloud.automl_v1.proto import data_items_pb2
3639
from google.cloud.automl_v1.proto import dataset_pb2
40+
from google.cloud.automl_v1.proto import image_pb2
3741
from google.cloud.automl_v1.proto import io_pb2
3842
from google.cloud.automl_v1.proto import model_evaluation_pb2
3943
from google.cloud.automl_v1.proto import model_pb2
@@ -222,8 +226,18 @@ def predict(
222226
returned in the response. Available for following ML problems, and their
223227
expected request payloads:
224228
229+
- Image Classification - Image in .JPEG, .GIF or .PNG format,
230+
image\_bytes up to 30MB.
231+
- Image Object Detection - Image in .JPEG, .GIF or .PNG format,
232+
image\_bytes up to 30MB.
233+
- Text Classification - TextSnippet, content up to 60,000 characters,
234+
UTF-8 encoded.
235+
- Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8
236+
NFC encoded.
225237
- Translation - TextSnippet, content up to 25,000 characters, UTF-8
226238
encoded.
239+
- Text Sentiment - TextSnippet, content up 500 characters, UTF-8
240+
encoded.
227241
228242
Example:
229243
>>> from google.cloud import automl_v1
@@ -246,6 +260,19 @@ def predict(
246260
message :class:`~google.cloud.automl_v1.types.ExamplePayload`
247261
params (dict[str -> str]): Additional domain-specific parameters, any string must be up to 25000
248262
characters long.
263+
264+
- For Image Classification:
265+
266+
``score_threshold`` - (float) A value from 0.0 to 1.0. When the model
267+
makes predictions for an image, it will only produce results that
268+
have at least this confidence score. The default is 0.5.
269+
270+
- For Image Object Detection: ``score_threshold`` - (float) When Model
271+
detects objects on the image, it will only produce bounding boxes
272+
which have at least this confidence score. Value in 0 to 1 range,
273+
default is 0.5. ``max_bounding_box_count`` - (int64) No more than
274+
this number of bounding boxes will be returned in the response.
275+
Default is 100, the requested value may be limited by server.
249276
retry (Optional[google.api_core.retry.Retry]): A retry object used
250277
to retry requests. If ``None`` is specified, requests will
251278
be retried using a default configuration.
@@ -295,3 +322,142 @@ def predict(
295322
return self._inner_api_calls["predict"](
296323
request, retry=retry, timeout=timeout, metadata=metadata
297324
)
325+
326+
def batch_predict(
327+
self,
328+
name,
329+
input_config,
330+
output_config,
331+
params=None,
332+
retry=google.api_core.gapic_v1.method.DEFAULT,
333+
timeout=google.api_core.gapic_v1.method.DEFAULT,
334+
metadata=None,
335+
):
336+
"""
337+
Perform a batch prediction. Unlike the online ``Predict``, batch
338+
prediction result won't be immediately available in the response.
339+
Instead, a long running operation object is returned. User can poll the
340+
operation result via ``GetOperation`` method. Once the operation is
341+
done, ``BatchPredictResult`` is returned in the ``response`` field.
342+
Available for following ML problems:
343+
344+
- Image Classification
345+
- Image Object Detection
346+
- Text Extraction
347+
348+
Example:
349+
>>> from google.cloud import automl_v1
350+
>>>
351+
>>> client = automl_v1.PredictionServiceClient()
352+
>>>
353+
>>> name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
354+
>>>
355+
>>> # TODO: Initialize `input_config`:
356+
>>> input_config = {}
357+
>>>
358+
>>> # TODO: Initialize `output_config`:
359+
>>> output_config = {}
360+
>>>
361+
>>> response = client.batch_predict(name, input_config, output_config)
362+
>>>
363+
>>> def callback(operation_future):
364+
... # Handle result.
365+
... result = operation_future.result()
366+
>>>
367+
>>> response.add_done_callback(callback)
368+
>>>
369+
>>> # Handle metadata.
370+
>>> metadata = response.metadata()
371+
372+
Args:
373+
name (str): Name of the model requested to serve the batch prediction.
374+
input_config (Union[dict, ~google.cloud.automl_v1.types.BatchPredictInputConfig]): Required. The input configuration for batch prediction.
375+
376+
If a dict is provided, it must be of the same form as the protobuf
377+
message :class:`~google.cloud.automl_v1.types.BatchPredictInputConfig`
378+
output_config (Union[dict, ~google.cloud.automl_v1.types.BatchPredictOutputConfig]): Required. The Configuration specifying where output predictions should
379+
be written.
380+
381+
If a dict is provided, it must be of the same form as the protobuf
382+
message :class:`~google.cloud.automl_v1.types.BatchPredictOutputConfig`
383+
params (dict[str -> str]): Additional domain-specific parameters for the predictions, any string
384+
must be up to 25000 characters long.
385+
386+
- For Text Classification:
387+
388+
``score_threshold`` - (float) A value from 0.0 to 1.0. When the model
389+
makes predictions for a text snippet, it will only produce results
390+
that have at least this confidence score. The default is 0.5.
391+
392+
- For Image Classification:
393+
394+
``score_threshold`` - (float) A value from 0.0 to 1.0. When the model
395+
makes predictions for an image, it will only produce results that
396+
have at least this confidence score. The default is 0.5.
397+
398+
- For Image Object Detection:
399+
400+
``score_threshold`` - (float) When Model detects objects on the
401+
image, it will only produce bounding boxes which have at least this
402+
confidence score. Value in 0 to 1 range, default is 0.5.
403+
``max_bounding_box_count`` - (int64) No more than this number of
404+
bounding boxes will be produced per image. Default is 100, the
405+
requested value may be limited by server.
406+
retry (Optional[google.api_core.retry.Retry]): A retry object used
407+
to retry requests. If ``None`` is specified, requests will
408+
be retried using a default configuration.
409+
timeout (Optional[float]): The amount of time, in seconds, to wait
410+
for the request to complete. Note that if ``retry`` is
411+
specified, the timeout applies to each individual attempt.
412+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
413+
that is provided to the method.
414+
415+
Returns:
416+
A :class:`~google.cloud.automl_v1.types._OperationFuture` instance.
417+
418+
Raises:
419+
google.api_core.exceptions.GoogleAPICallError: If the request
420+
failed for any reason.
421+
google.api_core.exceptions.RetryError: If the request failed due
422+
to a retryable error and retry attempts failed.
423+
ValueError: If the parameters are invalid.
424+
"""
425+
# Wrap the transport method to add retry and timeout logic.
426+
if "batch_predict" not in self._inner_api_calls:
427+
self._inner_api_calls[
428+
"batch_predict"
429+
] = google.api_core.gapic_v1.method.wrap_method(
430+
self.transport.batch_predict,
431+
default_retry=self._method_configs["BatchPredict"].retry,
432+
default_timeout=self._method_configs["BatchPredict"].timeout,
433+
client_info=self._client_info,
434+
)
435+
436+
request = prediction_service_pb2.BatchPredictRequest(
437+
name=name,
438+
input_config=input_config,
439+
output_config=output_config,
440+
params=params,
441+
)
442+
if metadata is None:
443+
metadata = []
444+
metadata = list(metadata)
445+
try:
446+
routing_header = [("name", name)]
447+
except AttributeError:
448+
pass
449+
else:
450+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
451+
routing_header
452+
)
453+
metadata.append(routing_metadata)
454+
455+
operation = self._inner_api_calls["batch_predict"](
456+
request, retry=retry, timeout=timeout, metadata=metadata
457+
)
458+
return google.api_core.operation.from_gapic(
459+
operation,
460+
self.transport._operations_client,
461+
prediction_service_pb2.BatchPredictResult,
462+
metadata_type=proto_operations_pb2.OperationMetadata,
463+
)

automl/google/cloud/automl_v1/gapic/prediction_service_client_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
"timeout_millis": 60000,
2222
"retry_codes_name": "non_idempotent",
2323
"retry_params_name": "default",
24-
}
24+
},
25+
"BatchPredict": {
26+
"timeout_millis": 20000,
27+
"retry_codes_name": "non_idempotent",
28+
"retry_params_name": "default",
29+
},
2530
},
2631
}
2732
}

0 commit comments

Comments
 (0)