Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regenerate vision gapics #5467

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions vision/google/cloud/vision_v1/gapic/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
# limitations under the License.
"""Wrappers for protocol buffer enum types."""

import enum

class Likelihood(object):

class Likelihood(enum.IntEnum):
"""
A bucketized representation of likelihood, which is intended to give clients
highly stable results across model upgrades.
Expand All @@ -37,7 +39,7 @@ class Likelihood(object):

class TextAnnotation(object):
class DetectedBreak(object):
class BreakType(object):
class BreakType(enum.IntEnum):
"""
Enum to denote the type of break found. New line, space etc.
Expand All @@ -59,7 +61,7 @@ class BreakType(object):


class Block(object):
class BlockType(object):
class BlockType(enum.IntEnum):
"""
Type of a block (text, image etc) as identified by OCR.
Expand All @@ -80,7 +82,7 @@ class BlockType(object):


class Feature(object):
class Type(object):
class Type(enum.IntEnum):
"""
Type of Google Cloud Vision API feature to be extracted.
Expand Down Expand Up @@ -117,7 +119,7 @@ class Type(object):

class FaceAnnotation(object):
class Landmark(object):
class Type(object):
class Type(enum.IntEnum):
"""
Face landmark (feature) type.
Left and right are defined from the vantage of the viewer of the image
Expand Down Expand Up @@ -196,3 +198,22 @@ class Type(object):
CHIN_GNATHION = 32
CHIN_LEFT_GONION = 33
CHIN_RIGHT_GONION = 34


class OperationMetadata(object):
class State(enum.IntEnum):
"""
Batch operation states.
Attributes:
STATE_UNSPECIFIED (int): Invalid.
CREATED (int): Request is received.
RUNNING (int): Request is actively being processed.
DONE (int): The batch processing is done.
CANCELLED (int): The batch processing was cancelled.
"""
STATE_UNSPECIFIED = 0
CREATED = 1
RUNNING = 2
DONE = 3
CANCELLED = 4
151 changes: 132 additions & 19 deletions vision/google/cloud/vision_v1/gapic/image_annotator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
import google.api_core.grpc_helpers
import google.api_core.operation
import google.api_core.operations_v1
import grpc

from google.cloud.vision_v1.gapic import enums
from google.cloud.vision_v1.gapic import image_annotator_client_config
from google.cloud.vision_v1.proto import image_annotator_pb2
from google.cloud.vision_v1.proto import image_annotator_pb2_grpc
from google.longrunning import operations_pb2

_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
'google-cloud-vision', ).version
Expand Down Expand Up @@ -81,39 +86,60 @@ def __init__(self,
'exclusive.'.format(self.__class__.__name__), )

# Create the channel.
if channel is None:
channel = google.api_core.grpc_helpers.create_channel(
self.channel = channel
if self.channel is None:
self.channel = google.api_core.grpc_helpers.create_channel(
self.SERVICE_ADDRESS,
credentials=credentials,
scopes=self._DEFAULT_SCOPES,
)

# Create the gRPC stubs.
self.image_annotator_stub = (
image_annotator_pb2.ImageAnnotatorStub(channel))
self._image_annotator_stub = (
image_annotator_pb2_grpc.ImageAnnotatorStub(self.channel))

# Operations client for methods that return long-running operations
# futures.
self._operations_client = (
google.api_core.operations_v1.OperationsClient(self.channel))

if client_info is None:
client_info = (
google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO)
client_info.gapic_version = _GAPIC_LIBRARY_VERSION
self._client_info = client_info

# Parse out the default settings for retry and timeout for each RPC
# from the client configuration.
# (Ordinarily, these are the defaults specified in the `*_config.py`
# file next to this one.)
method_configs = google.api_core.gapic_v1.config.parse_method_configs(
self._method_configs = google.api_core.gapic_v1.config.parse_method_configs(
client_config['interfaces'][self._INTERFACE_NAME], )

# Write the "inner API call" methods to the class.
# These are wrapped versions of the gRPC stub methods, with retry and
# timeout configuration applied, called by the public methods on
# this class.
self._batch_annotate_images = google.api_core.gapic_v1.method.wrap_method(
self.image_annotator_stub.BatchAnnotateImages,
default_retry=method_configs['BatchAnnotateImages'].retry,
default_timeout=method_configs['BatchAnnotateImages'].timeout,
client_info=client_info,
)
self._inner_api_calls = {}

def _intercept_channel(self, *interceptors):
""" Experimental. Bind gRPC interceptors to the gRPC channel.
Args:
interceptors (*Union[grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamingClientInterceptor, grpc.StreamingUnaryClientInterceptor, grpc.StreamingStreamingClientInterceptor]):
Zero or more gRPC interceptors. Interceptors are given control in the order
they are listed.
Raises:
TypeError: If interceptor does not derive from any of
UnaryUnaryClientInterceptor,
UnaryStreamClientInterceptor,
StreamUnaryClientInterceptor, or
StreamStreamClientInterceptor.
"""
self.channel = grpc.intercept_channel(self.channel, *interceptors)
self._image_annotator_stub = (
image_annotator_pb2_grpc.ImageAnnotatorStub(self.channel))
# Operations client for methods that return long-running operations
# futures.
self._operations_client = (
google.api_core.operations_v1.OperationsClient(self.channel))
self._inner_api_calls.clear()

# Service calls
def batch_annotate_images(self,
Expand All @@ -129,6 +155,7 @@ def batch_annotate_images(self,
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize ``requests``:
>>> requests = []
>>>
>>> response = client.batch_annotate_images(requests)
Expand Down Expand Up @@ -156,10 +183,96 @@ def batch_annotate_images(self,
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
if metadata is None:
metadata = []
metadata = list(metadata)
if 'batch_annotate_images' not in self._inner_api_calls:
self._inner_api_calls[
'batch_annotate_images'] = google.api_core.gapic_v1.method.wrap_method(
self._image_annotator_stub.BatchAnnotateImages,
default_retry=self._method_configs[
'BatchAnnotateImages'].retry,
default_timeout=self._method_configs['BatchAnnotateImages']
.timeout,
client_info=self._client_info,
)

request = image_annotator_pb2.BatchAnnotateImagesRequest(
requests=requests, )
return self._batch_annotate_images(
return self._inner_api_calls['batch_annotate_images'](
request, retry=retry, timeout=timeout, metadata=metadata)

def async_batch_annotate_files(
self,
requests,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None):
"""
Run asynchronous image detection and annotation for a list of generic
files, such as PDF files, which may contain multiple pages and multiple
images per page. Progress and results can be retrieved through the
``google.longrunning.Operations`` interface.
``Operation.metadata`` contains ``OperationMetadata`` (metadata).
``Operation.response`` contains ``AsyncBatchAnnotateFilesResponse`` (results).
Example:
>>> from google.cloud import vision_v1
>>>
>>> client = vision_v1.ImageAnnotatorClient()
>>>
>>> # TODO: Initialize ``requests``:
>>> requests = []
>>>
>>> response = client.async_batch_annotate_files(requests)
>>>
>>> def callback(operation_future):
... # Handle result.
... result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Args:
requests (list[Union[dict, ~google.cloud.vision_v1.types.AsyncAnnotateFileRequest]]): Individual async file annotation requests for this batch.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.vision_v1.types.AsyncAnnotateFileRequest`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.vision_v1.types._OperationFuture` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
if 'async_batch_annotate_files' not in self._inner_api_calls:
self._inner_api_calls[
'async_batch_annotate_files'] = google.api_core.gapic_v1.method.wrap_method(
self._image_annotator_stub.AsyncBatchAnnotateFiles,
default_retry=self._method_configs[
'AsyncBatchAnnotateFiles'].retry,
default_timeout=self._method_configs[
'AsyncBatchAnnotateFiles'].timeout,
client_info=self._client_info,
)

request = image_annotator_pb2.AsyncBatchAnnotateFilesRequest(
requests=requests, )
operation = self._inner_api_calls['async_batch_annotate_files'](
request, retry=retry, timeout=timeout, metadata=metadata)
return google.api_core.operation.from_gapic(
operation,
self._operations_client,
image_annotator_pb2.AsyncBatchAnnotateFilesResponse,
metadata_type=image_annotator_pb2.OperationMetadata,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
},
"AsyncBatchAnnotateFiles": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
}
}
}
Expand Down
Loading