clarifai-grpc 6.4.0__py3-none-any.whl → 11.10.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clarifai_grpc/__init__.py +33 -0
- clarifai_grpc/channel/clarifai_channel.py +150 -44
- clarifai_grpc/channel/custom_converters/custom_dict_to_message.py +41 -34
- clarifai_grpc/channel/custom_converters/custom_message_to_dict.py +85 -74
- clarifai_grpc/channel/errors.py +5 -0
- clarifai_grpc/channel/exceptions.py +1 -1
- clarifai_grpc/channel/grpc_json_channel.py +387 -261
- clarifai_grpc/channel/http_client.py +125 -104
- clarifai_grpc/grpc/api/resources_pb2.py +984 -7266
- clarifai_grpc/grpc/api/resources_pb2.pyi +17925 -0
- clarifai_grpc/grpc/api/resources_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/api/service_pb2.py +1578 -8672
- clarifai_grpc/grpc/api/service_pb2.pyi +18269 -0
- clarifai_grpc/grpc/api/service_pb2_grpc.py +9746 -1859
- clarifai_grpc/grpc/api/status/status_code_pb2.py +33 -1334
- clarifai_grpc/grpc/api/status/status_code_pb2.pyi +1210 -0
- clarifai_grpc/grpc/api/status/status_code_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/api/status/status_pb2.py +23 -149
- clarifai_grpc/grpc/api/status/status_pb2.pyi +174 -0
- clarifai_grpc/grpc/api/status/status_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/api/utils/extensions_pb2.py +13 -46
- clarifai_grpc/grpc/api/utils/extensions_pb2.pyi +39 -0
- clarifai_grpc/grpc/api/utils/extensions_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/api/utils/matrix_pb2.py +26 -0
- clarifai_grpc/grpc/api/utils/matrix_pb2.pyi +53 -0
- clarifai_grpc/grpc/api/utils/matrix_pb2_grpc.py +4 -0
- clarifai_grpc/grpc/api/utils/test_proto_pb2.py +17 -158
- clarifai_grpc/grpc/api/utils/test_proto_pb2.pyi +107 -0
- clarifai_grpc/grpc/api/utils/test_proto_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/auth/scope/scope_pb2.py +245 -448
- clarifai_grpc/grpc/auth/scope/scope_pb2.pyi +550 -0
- clarifai_grpc/grpc/auth/scope/scope_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/auth/types/types_pb2.py +11 -62
- clarifai_grpc/grpc/auth/types/types_pb2.pyi +78 -0
- clarifai_grpc/grpc/auth/types/types_pb2_grpc.py +1 -0
- clarifai_grpc/grpc/auth/util/extension_pb2.py +14 -68
- clarifai_grpc/grpc/auth/util/extension_pb2.pyi +68 -0
- clarifai_grpc/grpc/auth/util/extension_pb2_grpc.py +1 -0
- clarifai_grpc-11.10.3.dist-info/METADATA +124 -0
- clarifai_grpc-11.10.3.dist-info/RECORD +53 -0
- {clarifai_grpc-6.4.0.dist-info → clarifai_grpc-11.10.3.dist-info}/WHEEL +1 -1
- {clarifai_grpc-6.4.0.dist-info → clarifai_grpc-11.10.3.dist-info}/top_level.txt +0 -2
- clarifai_grpc-6.4.0.dist-info/METADATA +0 -88
- clarifai_grpc-6.4.0.dist-info/RECORD +0 -46
- scripts/__init__.py +0 -0
- scripts/app_and_key_for_tests.py +0 -180
- tests/__init__.py +0 -0
- tests/helpers.py +0 -105
- tests/test_integration.py +0 -243
- {clarifai_grpc-6.4.0.dist-info → clarifai_grpc-11.10.3.dist-info/licenses}/LICENSE +0 -0
scripts/app_and_key_for_tests.py
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
|
|
5
|
-
try:
|
|
6
|
-
from urllib.parse import urlparse, urlencode
|
|
7
|
-
from urllib.request import urlopen, Request, build_opener, HTTPHandler
|
|
8
|
-
from urllib.error import HTTPError
|
|
9
|
-
except ImportError:
|
|
10
|
-
from urlparse import urlparse
|
|
11
|
-
from urllib import urlencode
|
|
12
|
-
from urllib2 import urlopen, Request, HTTPError, build_opener, HTTPHandler
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
EMAIL = os.environ['CLARIFAI_USER_EMAIL']
|
|
16
|
-
PASSWORD = os.environ['CLARIFAI_USER_PASSWORD']
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
BASE = 'https://api.clarifai.com/v2'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def _request(method, url, payload={}, headers={}):
|
|
23
|
-
opener = build_opener(HTTPHandler)
|
|
24
|
-
full_url = '%s%s' % (BASE, url)
|
|
25
|
-
request = Request(full_url, data=json.dumps(payload).encode())
|
|
26
|
-
for k in headers.keys():
|
|
27
|
-
request.add_header(k, headers[k])
|
|
28
|
-
request.get_method = lambda: method
|
|
29
|
-
return json.loads(opener.open(request).read().decode())
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def create_app(env_name):
|
|
33
|
-
session_token, user_id = _login()
|
|
34
|
-
|
|
35
|
-
url = '/users/%s/apps' % user_id
|
|
36
|
-
payload = {'apps': [{'name': 'auto-created-in-%s-ci-test-run' % env_name}]}
|
|
37
|
-
|
|
38
|
-
response = _request(method='POST', url=url, payload=payload, headers=_auth_headers(session_token))
|
|
39
|
-
|
|
40
|
-
_raise_on_http_error(response)
|
|
41
|
-
data = response
|
|
42
|
-
app_id = data['apps'][0]['id']
|
|
43
|
-
|
|
44
|
-
# This print needs to be present so we can read the value in CI.
|
|
45
|
-
print(app_id)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def create_key(app_id):
|
|
49
|
-
session_token, user_id = _login()
|
|
50
|
-
|
|
51
|
-
url = '/users/%s/keys' % user_id
|
|
52
|
-
payload = {
|
|
53
|
-
'keys': [{
|
|
54
|
-
'description': 'Auto-created in a CI test run',
|
|
55
|
-
'scopes': ['All'],
|
|
56
|
-
'apps': [{'id': app_id, 'user_id': user_id}]
|
|
57
|
-
}]
|
|
58
|
-
}
|
|
59
|
-
response = _request(method='POST', url=url, payload=payload, headers=_auth_headers(session_token))
|
|
60
|
-
_raise_on_http_error(response)
|
|
61
|
-
data = response
|
|
62
|
-
key_id = data['keys'][0]['id']
|
|
63
|
-
|
|
64
|
-
# This print needs to be present so we can read the value in CI.
|
|
65
|
-
print(key_id)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def delete(app_id):
|
|
69
|
-
session_token, user_id = _login()
|
|
70
|
-
|
|
71
|
-
# All the related keys will be deleted automatically when the app is deleted
|
|
72
|
-
_delete_app(session_token, user_id, app_id)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def create_sample_workflow(api_key):
|
|
76
|
-
url = '/workflows'
|
|
77
|
-
payload = {
|
|
78
|
-
'workflows': [
|
|
79
|
-
{
|
|
80
|
-
'id': 'food-and-general',
|
|
81
|
-
'nodes': [
|
|
82
|
-
{
|
|
83
|
-
'id': 'food-workflow-node',
|
|
84
|
-
'model': {
|
|
85
|
-
'id': 'bd367be194cf45149e75f01d59f77ba7',
|
|
86
|
-
'model_version': {
|
|
87
|
-
'id': 'dfebc169854e429086aceb8368662641'
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
'id': 'general-workflow-node',
|
|
93
|
-
'model': {
|
|
94
|
-
'id': 'aaa03c23b3724a16a56b629203edc62c',
|
|
95
|
-
'model_version': {
|
|
96
|
-
'id': 'aa9ca48295b37401f8af92ad1af0d91d'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
response = _request(method='POST', url=url, payload=payload, headers=_auth_headers_for_api_key_key(api_key))
|
|
105
|
-
_raise_on_http_error(response)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def _delete_app(session_token, user_id, app_id):
|
|
109
|
-
url = '/users/%s/apps/%s' % (user_id, app_id)
|
|
110
|
-
response = _request(method='DELETE', url=url, headers=_auth_headers(session_token))
|
|
111
|
-
_raise_on_http_error(response)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
def _auth_headers(session_token):
|
|
115
|
-
headers = {'Content-Type': 'application/json', 'X-Clarifai-Session-Token': session_token}
|
|
116
|
-
return headers
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def _auth_headers_for_api_key_key(api_key):
|
|
120
|
-
headers = {'Content-Type': 'application/json', 'Authorization': 'Key ' + api_key}
|
|
121
|
-
return headers
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def _login():
|
|
125
|
-
url = '/login'
|
|
126
|
-
payload = {'email': EMAIL, 'password': PASSWORD}
|
|
127
|
-
response = _request(method='POST', url=url, payload=payload)
|
|
128
|
-
_raise_on_http_error(response)
|
|
129
|
-
data = response
|
|
130
|
-
user_id = data['v2_user_id']
|
|
131
|
-
session_token = data['session_token']
|
|
132
|
-
return session_token, user_id
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _raise_on_http_error(response):
|
|
136
|
-
# TODO: Make this work with urllib.
|
|
137
|
-
# if int(response.status_code) // 100 != 2:
|
|
138
|
-
# raise Exception('Unexpected response %s: %s' % (response.status_code, response.text))
|
|
139
|
-
pass
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def run(arguments):
|
|
143
|
-
command = arguments[0] if arguments else '--help'
|
|
144
|
-
if command == '--create-app':
|
|
145
|
-
if len(arguments) != 2:
|
|
146
|
-
raise Exception('--create-app takes one argument')
|
|
147
|
-
|
|
148
|
-
env_name = arguments[1]
|
|
149
|
-
create_app(env_name)
|
|
150
|
-
elif command == '--create-key':
|
|
151
|
-
if len(arguments) != 2:
|
|
152
|
-
raise Exception('--create-key takes one argument')
|
|
153
|
-
|
|
154
|
-
app_id = arguments[1]
|
|
155
|
-
create_key(app_id)
|
|
156
|
-
elif command == '--delete-app':
|
|
157
|
-
if len(arguments) != 2:
|
|
158
|
-
raise Exception('--delete-app takes one argument')
|
|
159
|
-
app_id = arguments[1]
|
|
160
|
-
delete(app_id)
|
|
161
|
-
elif command == '--create-workflow':
|
|
162
|
-
if len(arguments) != 2:
|
|
163
|
-
raise Exception('--create-workflow takes one argument')
|
|
164
|
-
api_key = arguments[1]
|
|
165
|
-
create_sample_workflow(api_key)
|
|
166
|
-
elif command == '--help':
|
|
167
|
-
print('''DESCRIPTION: Creates and delete applications and API keys
|
|
168
|
-
ARGUMENTS:
|
|
169
|
-
--create-app [env_name] ... Creates a new application.
|
|
170
|
-
--create-key [app_id] ... Creates a new API key.
|
|
171
|
-
--delete-app [app_id] ... Deletes an application (API keys that use it are deleted as well).
|
|
172
|
-
--create-workflow [api_key] ... Creates a sample workflow to be used in int. tests.
|
|
173
|
-
--help ... This text.''')
|
|
174
|
-
else:
|
|
175
|
-
print('Unknown argument. Please see --help')
|
|
176
|
-
exit(1)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if __name__ == '__main__':
|
|
180
|
-
run(arguments=sys.argv[1:])
|
tests/__init__.py
DELETED
|
File without changes
|
tests/helpers.py
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
|
|
3
|
-
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
|
|
4
|
-
from clarifai_grpc.grpc.api import service_pb2
|
|
5
|
-
from clarifai_grpc.grpc.api.status import status_code_pb2
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def both_channels(func):
|
|
9
|
-
"""
|
|
10
|
-
A decorator that runs the test first using the gRPC channel and then using the JSON channel.
|
|
11
|
-
:param func: The test function.
|
|
12
|
-
:return: A function wrapper.
|
|
13
|
-
"""
|
|
14
|
-
def func_wrapper():
|
|
15
|
-
channel = ClarifaiChannel.get_insecure_grpc_channel()
|
|
16
|
-
func(channel)
|
|
17
|
-
|
|
18
|
-
channel = ClarifaiChannel.get_json_channel()
|
|
19
|
-
func(channel)
|
|
20
|
-
return func_wrapper
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _wait_for_inputs_upload(stub, metadata, input_ids):
|
|
24
|
-
for input_id in input_ids:
|
|
25
|
-
while True:
|
|
26
|
-
get_input_response = stub.GetInput(
|
|
27
|
-
service_pb2.GetInputRequest(input_id=input_id),
|
|
28
|
-
metadata=metadata
|
|
29
|
-
)
|
|
30
|
-
_raise_on_failure(get_input_response)
|
|
31
|
-
if get_input_response.input.status.code == status_code_pb2.INPUT_DOWNLOAD_SUCCESS:
|
|
32
|
-
break
|
|
33
|
-
elif get_input_response.input.status.code in (status_code_pb2.INPUT_DOWNLOAD_PENDING,
|
|
34
|
-
status_code_pb2.INPUT_DOWNLOAD_IN_PROGRESS):
|
|
35
|
-
time.sleep(1)
|
|
36
|
-
else:
|
|
37
|
-
error_message = (
|
|
38
|
-
str(get_input_response.status.code) + " " +
|
|
39
|
-
get_input_response.status.description + " " +
|
|
40
|
-
get_input_response.status.details
|
|
41
|
-
)
|
|
42
|
-
raise Exception(
|
|
43
|
-
f"Expected inputs to upload, but got {error_message}. Full response: {get_input_response}"
|
|
44
|
-
)
|
|
45
|
-
# At this point, all inputs have been downloaded successfully.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _wait_for_model_trained(stub, metadata, model_id, model_version_id):
|
|
49
|
-
while True:
|
|
50
|
-
response = stub.GetModelVersion(
|
|
51
|
-
service_pb2.GetModelVersionRequest(model_id=model_id, version_id=model_version_id),
|
|
52
|
-
metadata=metadata
|
|
53
|
-
)
|
|
54
|
-
_raise_on_failure(response)
|
|
55
|
-
if response.model_version.status.code == status_code_pb2.MODEL_TRAINED:
|
|
56
|
-
break
|
|
57
|
-
elif response.model_version.status.code in (status_code_pb2.MODEL_QUEUED_FOR_TRAINING,
|
|
58
|
-
status_code_pb2.MODEL_TRAINING):
|
|
59
|
-
time.sleep(1)
|
|
60
|
-
else:
|
|
61
|
-
error_message = (
|
|
62
|
-
str(response.status.code) + " " +
|
|
63
|
-
response.status.description + " " +
|
|
64
|
-
response.status.details
|
|
65
|
-
)
|
|
66
|
-
raise Exception(
|
|
67
|
-
f"Expected model to train, but got {error_message}. Full response: {response}"
|
|
68
|
-
)
|
|
69
|
-
# At this point, the model has successfully finished training.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def _wait_for_model_evaluated(stub, metadata, model_id, model_version_id):
|
|
73
|
-
while True:
|
|
74
|
-
response = stub.GetModelVersionMetrics(
|
|
75
|
-
service_pb2.GetModelVersionMetricsRequest(model_id=model_id, version_id=model_version_id),
|
|
76
|
-
metadata=metadata
|
|
77
|
-
)
|
|
78
|
-
_raise_on_failure(response)
|
|
79
|
-
if response.model_version.metrics.status.code == status_code_pb2.MODEL_EVALUATED:
|
|
80
|
-
break
|
|
81
|
-
elif response.model_version.metrics.status.code in (status_code_pb2.MODEL_QUEUED_FOR_EVALUATION,
|
|
82
|
-
status_code_pb2.MODEL_EVALUATING):
|
|
83
|
-
time.sleep(1)
|
|
84
|
-
else:
|
|
85
|
-
error_message = (
|
|
86
|
-
str(response.status.code) + " " +
|
|
87
|
-
response.status.description + " " +
|
|
88
|
-
response.status.details
|
|
89
|
-
)
|
|
90
|
-
raise Exception(
|
|
91
|
-
f"Expected model to evaluate, but got {error_message}. Full response: {response}"
|
|
92
|
-
)
|
|
93
|
-
# At this point, the model has successfully finished evaluation.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def _raise_on_failure(response):
|
|
97
|
-
if response.status.code != status_code_pb2.SUCCESS:
|
|
98
|
-
error_message = (
|
|
99
|
-
str(response.status.code) + " " +
|
|
100
|
-
response.status.description + " " +
|
|
101
|
-
response.status.details
|
|
102
|
-
)
|
|
103
|
-
raise Exception(
|
|
104
|
-
f"Received failure response `{error_message}`. Whole response object: {response}"
|
|
105
|
-
)
|
tests/test_integration.py
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import time
|
|
3
|
-
import uuid
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
from clarifai_grpc.grpc.api import service_pb2_grpc, service_pb2, resources_pb2
|
|
8
|
-
from clarifai_grpc.grpc.api.status import status_code_pb2
|
|
9
|
-
from tests.helpers import (both_channels, _raise_on_failure, _wait_for_inputs_upload,
|
|
10
|
-
_wait_for_model_trained, _wait_for_model_evaluated)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
DOG_IMAGE_URL = 'https://samples.clarifai.com/dog2.jpeg'
|
|
14
|
-
TRUCK_IMAGE_URL = "https://s3.amazonaws.com/samples.clarifai.com/red-truck.png"
|
|
15
|
-
NON_EXISTING_IMAGE_URL = "http://example.com/non-existing.jpg"
|
|
16
|
-
|
|
17
|
-
GENERAL_MODEL_ID = 'aaa03c23b3724a16a56b629203edc62c'
|
|
18
|
-
|
|
19
|
-
metadata = (('authorization', 'Key %s' % os.environ.get('CLARIFAI_API_KEY')),)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@both_channels
|
|
23
|
-
def test_post_model_outputs(channel):
|
|
24
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
25
|
-
request = service_pb2.PostModelOutputsRequest(
|
|
26
|
-
model_id=GENERAL_MODEL_ID,
|
|
27
|
-
inputs=[
|
|
28
|
-
resources_pb2.Input(data=resources_pb2.Data(image=resources_pb2.Image(url=DOG_IMAGE_URL)))
|
|
29
|
-
])
|
|
30
|
-
response = stub.PostModelOutputs(request, metadata=metadata)
|
|
31
|
-
|
|
32
|
-
_raise_on_failure(response)
|
|
33
|
-
|
|
34
|
-
assert len(response.outputs[0].data.concepts) > 0
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@both_channels
|
|
38
|
-
def test_failed_post_model_outputs(channel):
|
|
39
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
40
|
-
request = service_pb2.PostModelOutputsRequest(
|
|
41
|
-
model_id=GENERAL_MODEL_ID,
|
|
42
|
-
inputs=[
|
|
43
|
-
resources_pb2.Input(
|
|
44
|
-
data=resources_pb2.Data(image=resources_pb2.Image(url=NON_EXISTING_IMAGE_URL))
|
|
45
|
-
)
|
|
46
|
-
])
|
|
47
|
-
response = stub.PostModelOutputs(request, metadata=metadata)
|
|
48
|
-
|
|
49
|
-
assert response.status.code == status_code_pb2.FAILURE
|
|
50
|
-
assert response.status.description == "Failure"
|
|
51
|
-
|
|
52
|
-
assert response.outputs[0].status.code == status_code_pb2.INPUT_DOWNLOAD_FAILED
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
@both_channels
|
|
56
|
-
def test_mixed_success_post_model_outputs(channel):
|
|
57
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
58
|
-
request = service_pb2.PostModelOutputsRequest(
|
|
59
|
-
model_id=GENERAL_MODEL_ID,
|
|
60
|
-
inputs=[
|
|
61
|
-
resources_pb2.Input(data=resources_pb2.Data(image=resources_pb2.Image(url=DOG_IMAGE_URL))),
|
|
62
|
-
resources_pb2.Input(
|
|
63
|
-
data=resources_pb2.Data(image=resources_pb2.Image(url=NON_EXISTING_IMAGE_URL))
|
|
64
|
-
)
|
|
65
|
-
])
|
|
66
|
-
response = stub.PostModelOutputs(request, metadata=metadata)
|
|
67
|
-
|
|
68
|
-
assert response.status.code == status_code_pb2.MIXED_STATUS
|
|
69
|
-
|
|
70
|
-
assert response.outputs[0].status.code == status_code_pb2.SUCCESS
|
|
71
|
-
assert response.outputs[1].status.code == status_code_pb2.INPUT_DOWNLOAD_FAILED
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@both_channels
|
|
75
|
-
def test_post_patch_delete_input(channel):
|
|
76
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
77
|
-
|
|
78
|
-
post_request = service_pb2.PostInputsRequest(
|
|
79
|
-
inputs=[
|
|
80
|
-
resources_pb2.Input(
|
|
81
|
-
data=resources_pb2.Data(
|
|
82
|
-
image=resources_pb2.Image(
|
|
83
|
-
url=TRUCK_IMAGE_URL, allow_duplicate_url=True
|
|
84
|
-
),
|
|
85
|
-
concepts=[resources_pb2.Concept(id='some-concept')]
|
|
86
|
-
)
|
|
87
|
-
)
|
|
88
|
-
]
|
|
89
|
-
)
|
|
90
|
-
post_response = stub.PostInputs(post_request, metadata=metadata)
|
|
91
|
-
|
|
92
|
-
_raise_on_failure(post_response)
|
|
93
|
-
|
|
94
|
-
input_id = post_response.inputs[0].id
|
|
95
|
-
|
|
96
|
-
try:
|
|
97
|
-
while True:
|
|
98
|
-
get_request = service_pb2.GetInputRequest(input_id=input_id)
|
|
99
|
-
get_response = stub.GetInput(get_request, metadata=metadata)
|
|
100
|
-
status_code = get_response.input.status.code
|
|
101
|
-
if status_code == status_code_pb2.INPUT_DOWNLOAD_SUCCESS:
|
|
102
|
-
break
|
|
103
|
-
elif status_code not in (
|
|
104
|
-
status_code_pb2.INPUT_DOWNLOAD_PENDING,
|
|
105
|
-
status_code_pb2.INPUT_DOWNLOAD_IN_PROGRESS
|
|
106
|
-
):
|
|
107
|
-
raise Exception(
|
|
108
|
-
f'Waiting for input ID {input_id} failed, status code is {status_code}.')
|
|
109
|
-
time.sleep(0.2)
|
|
110
|
-
|
|
111
|
-
patch_request = service_pb2.PatchInputsRequest(
|
|
112
|
-
action='overwrite',
|
|
113
|
-
inputs=[
|
|
114
|
-
resources_pb2.Input(
|
|
115
|
-
id=input_id,
|
|
116
|
-
data=resources_pb2.Data(concepts=[resources_pb2.Concept(id='some-new-concept')])
|
|
117
|
-
)
|
|
118
|
-
]
|
|
119
|
-
)
|
|
120
|
-
patch_response = stub.PatchInputs(patch_request, metadata=metadata)
|
|
121
|
-
assert status_code_pb2.SUCCESS == patch_response.status.code
|
|
122
|
-
finally:
|
|
123
|
-
delete_request = service_pb2.DeleteInputRequest(input_id=input_id)
|
|
124
|
-
delete_response = stub.DeleteInput(delete_request, metadata=metadata)
|
|
125
|
-
assert status_code_pb2.SUCCESS == delete_response.status.code
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
@both_channels
|
|
129
|
-
def test_list_models_with_pagination(channel):
|
|
130
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
131
|
-
|
|
132
|
-
response = stub.ListModels(service_pb2.ListModelsRequest(per_page=2), metadata=metadata)
|
|
133
|
-
_raise_on_failure(response)
|
|
134
|
-
assert len(response.models) == 2
|
|
135
|
-
|
|
136
|
-
# We shouldn 't have 1000*500 number of models, so the result should be empty.
|
|
137
|
-
response = stub.ListModels(
|
|
138
|
-
service_pb2.ListModelsRequest(page=1000, per_page=500),
|
|
139
|
-
metadata=metadata
|
|
140
|
-
)
|
|
141
|
-
_raise_on_failure(response)
|
|
142
|
-
assert len(response.models) == 0
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
@pytest.mark.skip(reason="On Github Actions there's 'Model training had no data' error for some reason")
|
|
146
|
-
@both_channels
|
|
147
|
-
def test_model_creation_training_and_evaluation(channel):
|
|
148
|
-
model_id = str(uuid.uuid4())
|
|
149
|
-
|
|
150
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
151
|
-
|
|
152
|
-
_raise_on_failure(
|
|
153
|
-
stub.PostModels(
|
|
154
|
-
service_pb2.PostModelsRequest(
|
|
155
|
-
models=[
|
|
156
|
-
resources_pb2.Model(
|
|
157
|
-
id=model_id,
|
|
158
|
-
output_info=resources_pb2.OutputInfo(
|
|
159
|
-
data=resources_pb2.Data(
|
|
160
|
-
concepts=[
|
|
161
|
-
resources_pb2.Concept(id="dog"),
|
|
162
|
-
resources_pb2.Concept(id="toddler"),
|
|
163
|
-
]
|
|
164
|
-
)
|
|
165
|
-
)
|
|
166
|
-
)
|
|
167
|
-
]
|
|
168
|
-
),
|
|
169
|
-
metadata=metadata)
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
post_inputs_response = stub.PostInputs(
|
|
173
|
-
service_pb2.PostInputsRequest(
|
|
174
|
-
inputs=[
|
|
175
|
-
resources_pb2.Input(
|
|
176
|
-
data=resources_pb2.Data(
|
|
177
|
-
image=resources_pb2.Image(
|
|
178
|
-
url="https://samples.clarifai.com/dog2.jpeg",
|
|
179
|
-
allow_duplicate_url=True
|
|
180
|
-
),
|
|
181
|
-
concepts=[resources_pb2.Concept(id="dog")],
|
|
182
|
-
)
|
|
183
|
-
),
|
|
184
|
-
resources_pb2.Input(
|
|
185
|
-
data=resources_pb2.Data(
|
|
186
|
-
image=resources_pb2.Image(
|
|
187
|
-
url="https://samples.clarifai.com/toddler-flowers.jpeg",
|
|
188
|
-
allow_duplicate_url=True
|
|
189
|
-
),
|
|
190
|
-
concepts=[resources_pb2.Concept(id="toddler")],
|
|
191
|
-
)
|
|
192
|
-
),
|
|
193
|
-
]
|
|
194
|
-
),
|
|
195
|
-
metadata=metadata
|
|
196
|
-
)
|
|
197
|
-
_raise_on_failure(post_inputs_response)
|
|
198
|
-
|
|
199
|
-
input_ids = [i.id for i in post_inputs_response.inputs]
|
|
200
|
-
_wait_for_inputs_upload(stub, metadata, input_ids)
|
|
201
|
-
|
|
202
|
-
response = stub.PostModelVersions(
|
|
203
|
-
service_pb2.PostModelVersionsRequest(model_id=model_id),
|
|
204
|
-
metadata=metadata
|
|
205
|
-
)
|
|
206
|
-
_raise_on_failure(response)
|
|
207
|
-
|
|
208
|
-
model_version_id = response.model.model_version.id
|
|
209
|
-
_wait_for_model_trained(stub, metadata, model_id, model_version_id)
|
|
210
|
-
|
|
211
|
-
_raise_on_failure(stub.PostModelVersionMetrics(
|
|
212
|
-
service_pb2.PostModelVersionMetricsRequest(
|
|
213
|
-
model_id=model_id,
|
|
214
|
-
version_id=model_version_id,
|
|
215
|
-
),
|
|
216
|
-
metadata=metadata
|
|
217
|
-
))
|
|
218
|
-
|
|
219
|
-
_wait_for_model_evaluated(stub, metadata, model_id, model_version_id)
|
|
220
|
-
|
|
221
|
-
response = stub.GetModelVersionMetrics(
|
|
222
|
-
service_pb2.GetModelVersionMetricsRequest(
|
|
223
|
-
model_id=model_id,
|
|
224
|
-
version_id=model_version_id,
|
|
225
|
-
fields=resources_pb2.FieldsValue(
|
|
226
|
-
confusion_matrix=True,
|
|
227
|
-
cooccurrence_matrix=True,
|
|
228
|
-
label_counts=True,
|
|
229
|
-
binary_metrics=True,
|
|
230
|
-
test_set=True,
|
|
231
|
-
)
|
|
232
|
-
),
|
|
233
|
-
metadata=metadata
|
|
234
|
-
)
|
|
235
|
-
_raise_on_failure(response)
|
|
236
|
-
|
|
237
|
-
_raise_on_failure(
|
|
238
|
-
stub.DeleteModel(service_pb2.DeleteModelRequest(model_id=model_id), metadata=metadata)
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
_raise_on_failure(
|
|
242
|
-
stub.DeleteInputs(service_pb2.DeleteInputsRequest(ids=input_ids), metadata=metadata)
|
|
243
|
-
)
|
|
File without changes
|