Skip to content

Commit 4751664

Browse files
committed
chore(VR): Apply manual changes
1 parent 5de0fdc commit 4751664

File tree

2 files changed

+101
-99
lines changed

2 files changed

+101
-99
lines changed

watson_developer_cloud/visual_recognition_v3.py

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -88,105 +88,6 @@ def __init__(
8888
use_vcap_services=True)
8989
self.version = version
9090

91-
#########################
92-
# General
93-
#########################
94-
95-
def classify(self,
96-
images_file=None,
97-
accept_language=None,
98-
url=None,
99-
threshold=None,
100-
owners=None,
101-
classifier_ids=None,
102-
images_file_content_type=None,
103-
images_filename=None,
104-
**kwargs):
105-
"""
106-
Classify images.
107-
108-
Classify images with built-in or custom classifiers.
109-
110-
:param file images_file: An image file (.jpg, .png) or .zip file with images.
111-
Maximum image size is 10 MB. Include no more than 20 images and limit the .zip
112-
file to 100 MB. Encode the image and .zip file names in UTF-8 if they contain
113-
non-ASCII characters. The service assumes UTF-8 encoding if it encounters
114-
non-ASCII characters.
115-
You can also include an image with the **url** parameter.
116-
:param str accept_language: The language of the output class names. The full set
117-
of languages is supported for the built-in classifier IDs: `default`, `food`, and
118-
`explicit`. The class names of custom classifiers are not translated.
119-
The response might not be in the specified language when the requested language is
120-
not supported or when there is no translation for the class name.
121-
:param str url: The URL of an image to analyze. Must be in .jpg, or .png format.
122-
The minimum recommended pixel density is 32X32 pixels per inch, and the maximum
123-
image size is 10 MB.
124-
You can also include images with the **images_file** parameter.
125-
:param float threshold: The minimum score a class must have to be displayed in the
126-
response. Set the threshold to `0.0` to ignore the classification score and return
127-
all values.
128-
:param list[str] owners: The categories of classifiers to apply. Use `IBM` to
129-
classify against the `default` general classifier, and use `me` to classify
130-
against your custom classifiers. To analyze the image against both classifier
131-
categories, set the value to both `IBM` and `me`.
132-
The built-in `default` classifier is used if both **classifier_ids** and
133-
**owners** parameters are empty.
134-
The **classifier_ids** parameter overrides **owners**, so make sure that
135-
**classifier_ids** is empty.
136-
:param list[str] classifier_ids: Which classifiers to apply. Overrides the
137-
**owners** parameter. You can specify both custom and built-in classifier IDs. The
138-
built-in `default` classifier is used if both **classifier_ids** and **owners**
139-
parameters are empty.
140-
The following built-in classifier IDs require no training:
141-
- `default`: Returns classes from thousands of general tags.
142-
- `food`: Enhances specificity and accuracy for images of food items.
143-
- `explicit`: Evaluates whether the image might be pornographic.
144-
:param str images_file_content_type: The content type of images_file.
145-
:param str images_filename: The filename for images_file.
146-
:param dict headers: A `dict` containing the request headers
147-
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
148-
:rtype: DetailedResponse
149-
"""
150-
headers = {'Accept-Language': accept_language}
151-
if 'headers' in kwargs:
152-
headers.update(kwargs.get('headers'))
153-
params = {'version': self.version}
154-
images_file_tuple = None
155-
if images_file:
156-
if not images_filename and hasattr(images_file, 'name'):
157-
images_filename = images_file.name
158-
mime_type = images_file_content_type or 'application/octet-stream'
159-
images_file_tuple = (images_filename, images_file, mime_type)
160-
url_tuple = None
161-
if url:
162-
url_tuple = (None, url, 'text/plain')
163-
threshold_tuple = None
164-
if threshold:
165-
threshold_tuple = (None, threshold, 'application/json')
166-
owners_tuple = None
167-
if owners:
168-
owners = self._convert_list(owners)
169-
owners_tuple = (None, owners, 'application/json')
170-
classifier_ids_tuple = None
171-
if classifier_ids:
172-
classifier_ids = self._convert_list(classifier_ids)
173-
classifier_ids_tuple = (None, classifier_ids, 'application/json')
174-
url = '/v3/classify'
175-
response = self.request(
176-
method='POST',
177-
url=url,
178-
headers=headers,
179-
params=params,
180-
files={
181-
'images_file': images_file_tuple,
182-
'url': url_tuple,
183-
'threshold': threshold_tuple,
184-
'owners': owners_tuple,
185-
'classifier_ids': classifier_ids_tuple
186-
},
187-
accept_json=True)
188-
return response
189-
19091
#########################
19192
# Face
19293
#########################

watson_developer_cloud/visual_recognition_v3_adapter.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .visual_recognition_v3 import VisualRecognitionV3
2+
from os.path import basename
23

34
class VisualRecognitionV3Adapter(VisualRecognitionV3):
45
def create_classifier(self,
@@ -59,3 +60,103 @@ def update_classifier(self,
5960
files=kwargs,
6061
accept_json=True)
6162
return response
63+
64+
#########################
65+
# General
66+
#########################
67+
68+
def classify(self,
69+
images_file=None,
70+
accept_language=None,
71+
url=None,
72+
threshold=None,
73+
owners=None,
74+
classifier_ids=None,
75+
images_file_content_type=None,
76+
images_filename=None,
77+
**kwargs):
78+
"""
79+
Classify images.
80+
81+
Classify images with built-in or custom classifiers.
82+
83+
:param file images_file: An image file (.jpg, .png) or .zip file with images.
84+
Maximum image size is 10 MB. Include no more than 20 images and limit the .zip
85+
file to 100 MB. Encode the image and .zip file names in UTF-8 if they contain
86+
non-ASCII characters. The service assumes UTF-8 encoding if it encounters
87+
non-ASCII characters.
88+
You can also include an image with the **url** parameter.
89+
:param str accept_language: The language of the output class names. The full set
90+
of languages is supported for the built-in classifier IDs: `default`, `food`, and
91+
`explicit`. The class names of custom classifiers are not translated.
92+
The response might not be in the specified language when the requested language is
93+
not supported or when there is no translation for the class name.
94+
:param str url: The URL of an image to analyze. Must be in .jpg, or .png format.
95+
The minimum recommended pixel density is 32X32 pixels per inch, and the maximum
96+
image size is 10 MB.
97+
You can also include images with the **images_file** parameter.
98+
:param float threshold: The minimum score a class must have to be displayed in the
99+
response. Set the threshold to `0.0` to ignore the classification score and return
100+
all values.
101+
:param list[str] owners: The categories of classifiers to apply. Use `IBM` to
102+
classify against the `default` general classifier, and use `me` to classify
103+
against your custom classifiers. To analyze the image against both classifier
104+
categories, set the value to both `IBM` and `me`.
105+
The built-in `default` classifier is used if both **classifier_ids** and
106+
**owners** parameters are empty.
107+
The **classifier_ids** parameter overrides **owners**, so make sure that
108+
**classifier_ids** is empty.
109+
:param list[str] classifier_ids: Which classifiers to apply. Overrides the
110+
**owners** parameter. You can specify both custom and built-in classifier IDs. The
111+
built-in `default` classifier is used if both **classifier_ids** and **owners**
112+
parameters are empty.
113+
The following built-in classifier IDs require no training:
114+
- `default`: Returns classes from thousands of general tags.
115+
- `food`: Enhances specificity and accuracy for images of food items.
116+
- `explicit`: Evaluates whether the image might be pornographic.
117+
:param str images_file_content_type: The content type of images_file.
118+
:param str images_filename: The filename for images_file.
119+
:param dict headers: A `dict` containing the request headers
120+
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
121+
:rtype: DetailedResponse
122+
"""
123+
headers = {'Accept-Language': accept_language}
124+
if 'headers' in kwargs:
125+
headers.update(kwargs.get('headers'))
126+
params = {'version': self.version}
127+
images_file_tuple = None
128+
if images_file:
129+
if not images_filename and hasattr(images_file, 'name'):
130+
images_filename = images_file.name
131+
images_filename = basename(images_filename)
132+
mime_type = images_file_content_type or 'application/octet-stream'
133+
images_file_tuple = (images_filename, images_file, mime_type)
134+
url_tuple = None
135+
if url:
136+
url_tuple = (None, url, 'text/plain')
137+
threshold_tuple = None
138+
if threshold:
139+
threshold_tuple = (None, threshold, 'application/json')
140+
owners_tuple = None
141+
if owners:
142+
owners = self._convert_list(owners)
143+
owners_tuple = (None, owners, 'application/json')
144+
classifier_ids_tuple = None
145+
if classifier_ids:
146+
classifier_ids = self._convert_list(classifier_ids)
147+
classifier_ids_tuple = (None, classifier_ids, 'application/json')
148+
url = '/v3/classify'
149+
response = self.request(
150+
method='POST',
151+
url=url,
152+
headers=headers,
153+
params=params,
154+
files={
155+
'images_file': images_file_tuple,
156+
'url': url_tuple,
157+
'threshold': threshold_tuple,
158+
'owners': owners_tuple,
159+
'classifier_ids': classifier_ids_tuple
160+
},
161+
accept_json=True)
162+
return response

0 commit comments

Comments
 (0)