17
17
from . import models
18
18
19
19
20
- class PredictionEndpointConfiguration (Configuration ):
21
- """Configuration for PredictionEndpoint
20
+ class CustomVisionPredictionClientConfiguration (Configuration ):
21
+ """Configuration for CustomVisionPredictionClient
22
22
Note that all parameters used to create this instance are saved as instance
23
23
attributes.
24
24
25
25
:param api_key:
26
26
:type api_key: str
27
- :param str base_url: Service URL
27
+ :param endpoint: Supported Cognitive Services endpoints
28
+ :type endpoint: str
28
29
"""
29
30
30
31
def __init__ (
31
- self , api_key , base_url = None ):
32
+ self , api_key , endpoint ):
32
33
33
34
if api_key is None :
34
35
raise ValueError ("Parameter 'api_key' must not be None." )
35
- if not base_url :
36
- base_url = 'https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction'
36
+ if endpoint is None :
37
+ raise ValueError ("Parameter 'endpoint' must not be None." )
38
+ base_url = '{Endpoint}/customvision/v2.0/Prediction'
37
39
38
- super (PredictionEndpointConfiguration , self ).__init__ (base_url )
40
+ super (CustomVisionPredictionClientConfiguration , self ).__init__ (base_url )
39
41
40
42
self .add_user_agent ('azure-cognitiveservices-vision-customvision/{}' .format (VERSION ))
41
43
42
44
self .api_key = api_key
45
+ self .endpoint = endpoint
43
46
44
47
45
- class PredictionEndpoint (SDKClient ):
46
- """PredictionEndpoint
48
+ class CustomVisionPredictionClient (SDKClient ):
49
+ """CustomVisionPredictionClient
47
50
48
51
:ivar config: Configuration for client.
49
- :vartype config: PredictionEndpointConfiguration
52
+ :vartype config: CustomVisionPredictionClientConfiguration
50
53
51
54
:param api_key:
52
55
:type api_key: str
53
- :param str base_url: Service URL
56
+ :param endpoint: Supported Cognitive Services endpoints
57
+ :type endpoint: str
54
58
"""
55
59
56
60
def __init__ (
57
- self , api_key , base_url = None ):
61
+ self , api_key , endpoint ):
58
62
59
- self .config = PredictionEndpointConfiguration (api_key , base_url )
60
- super (PredictionEndpoint , self ).__init__ (None , self .config )
63
+ self .config = CustomVisionPredictionClientConfiguration (api_key , endpoint )
64
+ super (CustomVisionPredictionClient , self ).__init__ (None , self .config )
61
65
62
66
client_models = {k : v for k , v in models .__dict__ .items () if isinstance (v , type )}
63
67
self .api_version = '2.0'
@@ -97,6 +101,7 @@ def predict_image_url(
97
101
# Construct URL
98
102
url = self .predict_image_url .metadata ['url' ]
99
103
path_format_arguments = {
104
+ 'Endpoint' : self ._serialize .url ("self.config.endpoint" , self .config .endpoint , 'str' , skip_quote = True ),
100
105
'projectId' : self ._serialize .url ("project_id" , project_id , 'str' )
101
106
}
102
107
url = self ._client .format_url (url , ** path_format_arguments )
@@ -110,6 +115,7 @@ def predict_image_url(
110
115
111
116
# Construct headers
112
117
header_parameters = {}
118
+ header_parameters ['Accept' ] = 'application/json'
113
119
header_parameters ['Content-Type' ] = 'application/json; charset=utf-8'
114
120
if custom_headers :
115
121
header_parameters .update (custom_headers )
@@ -119,9 +125,8 @@ def predict_image_url(
119
125
body_content = self ._serialize .body (image_url , 'ImageUrl' )
120
126
121
127
# Construct and send request
122
- request = self ._client .post (url , query_parameters )
123
- response = self ._client .send (
124
- request , header_parameters , body_content , stream = False , ** operation_config )
128
+ request = self ._client .post (url , query_parameters , header_parameters , body_content )
129
+ response = self ._client .send (request , stream = False , ** operation_config )
125
130
126
131
if response .status_code not in [200 ]:
127
132
raise HttpOperationError (self ._deserialize , response )
@@ -168,6 +173,7 @@ def predict_image(
168
173
# Construct URL
169
174
url = self .predict_image .metadata ['url' ]
170
175
path_format_arguments = {
176
+ 'Endpoint' : self ._serialize .url ("self.config.endpoint" , self .config .endpoint , 'str' , skip_quote = True ),
171
177
'projectId' : self ._serialize .url ("project_id" , project_id , 'str' )
172
178
}
173
179
url = self ._client .format_url (url , ** path_format_arguments )
@@ -181,6 +187,7 @@ def predict_image(
181
187
182
188
# Construct headers
183
189
header_parameters = {}
190
+ header_parameters ['Accept' ] = 'application/json'
184
191
header_parameters ['Content-Type' ] = 'multipart/form-data'
185
192
if custom_headers :
186
193
header_parameters .update (custom_headers )
@@ -192,9 +199,8 @@ def predict_image(
192
199
}
193
200
194
201
# Construct and send request
195
- request = self ._client .post (url , query_parameters )
196
- response = self ._client .send_formdata (
197
- request , header_parameters , form_data_content , stream = False , ** operation_config )
202
+ request = self ._client .post (url , query_parameters , header_parameters , form_content = form_data_content )
203
+ response = self ._client .send (request , stream = False , ** operation_config )
198
204
199
205
if response .status_code not in [200 ]:
200
206
raise HttpOperationError (self ._deserialize , response )
@@ -243,6 +249,7 @@ def predict_image_url_with_no_store(
243
249
# Construct URL
244
250
url = self .predict_image_url_with_no_store .metadata ['url' ]
245
251
path_format_arguments = {
252
+ 'Endpoint' : self ._serialize .url ("self.config.endpoint" , self .config .endpoint , 'str' , skip_quote = True ),
246
253
'projectId' : self ._serialize .url ("project_id" , project_id , 'str' )
247
254
}
248
255
url = self ._client .format_url (url , ** path_format_arguments )
@@ -256,6 +263,7 @@ def predict_image_url_with_no_store(
256
263
257
264
# Construct headers
258
265
header_parameters = {}
266
+ header_parameters ['Accept' ] = 'application/json'
259
267
header_parameters ['Content-Type' ] = 'application/json; charset=utf-8'
260
268
if custom_headers :
261
269
header_parameters .update (custom_headers )
@@ -265,9 +273,8 @@ def predict_image_url_with_no_store(
265
273
body_content = self ._serialize .body (image_url , 'ImageUrl' )
266
274
267
275
# Construct and send request
268
- request = self ._client .post (url , query_parameters )
269
- response = self ._client .send (
270
- request , header_parameters , body_content , stream = False , ** operation_config )
276
+ request = self ._client .post (url , query_parameters , header_parameters , body_content )
277
+ response = self ._client .send (request , stream = False , ** operation_config )
271
278
272
279
if response .status_code not in [200 ]:
273
280
raise HttpOperationError (self ._deserialize , response )
@@ -314,6 +321,7 @@ def predict_image_with_no_store(
314
321
# Construct URL
315
322
url = self .predict_image_with_no_store .metadata ['url' ]
316
323
path_format_arguments = {
324
+ 'Endpoint' : self ._serialize .url ("self.config.endpoint" , self .config .endpoint , 'str' , skip_quote = True ),
317
325
'projectId' : self ._serialize .url ("project_id" , project_id , 'str' )
318
326
}
319
327
url = self ._client .format_url (url , ** path_format_arguments )
@@ -327,6 +335,7 @@ def predict_image_with_no_store(
327
335
328
336
# Construct headers
329
337
header_parameters = {}
338
+ header_parameters ['Accept' ] = 'application/json'
330
339
header_parameters ['Content-Type' ] = 'multipart/form-data'
331
340
if custom_headers :
332
341
header_parameters .update (custom_headers )
@@ -338,9 +347,8 @@ def predict_image_with_no_store(
338
347
}
339
348
340
349
# Construct and send request
341
- request = self ._client .post (url , query_parameters )
342
- response = self ._client .send_formdata (
343
- request , header_parameters , form_data_content , stream = False , ** operation_config )
350
+ request = self ._client .post (url , query_parameters , header_parameters , form_content = form_data_content )
351
+ response = self ._client .send (request , stream = False , ** operation_config )
344
352
345
353
if response .status_code not in [200 ]:
346
354
raise HttpOperationError (self ._deserialize , response )
0 commit comments