clarifai 11.1.7rc6__py3-none-any.whl → 11.1.7rc7__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/__init__.py +1 -1
- clarifai/client/model.py +1 -0
- clarifai/client/model_client.py +2 -0
- clarifai/runners/utils/data_types.py +5 -4
- clarifai/runners/utils/data_utils.py +132 -0
- clarifai/runners/utils/method_signatures.py +8 -3
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/METADATA +1 -1
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/RECORD +12 -12
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/LICENSE +0 -0
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/WHEEL +0 -0
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/entry_points.txt +0 -0
- {clarifai-11.1.7rc6.dist-info → clarifai-11.1.7rc7.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.1.
|
1
|
+
__version__ = "11.1.7rc7"
|
clarifai/client/model.py
CHANGED
@@ -84,6 +84,7 @@ class Model(Lister, BaseClient):
|
|
84
84
|
compute_cluster_id=compute_cluster_id,
|
85
85
|
nodepool_id=nodepool_id,
|
86
86
|
deployment_id=deployment_id,
|
87
|
+
user_id=self.user_id, # FIXME the deployment's user_id can be different than the model's.
|
87
88
|
)
|
88
89
|
BaseClient.__init__(
|
89
90
|
self,
|
clarifai/client/model_client.py
CHANGED
@@ -203,6 +203,8 @@ class ModelClient:
|
|
203
203
|
proto = resources_pb2.Input()
|
204
204
|
|
205
205
|
serialize(input, input_signature, proto.data)
|
206
|
+
print("input:", input)
|
207
|
+
print("proto.data:", proto.data)
|
206
208
|
proto_inputs.append(proto)
|
207
209
|
|
208
210
|
response = self._predict_by_proto(proto_inputs, method_name)
|
@@ -158,19 +158,20 @@ class Text(MessageData):
|
|
158
158
|
|
159
159
|
class Concept(MessageData):
|
160
160
|
|
161
|
-
def __init__(self, name: str, value: float =
|
161
|
+
def __init__(self, id: str, name: str, value: float = 1):
|
162
|
+
self.id = id
|
162
163
|
self.name = name
|
163
164
|
self.value = value
|
164
165
|
|
165
166
|
def __repr__(self) -> str:
|
166
|
-
return f"Concept(name={self.name!r}, value={self.value})"
|
167
|
+
return f"Concept(id={self.id!r}, name={self.name!r}, value={self.value})"
|
167
168
|
|
168
169
|
def to_proto(self):
|
169
|
-
return ConceptProto(name=self.name, value=self.value)
|
170
|
+
return ConceptProto(id=self.id, name=self.name, value=self.value)
|
170
171
|
|
171
172
|
@classmethod
|
172
173
|
def from_proto(cls, proto: ConceptProto) -> "Concept":
|
173
|
-
return cls(proto.name, proto.value)
|
174
|
+
return cls(proto.id, proto.name, proto.value)
|
174
175
|
|
175
176
|
|
176
177
|
class Region(MessageData):
|
@@ -1,7 +1,12 @@
|
|
1
1
|
from io import BytesIO
|
2
2
|
|
3
|
+
from clarifai_grpc.grpc.api.resources_pb2 import ModelTypeEnumOption
|
4
|
+
from clarifai_grpc.grpc.api.resources_pb2 import ModelTypeField as InputFieldProto
|
5
|
+
from clarifai_grpc.grpc.api.resources_pb2 import ModelTypeRangeInfo
|
3
6
|
from PIL import Image
|
4
7
|
|
8
|
+
from clarifai.runners.utils.data_types import MessageData
|
9
|
+
|
5
10
|
|
6
11
|
def image_to_bytes(img: Image.Image, format="JPEG") -> bytes:
|
7
12
|
buffered = BytesIO()
|
@@ -49,3 +54,130 @@ def is_openai_chat_format(messages):
|
|
49
54
|
if not isinstance(item, dict):
|
50
55
|
return False
|
51
56
|
return True
|
57
|
+
|
58
|
+
|
59
|
+
class InputField(MessageData):
|
60
|
+
"""A field that can be used to store input data."""
|
61
|
+
|
62
|
+
def __init__(self,
|
63
|
+
default=None,
|
64
|
+
description=None,
|
65
|
+
min_value=None,
|
66
|
+
max_value=None,
|
67
|
+
choices=None,
|
68
|
+
visibility=True,
|
69
|
+
is_param=False):
|
70
|
+
self.default = default
|
71
|
+
self.description = description
|
72
|
+
self.min_value = min_value
|
73
|
+
self.max_value = max_value
|
74
|
+
self.choices = choices
|
75
|
+
self.visibility = visibility
|
76
|
+
self.is_param = is_param
|
77
|
+
|
78
|
+
def __repr__(self) -> str:
|
79
|
+
attrs = []
|
80
|
+
if self.default is not None:
|
81
|
+
attrs.append(f"default={self.default!r}")
|
82
|
+
if self.description is not None:
|
83
|
+
attrs.append(f"description={self.description!r}")
|
84
|
+
if self.min_value is not None:
|
85
|
+
attrs.append(f"min_value={self.min_value!r}")
|
86
|
+
if self.max_value is not None:
|
87
|
+
attrs.append(f"max_value={self.max_value!r}")
|
88
|
+
if self.choices is not None:
|
89
|
+
attrs.append(f"choices={self.choices!r}")
|
90
|
+
attrs.append(f"visibility={self.visibility!r}")
|
91
|
+
attrs.append(f"is_param={self.is_param!r}")
|
92
|
+
return f"InputField({', '.join(attrs)})"
|
93
|
+
|
94
|
+
def to_proto(self, proto=None) -> InputFieldProto:
|
95
|
+
if proto is None:
|
96
|
+
proto = InputFieldProto()
|
97
|
+
if self.description is not None:
|
98
|
+
proto.description = self.description
|
99
|
+
|
100
|
+
if self.choices is not None:
|
101
|
+
for choice in self.choices:
|
102
|
+
option = ModelTypeEnumOption(id=str(choice))
|
103
|
+
proto.model_type_enum_options.append(option)
|
104
|
+
|
105
|
+
proto.required = self.default is None
|
106
|
+
|
107
|
+
if self.min_value is not None or self.max_value is not None:
|
108
|
+
range_info = ModelTypeRangeInfo()
|
109
|
+
if self.min_value is not None:
|
110
|
+
range_info.min = float(self.min_value)
|
111
|
+
if self.max_value is not None:
|
112
|
+
range_info.max = float(self.max_value)
|
113
|
+
proto.model_type_range_info.CopyFrom(range_info)
|
114
|
+
|
115
|
+
proto.visibility = self.visibility
|
116
|
+
proto.is_param = self.is_param
|
117
|
+
|
118
|
+
if self.default is not None:
|
119
|
+
if isinstance(self.default, str) or isinstance(self.default, bool) or isinstance(
|
120
|
+
self.default, (int, float)):
|
121
|
+
proto.default = str(self.default)
|
122
|
+
else:
|
123
|
+
import json
|
124
|
+
proto.default = json.dumps(self.default)
|
125
|
+
|
126
|
+
return proto
|
127
|
+
|
128
|
+
@classmethod
|
129
|
+
def from_proto(cls, proto):
|
130
|
+
default = None
|
131
|
+
if proto.HasField('default'):
|
132
|
+
pb_value = proto.default
|
133
|
+
if pb_value.HasField('string_value'):
|
134
|
+
default = pb_value.string_value
|
135
|
+
try:
|
136
|
+
import json
|
137
|
+
default = json.loads(default)
|
138
|
+
except json.JSONDecodeError:
|
139
|
+
pass
|
140
|
+
elif pb_value.HasField('number_value'):
|
141
|
+
default = pb_value.number_value
|
142
|
+
if default.is_integer():
|
143
|
+
default = int(default)
|
144
|
+
else:
|
145
|
+
default = float(default)
|
146
|
+
elif pb_value.HasField('bool_value'):
|
147
|
+
default = pb_value.bool_value
|
148
|
+
|
149
|
+
choices = [option.id for option in proto.model_type_enum_options
|
150
|
+
] if proto.model_type_enum_options else None
|
151
|
+
|
152
|
+
min_value = None
|
153
|
+
max_value = None
|
154
|
+
if proto.HasField('model_type_range_info'):
|
155
|
+
min_value = proto.model_type_range_info.min
|
156
|
+
max_value = proto.model_type_range_info.max
|
157
|
+
if min_value.is_integer():
|
158
|
+
min_value = int(min_value)
|
159
|
+
if max_value.is_integer():
|
160
|
+
max_value = int(max_value)
|
161
|
+
|
162
|
+
return cls(
|
163
|
+
default=default,
|
164
|
+
description=proto.description if proto.description else None,
|
165
|
+
min_value=min_value,
|
166
|
+
max_value=max_value,
|
167
|
+
choices=choices,
|
168
|
+
visibility=proto.visibility,
|
169
|
+
is_param=proto.is_param)
|
170
|
+
|
171
|
+
@classmethod
|
172
|
+
def set_default(cls, proto=None, default=None):
|
173
|
+
|
174
|
+
if proto is None:
|
175
|
+
proto = InputFieldProto()
|
176
|
+
if default is not None:
|
177
|
+
if isinstance(default, str) or isinstance(default, bool) or isinstance(
|
178
|
+
default, (int, float)):
|
179
|
+
proto.default = str(default)
|
180
|
+
else:
|
181
|
+
import json
|
182
|
+
proto.default = json.dumps(default)
|
183
|
+
return proto
|
@@ -10,7 +10,7 @@ from clarifai_grpc.grpc.api import resources_pb2
|
|
10
10
|
from google.protobuf.json_format import MessageToDict, ParseDict
|
11
11
|
from google.protobuf.message import Message as MessageProto
|
12
12
|
|
13
|
-
from clarifai.runners.utils import data_types
|
13
|
+
from clarifai.runners.utils import data_types, data_utils
|
14
14
|
from clarifai.runners.utils.serializers import (
|
15
15
|
AtomicFieldSerializer, JSONSerializer, ListSerializer, MessageSerializer,
|
16
16
|
NamedFieldsSerializer, NDArraySerializer, Serializer, TupleSerializer)
|
@@ -107,7 +107,10 @@ def build_variable_signature(name, annotation, default=inspect.Parameter.empty,
|
|
107
107
|
if not is_output:
|
108
108
|
sig.required = (default is inspect.Parameter.empty)
|
109
109
|
if not sig.required:
|
110
|
-
|
110
|
+
if isinstance(default, data_utils.InputField):
|
111
|
+
sig = default.to_proto(sig)
|
112
|
+
else:
|
113
|
+
sig = data_utils.InputField.set_default(sig, default)
|
111
114
|
|
112
115
|
_fill_signature_type(sig, tp)
|
113
116
|
|
@@ -150,6 +153,7 @@ def _fill_signature_type(sig, tp):
|
|
150
153
|
sig.type = resources_pb2.ModelTypeField.DataType.TUPLE
|
151
154
|
for inner_type in args:
|
152
155
|
inner_sig = sig.type_args.add()
|
156
|
+
inner_sig.name = sig.name + '_item'
|
153
157
|
_fill_signature_type(inner_sig, inner_type)
|
154
158
|
return
|
155
159
|
|
@@ -157,6 +161,7 @@ def _fill_signature_type(sig, tp):
|
|
157
161
|
if origin == list:
|
158
162
|
sig.type = resources_pb2.ModelTypeField.DataType.LIST
|
159
163
|
inner_sig = sig.type_args.add()
|
164
|
+
inner_sig.name = sig.name + '_item'
|
160
165
|
_fill_signature_type(inner_sig, args[0])
|
161
166
|
return
|
162
167
|
|
@@ -237,7 +242,7 @@ def serialize(kwargs, signatures, proto=None, is_output=False):
|
|
237
242
|
# if there is only one output, flatten it and return directly
|
238
243
|
inline_first_value = True
|
239
244
|
if signatures and signatures[0].type not in _NON_INLINABLE_TYPES:
|
240
|
-
inline_first_value =
|
245
|
+
inline_first_value = False
|
241
246
|
for sig_i, sig in enumerate(signatures):
|
242
247
|
if sig.name not in kwargs:
|
243
248
|
if sig.required:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
clarifai/__init__.py,sha256=
|
1
|
+
clarifai/__init__.py,sha256=UVb-Qd94W3trcR1tUhxvZWOZsQeO3zRk4WOaKuSTtK0,26
|
2
2
|
clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
clarifai/errors.py,sha256=RwzTajwds51wLD0MVlMC5kcpBnzRpreDLlazPSBZxrg,2605
|
4
4
|
clarifai/versions.py,sha256=jctnczzfGk_S3EnVqb2FjRKfSREkNmvNEwAAa_VoKiQ,222
|
@@ -30,8 +30,8 @@ clarifai/client/dataset.py,sha256=y3zKT_VhP1gyN3OO-b3cPeW21ZXyKbQ7ZJkEG06bsTU,32
|
|
30
30
|
clarifai/client/deployment.py,sha256=w7Y6pA1rYG4KRK1SwusRZc2sQRXlG8wezuVdzSWpCo0,2586
|
31
31
|
clarifai/client/input.py,sha256=obMAHMDU1OwfXZ8KraOnGFlWzlW-3F7Ob_2lcOQMlhY,46339
|
32
32
|
clarifai/client/lister.py,sha256=03KGMvs5RVyYqxLsSrWhNc34I8kiF1Ph0NeyEwu7nMU,2082
|
33
|
-
clarifai/client/model.py,sha256=
|
34
|
-
clarifai/client/model_client.py,sha256=
|
33
|
+
clarifai/client/model.py,sha256=HLTzCoGhZ5Ifm5x5nSFa4YULnLLlBpZF-29nfOcwFuY,76995
|
34
|
+
clarifai/client/model_client.py,sha256=B2M_yr-iuhgT1bJTontfN_KrJyfDRKfNW5ALM0Cufkc,17864
|
35
35
|
clarifai/client/module.py,sha256=FTkm8s9m-EaTKN7g9MnLhGJ9eETUfKG7aWZ3o1RshYs,4204
|
36
36
|
clarifai/client/nodepool.py,sha256=la3vTFrO4LX8zm2eQ5jqf2L0-kQ63Dano8FibadoZbk,10152
|
37
37
|
clarifai/client/search.py,sha256=GaPWN6JmTQGZaCHr6U1yv0zqR6wKFl7i9IVLg2ul1CI,14254
|
@@ -159,11 +159,11 @@ clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
|
|
159
159
|
clarifai/runners/utils/const.py,sha256=bwj-Pcw558-pasdIFbNhnkn-9oiCdojYH1fNTTUG2gU,1048
|
160
160
|
clarifai/runners/utils/data_handler.py,sha256=b7k6MWYPXSgjrfw6wsDf82xFYa0D7UjYmjE4mw5HzHM,8499
|
161
161
|
clarifai/runners/utils/data_handler_refract.py,sha256=3M-V4hkOoF-9Ix4hE6ocXWiTJPc9dewtu6FMtddd-jQ,6343
|
162
|
-
clarifai/runners/utils/data_types.py,sha256=
|
163
|
-
clarifai/runners/utils/data_utils.py,sha256=
|
162
|
+
clarifai/runners/utils/data_types.py,sha256=xW3DrBP0uyyyAw_K7xuLhEfBDhTbGu2u1L-mKK2bhTY,12322
|
163
|
+
clarifai/runners/utils/data_utils.py,sha256=j_W_O57ciGbp2JDVLlau-V-DDrF6gsN6cjtLaL51AvA,5512
|
164
164
|
clarifai/runners/utils/loader.py,sha256=SgNHMwRmCCymFQm8aDp73NmIUHhM-N60CBlTKbPzmVc,7470
|
165
165
|
clarifai/runners/utils/logger.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
166
|
-
clarifai/runners/utils/method_signatures.py,sha256=
|
166
|
+
clarifai/runners/utils/method_signatures.py,sha256=ZFqcPsjp9Fbih2u-xTLN3utZkHeOhBxtaiHMEzJKcCw,17657
|
167
167
|
clarifai/runners/utils/serializers.py,sha256=S4sRsOVvH191vAGTRTAAdwLlQwlK4T5QVRDGPptg9nQ,7191
|
168
168
|
clarifai/runners/utils/url_fetcher.py,sha256=v_8JOWmkyFAzsBulsieKX7Nfjy1Yg7wGSZeqfEvw2cg,1640
|
169
169
|
clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc,sha256=0GGbXIecXlOZmQKMCkSRhEBY_a1zvoimv-mHG4pJuNA,167
|
@@ -229,9 +229,9 @@ clarifai/workflows/__pycache__/__init__.cpython-39.pyc,sha256=9nA--jULSW7OFrYOcs
|
|
229
229
|
clarifai/workflows/__pycache__/export.cpython-310.pyc,sha256=phEGwi2gAojCUhRTqjZVeTDn7Gk6LCVBeSTjAj4m9iY,2418
|
230
230
|
clarifai/workflows/__pycache__/utils.cpython-310.pyc,sha256=M9_KTM7GOOS5SPrWwAzqHDqyGvgKi3xuSGvyw6MNf-I,1925
|
231
231
|
clarifai/workflows/__pycache__/validate.cpython-310.pyc,sha256=c18Jgp_-CAm8RD_tmUpDCPoqZeexaoWELG0yBzb9rjw,2149
|
232
|
-
clarifai-11.1.
|
233
|
-
clarifai-11.1.
|
234
|
-
clarifai-11.1.
|
235
|
-
clarifai-11.1.
|
236
|
-
clarifai-11.1.
|
237
|
-
clarifai-11.1.
|
232
|
+
clarifai-11.1.7rc7.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
|
233
|
+
clarifai-11.1.7rc7.dist-info/METADATA,sha256=5YXRRR7I8rkzcai9pN5auQTaxd0M-X0jUKNaVk-qNmo,22453
|
234
|
+
clarifai-11.1.7rc7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
235
|
+
clarifai-11.1.7rc7.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
|
236
|
+
clarifai-11.1.7rc7.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
|
237
|
+
clarifai-11.1.7rc7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|