Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a138a4f

Browse files
authored
Update google cloud vision >= 2.0.0 (#23755)
Co-authored-by: Anand Inguva <[email protected]>
1 parent 3d055da commit a138a4f

8 files changed

Lines changed: 51 additions & 40 deletions

File tree

sdks/python/apache_beam/ml/gcp/visionml.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
metadata=None):
8181
"""
8282
Args:
83-
features: (List[``vision.types.Feature.enums.Feature``]) Required.
83+
features: (List[``vision.Feature``]) Required.
8484
The Vision API features to detect
8585
retry: (google.api_core.retry.Retry) Optional.
8686
A retry object used to retry requests.
@@ -107,9 +107,9 @@ def __init__(
107107
108108
image_contexts =
109109
[(''gs://cloud-samples-data/vision/ocr/sign.jpg'', Union[dict,
110-
``vision.types.ImageContext()``]),
110+
``vision.ImageContext()``]),
111111
(''gs://cloud-samples-data/vision/ocr/sign.jpg'', Union[dict,
112-
``vision.types.ImageContext()``]),]
112+
``vision.ImageContext()``]),]
113113
114114
context_side_input =
115115
(
@@ -152,23 +152,27 @@ def expand(self, pvalue):
152152
client_options=self.client_options,
153153
metadata=self.metadata)))
154154

155-
@typehints.with_input_types(
156-
Union[str, bytes], Optional[vision.types.ImageContext])
157-
@typehints.with_output_types(List[vision.types.AnnotateImageRequest])
155+
@typehints.with_input_types(Union[str, bytes], Optional[vision.ImageContext])
156+
@typehints.with_output_types(List[vision.AnnotateImageRequest])
158157
def _create_image_annotation_pairs(self, element, context_side_input):
159158
if context_side_input: # If we have a side input image context, use that
160159
image_context = context_side_input.get(element)
161160
else:
162161
image_context = None
163162

164163
if isinstance(element, str):
165-
image = vision.types.Image(
166-
source=vision.types.ImageSource(image_uri=element))
164+
165+
image = vision.Image(
166+
{'source': vision.ImageSource({'image_uri': element})})
167+
167168
else: # Typehint checks only allows str or bytes
168-
image = vision.types.Image(content=element)
169+
image = vision.Image(content=element)
169170

170-
request = vision.types.AnnotateImageRequest(
171-
image=image, features=self.features, image_context=image_context)
171+
request = vision.AnnotateImageRequest({
172+
'image': image,
173+
'features': self.features,
174+
'image_context': image_context
175+
})
172176
yield request
173177

174178

@@ -181,7 +185,7 @@ class AnnotateImageWithContext(AnnotateImage):
181185
Element is a tuple of::
182186
183187
(Union[str, bytes],
184-
Optional[``vision.types.ImageContext``])
188+
Optional[``vision.ImageContext``])
185189
186190
where the former is either an URI (e.g. a GCS URI) or bytes
187191
base64-encoded image data.
@@ -197,7 +201,7 @@ def __init__(
197201
metadata=None):
198202
"""
199203
Args:
200-
features: (List[``vision.types.Feature.enums.Feature``]) Required.
204+
features: (List[``vision.Feature``]) Required.
201205
The Vision API features to detect
202206
retry: (google.api_core.retry.Retry) Optional.
203207
A retry object used to retry requests.
@@ -244,25 +248,28 @@ def expand(self, pvalue):
244248
metadata=self.metadata)))
245249

246250
@typehints.with_input_types(
247-
Tuple[Union[str, bytes], Optional[vision.types.ImageContext]])
248-
@typehints.with_output_types(List[vision.types.AnnotateImageRequest])
251+
Tuple[Union[str, bytes], Optional[vision.ImageContext]])
252+
@typehints.with_output_types(List[vision.AnnotateImageRequest])
249253
def _create_image_annotation_pairs(self, element, **kwargs):
250254
element, image_context = element # Unpack (image, image_context) tuple
251255
if isinstance(element, str):
252-
image = vision.types.Image(
253-
source=vision.types.ImageSource(image_uri=element))
256+
image = vision.Image(
257+
{'source': vision.ImageSource({'image_uri': element})})
254258
else: # Typehint checks only allows str or bytes
255-
image = vision.types.Image(content=element)
259+
image = vision.Image({"content": element})
256260

257-
request = vision.types.AnnotateImageRequest(
258-
image=image, features=self.features, image_context=image_context)
261+
request = vision.AnnotateImageRequest({
262+
'image': image,
263+
'features': self.features,
264+
'image_context': image_context
265+
})
259266
yield request
260267

261268

262-
@typehints.with_input_types(List[vision.types.AnnotateImageRequest])
269+
@typehints.with_input_types(List[vision.AnnotateImageRequest])
263270
class _ImageAnnotateFn(DoFn):
264271
"""A DoFn that sends each input element to the GCP Vision API.
265-
Returns ``google.cloud.vision.types.BatchAnnotateImagesResponse``.
272+
Returns ``google.cloud.vision.BatchAnnotateImagesResponse``.
266273
"""
267274
def __init__(self, features, retry, timeout, client_options, metadata):
268275
super().__init__()

sdks/python/apache_beam/ml/gcp/visionml_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def setUp(self):
4545
self._mock_client = mock.Mock()
4646
self._mock_client.batch_annotate_images.return_value = None
4747

48-
feature_type = vision.enums.Feature.Type.TEXT_DETECTION
48+
feature_type = vision.Feature.Type.TEXT_DETECTION
4949
self.features = [
50-
vision.types.Feature(
51-
type=feature_type, max_results=3, model="builtin/stable")
50+
vision.Feature({
51+
'type': feature_type, 'max_results': 3, 'model': "builtin/stable"
52+
})
5253
]
53-
self.img_ctx = vision.types.ImageContext()
54+
self.img_ctx = vision.ImageContext()
5455
self.min_batch_size = 1
5556
self.max_batch_size = 1
5657

sdks/python/apache_beam/ml/gcp/visionml_test_it.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def test_text_detection_with_language_hint(self):
4747
IMAGES_TO_ANNOTATE = [
4848
'gs://apache-beam-samples/advanced_analytics/vision/sign.jpg'
4949
]
50-
IMAGE_CONTEXT = [vision.types.ImageContext(language_hints=['en'])]
50+
51+
IMAGE_CONTEXT = [vision.ImageContext({'language_hints': ['en']})]
5152

5253
with TestPipeline(is_integration_test=True) as p:
5354
contexts = p | 'Create context' >> beam.Create(
@@ -57,7 +58,9 @@ def test_text_detection_with_language_hint(self):
5758
p
5859
| beam.Create(IMAGES_TO_ANNOTATE)
5960
| AnnotateImage(
60-
features=[vision.types.Feature(type='TEXT_DETECTION')],
61+
features=[
62+
vision.Feature({'type_': vision.Feature.Type.TEXT_DETECTION})
63+
],
6164
context_side_input=beam.pvalue.AsDict(contexts))
6265
| beam.ParDo(extract))
6366

sdks/python/container/py310/base_image_requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ google-cloud-pubsublite==1.5.0
6666
google-cloud-recommendations-ai==0.7.1
6767
google-cloud-spanner==3.22.2
6868
google-cloud-videointelligence==1.16.3
69-
google-cloud-vision==1.0.2
69+
google-cloud-vision==3.1.4
7070
google-crc32c==1.5.0
7171
google-pasta==0.2.0
7272
google-resumable-media==2.4.0
@@ -102,7 +102,7 @@ overrides==6.5.0
102102
packaging==21.3
103103
pandas==1.4.4
104104
parameterized==0.8.1
105-
pbr==5.10.0
105+
pbr==5.11.0
106106
pluggy==1.0.0
107107
proto-plus==1.22.1
108108
protobuf==3.19.6
@@ -131,7 +131,7 @@ requests-mock==1.10.0
131131
requests-oauthlib==1.3.1
132132
rsa==4.9
133133
scikit-learn==1.1.2
134-
scipy==1.9.2
134+
scipy==1.9.3
135135
six==1.16.0
136136
sortedcontainers==2.4.0
137137
soupsieve==2.3.2.post1

sdks/python/container/py37/base_image_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
7070
google-cloud-spanner==3.22.2
7171
google-cloud-storage==2.5.0
7272
google-cloud-videointelligence==1.16.3
73-
google-cloud-vision==1.0.2
73+
google-cloud-vision==3.1.4
7474
google-crc32c==1.5.0
7575
google-pasta==0.2.0
7676
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
109109
packaging==21.3
110110
pandas==1.3.5
111111
parameterized==0.8.1
112-
pbr==5.10.0
112+
pbr==5.11.0
113113
pluggy==1.0.0
114114
proto-plus==1.22.1
115115
protobuf==3.19.6

sdks/python/container/py38/base_image_requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
7070
google-cloud-spanner==3.22.2
7171
google-cloud-storage==2.5.0
7272
google-cloud-videointelligence==1.16.3
73-
google-cloud-vision==1.0.2
73+
google-cloud-vision==3.1.4
7474
google-crc32c==1.5.0
7575
google-pasta==0.2.0
7676
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
109109
packaging==21.3
110110
pandas==1.4.4
111111
parameterized==0.8.1
112-
pbr==5.10.0
112+
pbr==5.11.0
113113
pluggy==1.0.0
114114
proto-plus==1.22.1
115115
protobuf==3.19.6
@@ -138,7 +138,7 @@ requests-mock==1.10.0
138138
requests-oauthlib==1.3.1
139139
rsa==4.9
140140
scikit-learn==1.1.2
141-
scipy==1.9.2
141+
scipy==1.9.3
142142
six==1.16.0
143143
sortedcontainers==2.4.0
144144
soupsieve==2.3.2.post1

sdks/python/container/py39/base_image_requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ google-cloud-recommendations-ai==0.7.1
7070
google-cloud-spanner==3.22.2
7171
google-cloud-storage==2.5.0
7272
google-cloud-videointelligence==1.16.3
73-
google-cloud-vision==1.0.2
73+
google-cloud-vision==3.1.4
7474
google-crc32c==1.5.0
7575
google-pasta==0.2.0
7676
google-python-cloud-debugger==3.1
@@ -109,7 +109,7 @@ overrides==6.5.0
109109
packaging==21.3
110110
pandas==1.4.4
111111
parameterized==0.8.1
112-
pbr==5.10.0
112+
pbr==5.11.0
113113
pluggy==1.0.0
114114
proto-plus==1.22.1
115115
protobuf==3.19.6
@@ -138,7 +138,7 @@ requests-mock==1.10.0
138138
requests-oauthlib==1.3.1
139139
rsa==4.9
140140
scikit-learn==1.1.2
141-
scipy==1.9.2
141+
scipy==1.9.3
142142
six==1.16.0
143143
sortedcontainers==2.4.0
144144
soupsieve==2.3.2.post1

sdks/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def get_portability_package_data():
314314
'google-cloud-dlp>=3.0.0,<4',
315315
'google-cloud-language>=1.3.0,<2',
316316
'google-cloud-videointelligence>=1.8.0,<2',
317-
'google-cloud-vision>=0.38.0,<2',
317+
'google-cloud-vision>=2,<4',
318318
'google-cloud-recommendations-ai>=0.1.0,<0.8.0'
319319
],
320320
'interactive': [

0 commit comments

Comments
 (0)