clarifai 11.1.6rc1__py3-none-any.whl → 11.1.7__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.
Files changed (112) hide show
  1. clarifai/__init__.py +1 -1
  2. {clarifai-11.1.6rc1.dist-info → clarifai-11.1.7.dist-info}/METADATA +26 -15
  3. clarifai-11.1.7.dist-info/RECORD +101 -0
  4. {clarifai-11.1.6rc1.dist-info → clarifai-11.1.7.dist-info}/WHEEL +1 -1
  5. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  6. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  7. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  8. clarifai/cli/__main__.py~ +0 -4
  9. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  10. clarifai/cli/__pycache__/__main__.cpython-310.pyc +0 -0
  11. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  12. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  13. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  14. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  15. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  16. clarifai/client/#model_client.py# +0 -430
  17. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  18. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  19. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  20. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  21. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  22. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  23. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  24. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  25. clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
  26. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  27. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  28. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  29. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  30. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  31. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  32. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  33. clarifai/client/model_client.py +0 -447
  34. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  35. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  36. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  37. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  38. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  39. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  40. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  41. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  42. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  43. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  44. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  45. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  46. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-310.pyc +0 -0
  47. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-310.pyc +0 -0
  48. clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
  49. clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
  50. clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
  51. clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  52. clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
  53. clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
  54. clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
  55. clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
  56. clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
  57. clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
  58. clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
  59. clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
  60. clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
  61. clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
  62. clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
  63. clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
  64. clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
  65. clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
  66. clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
  67. clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
  68. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  69. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  70. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  71. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  72. clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
  73. clarifai/runners/dockerfile_template/Dockerfile.debug +0 -11
  74. clarifai/runners/dockerfile_template/Dockerfile.debug~ +0 -9
  75. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  76. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  77. clarifai/runners/models/__pycache__/model_builder.cpython-310.pyc +0 -0
  78. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  79. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  80. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  81. clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
  82. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  83. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  84. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  85. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  86. clarifai/runners/utils/__pycache__/data_types.cpython-310.pyc +0 -0
  87. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  88. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  89. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  90. clarifai/runners/utils/__pycache__/method_signatures.cpython-310.pyc +0 -0
  91. clarifai/runners/utils/__pycache__/serializers.cpython-310.pyc +0 -0
  92. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  93. clarifai/runners/utils/data_types.py +0 -386
  94. clarifai/runners/utils/method_signatures.py +0 -435
  95. clarifai/runners/utils/serializers.py +0 -208
  96. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  97. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  98. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  99. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  100. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  101. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  102. clarifai/utils/evaluation/__pycache__/__init__.cpython-310.pyc +0 -0
  103. clarifai/utils/evaluation/__pycache__/helpers.cpython-310.pyc +0 -0
  104. clarifai/utils/evaluation/__pycache__/main.cpython-310.pyc +0 -0
  105. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  106. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  107. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  108. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  109. clarifai-11.1.6rc1.dist-info/RECORD +0 -205
  110. {clarifai-11.1.6rc1.dist-info → clarifai-11.1.7.dist-info}/LICENSE +0 -0
  111. {clarifai-11.1.6rc1.dist-info → clarifai-11.1.7.dist-info}/entry_points.txt +0 -0
  112. {clarifai-11.1.6rc1.dist-info → clarifai-11.1.7.dist-info}/top_level.txt +0 -0
@@ -1,386 +0,0 @@
1
- import io
2
- import json
3
- from typing import Iterable, List, get_args, get_origin
4
-
5
- import numpy as np
6
- from clarifai_grpc.grpc.api.resources_pb2 import Audio as AudioProto
7
- from clarifai_grpc.grpc.api.resources_pb2 import Concept as ConceptProto
8
- from clarifai_grpc.grpc.api.resources_pb2 import Frame as FrameProto
9
- from clarifai_grpc.grpc.api.resources_pb2 import Image as ImageProto
10
- from clarifai_grpc.grpc.api.resources_pb2 import Region as RegionProto
11
- from clarifai_grpc.grpc.api.resources_pb2 import Text as TextProto
12
- from clarifai_grpc.grpc.api.resources_pb2 import Video as VideoProto
13
- from PIL import Image as PILImage
14
-
15
-
16
- class MessageData:
17
-
18
- def to_proto(self):
19
- raise NotImplementedError
20
-
21
- @classmethod
22
- def from_proto(cls, proto):
23
- raise NotImplementedError
24
-
25
- @classmethod
26
- def from_value(cls, value):
27
- if isinstance(value, cls):
28
- return value
29
- return cls(value)
30
-
31
- def cast(self, python_type):
32
- if python_type == self.__class__:
33
- return self
34
- raise TypeError(f'Incompatible type for {self.__class__.__name__}: {python_type}')
35
-
36
-
37
- class NamedFields(dict):
38
- __getattr__ = dict.__getitem__
39
- __setattr__ = dict.__setitem__
40
-
41
- def __origin__(self):
42
- return self
43
-
44
- def __args__(self):
45
- return list(self.keys())
46
-
47
-
48
- class Stream(Iterable):
49
- pass
50
-
51
-
52
- class JSON:
53
-
54
- def __init__(self, value):
55
- self.value = value
56
-
57
- def __eq__(self, other):
58
- return self.value == other
59
-
60
- def __bool__(self):
61
- return bool(self.value)
62
-
63
- def to_json(self):
64
- return json.dumps(self.value)
65
-
66
- @classmethod
67
- def from_json(cls, json_str):
68
- return cls(json.loads(json_str))
69
-
70
- @classmethod
71
- def from_value(cls, value):
72
- return cls(value)
73
-
74
- def cast(self, python_type):
75
- if not isinstance(self.value, python_type):
76
- raise TypeError(f'Incompatible type {type(self.value)} for {python_type}')
77
- return self.value
78
-
79
-
80
- class Text(MessageData):
81
-
82
- def __init__(self, text: str, url: str = None):
83
- self.text = text
84
- self.url = url
85
-
86
- def __eq__(self, other):
87
- if isinstance(other, Text):
88
- return self.text == other.text and self.url == other.url
89
- if isinstance(other, str):
90
- return self.text == other
91
- return False
92
-
93
- def __bool__(self):
94
- return bool(self.text) or bool(self.url)
95
-
96
- def to_proto(self) -> TextProto:
97
- return TextProto(raw=self.text or '', url=self.url or '')
98
-
99
- @classmethod
100
- def from_proto(cls, proto: TextProto) -> "Text":
101
- return cls(proto.raw, proto.url or None)
102
-
103
- @classmethod
104
- def from_value(cls, value):
105
- if isinstance(value, str):
106
- return cls(value)
107
- if isinstance(value, Text):
108
- return value
109
- if isinstance(value, dict):
110
- return cls(value.get('text'), value.get('url'))
111
- raise TypeError(f'Incompatible type for Text: {type(value)}')
112
-
113
- def cast(self, python_type):
114
- if python_type == str:
115
- return self.text
116
- if python_type == Text:
117
- return self
118
- raise TypeError(f'Incompatible type for Text: {python_type}')
119
-
120
-
121
- class Concept(MessageData):
122
-
123
- def __init__(self, name: str, value: float = 0):
124
- self.name = name
125
- self.value = value
126
-
127
- def __repr__(self) -> str:
128
- return f"Concept(name={self.name!r}, value={self.value})"
129
-
130
- def to_proto(self):
131
- return ConceptProto(name=self.name, value=self.value)
132
-
133
- @classmethod
134
- def from_proto(cls, proto: ConceptProto) -> "Concept":
135
- return cls(proto.name, proto.value)
136
-
137
-
138
- class Region(MessageData):
139
-
140
- def __init__(self, proto_region: RegionProto):
141
- self.proto = proto_region
142
-
143
- @property
144
- def box(self) -> List[float]:
145
- bbox = self.proto.region_info.bounding_box
146
- return [bbox.left_col, bbox.top_row, bbox.right_col, bbox.bottom_row] # x1, y1, x2, y2
147
-
148
- @box.setter
149
- def box(self, value: List[float]):
150
- bbox = self.proto.region_info.bounding_box
151
- bbox.left_col, bbox.top_row, bbox.right_col, bbox.bottom_row = value
152
-
153
- @property
154
- def concepts(self) -> List[Concept]:
155
- return [Concept.from_proto(proto) for proto in self.proto.data.concepts]
156
-
157
- @concepts.setter
158
- def concepts(self, value: List[Concept]):
159
- self.proto.data.concepts.extend([concept.to_proto() for concept in value])
160
-
161
- def __repr__(self) -> str:
162
- return f"Region(box={self.box}, concepts={self.concepts})"
163
-
164
- def to_proto(self) -> RegionProto:
165
- return self.proto
166
-
167
- @classmethod
168
- def from_proto(cls, proto: RegionProto) -> "Region":
169
- return cls(proto)
170
-
171
-
172
- class Image(MessageData):
173
-
174
- def __init__(self, proto_image: ImageProto = None, url: str = None, bytes: bytes = None):
175
- if proto_image is None:
176
- proto_image = ImageProto()
177
- self.proto = proto_image
178
- # use setters for init vals
179
- if url:
180
- self.url = url
181
- if bytes:
182
- self.bytes = bytes
183
-
184
- @property
185
- def url(self) -> str:
186
- return self.proto.url
187
-
188
- @url.setter
189
- def url(self, value: str):
190
- self.proto.url = value
191
-
192
- @property
193
- def bytes(self) -> bytes:
194
- return self.proto.base64
195
-
196
- @bytes.setter
197
- def bytes(self, value: bytes):
198
- self.proto.base64 = value
199
-
200
- def __repr__(self) -> str:
201
- attrs = []
202
- if self.url:
203
- attrs.append(f"url={self.url!r}")
204
- if self.bytes:
205
- attrs.append(f"bytes=<{len(self.bytes)} bytes>")
206
- return f"Image({', '.join(attrs)})"
207
-
208
- @classmethod
209
- def from_url(cls, url: str) -> "Image":
210
- proto_image = ImageProto(url=url)
211
- return cls(proto_image)
212
-
213
- @classmethod
214
- def from_pil(cls, pil_image: PILImage.Image) -> "Image":
215
- with io.BytesIO() as output:
216
- pil_image.save(output, format="PNG")
217
- image_bytes = output.getvalue()
218
- proto_image = ImageProto(base64=image_bytes)
219
- return cls(proto_image)
220
-
221
- def to_pil(self) -> PILImage.Image:
222
- if not self.proto.base64:
223
- raise ValueError("Image has no bytes")
224
- return PILImage.open(io.BytesIO(self.proto.base64))
225
-
226
- def to_numpy(self) -> np.ndarray:
227
- return np.asarray(self.to_pil())
228
-
229
- def to_proto(self) -> ImageProto:
230
- return self.proto
231
-
232
- @classmethod
233
- def from_proto(cls, proto: ImageProto) -> "Image":
234
- return cls(proto)
235
-
236
- @classmethod
237
- def from_value(cls, value):
238
- if isinstance(value, PILImage.Image):
239
- return cls.from_pil(value)
240
- if isinstance(value, Image):
241
- return value
242
- raise TypeError(f'Incompatible type for Image: {type(value)}')
243
-
244
- def cast(self, python_type):
245
- if python_type == Image:
246
- return self
247
- if python_type in (PILImage.Image, PILImage):
248
- return self.to_pil()
249
- if python_type == np.ndarray or get_origin(python_type) == np.ndarray:
250
- return self.to_numpy()
251
- raise TypeError(f'Incompatible type for Image: {python_type}')
252
-
253
-
254
- class Audio(MessageData):
255
-
256
- def __init__(self, proto_audio: AudioProto):
257
- self.proto = proto_audio
258
-
259
- @property
260
- def url(self) -> str:
261
- return self.proto.url
262
-
263
- @url.setter
264
- def url(self, value: str):
265
- self.proto.url = value
266
-
267
- @property
268
- def bytes(self) -> bytes:
269
- return self.proto.base64
270
-
271
- @bytes.setter
272
- def bytes(self, value: bytes):
273
- self.proto.base64 = value
274
-
275
- @classmethod
276
- def from_url(cls, url: str) -> "Audio":
277
- proto_audio = AudioProto(url=url)
278
- return cls(proto_audio)
279
-
280
- def __repr__(self) -> str:
281
- attrs = []
282
- if self.url:
283
- attrs.append(f"url={self.url!r}")
284
- if self.bytes:
285
- attrs.append(f"bytes=<{len(self.bytes)} bytes>")
286
- return f"Audio({', '.join(attrs)})"
287
-
288
- def to_proto(self) -> AudioProto:
289
- return self.proto
290
-
291
- @classmethod
292
- def from_proto(cls, proto: AudioProto) -> "Audio":
293
- return cls(proto)
294
-
295
-
296
- class Frame(MessageData):
297
-
298
- def __init__(self, proto_frame: FrameProto):
299
- self.proto = proto_frame
300
-
301
- @property
302
- def time(self) -> float:
303
- # TODO: time is a uint32, so this will overflow at 49.7 days
304
- # we should be using double or uint64 in the proto instead
305
- return self.proto.frame_info.time / 1000.0
306
-
307
- @time.setter
308
- def time(self, value: float):
309
- self.proto.frame_info.time = int(value * 1000)
310
-
311
- @property
312
- def image(self) -> Image:
313
- return Image.from_proto(self.proto.data.image)
314
-
315
- @image.setter
316
- def image(self, value: Image):
317
- self.proto.data.image.CopyFrom(value.to_proto())
318
-
319
- @property
320
- def regions(self) -> List[Region]:
321
- return [Region(region) for region in self.proto.data.regions]
322
-
323
- @regions.setter
324
- def regions(self, value: List[Region]):
325
- self.proto.data.regions.extend([region.proto for region in value])
326
-
327
- def to_proto(self) -> FrameProto:
328
- return self.proto
329
-
330
- @classmethod
331
- def from_proto(cls, proto: FrameProto) -> "Frame":
332
- return cls(proto)
333
-
334
-
335
- class Video(MessageData):
336
-
337
- def __init__(self, proto_video: VideoProto):
338
- self.proto = proto_video
339
-
340
- @property
341
- def url(self) -> str:
342
- return self.proto.url
343
-
344
- @url.setter
345
- def url(self, value: str):
346
- self.proto.url = value
347
-
348
- @property
349
- def bytes(self) -> bytes:
350
- return self.proto.base64
351
-
352
- @bytes.setter
353
- def bytes(self, value: bytes):
354
- self.proto.base64 = value
355
-
356
- @classmethod
357
- def from_url(cls, url: str) -> "Video":
358
- proto_video = VideoProto(url=url)
359
- return cls(proto_video)
360
-
361
- def __repr__(self) -> str:
362
- attrs = []
363
- if self.url:
364
- attrs.append(f"url={self.url!r}")
365
- if self.bytes:
366
- attrs.append(f"bytes=<{len(self.bytes)} bytes>")
367
- return f"Video({', '.join(attrs)})"
368
-
369
- def to_proto(self) -> VideoProto:
370
- return self.proto
371
-
372
- @classmethod
373
- def from_proto(cls, proto: VideoProto) -> "Video":
374
- return cls(proto)
375
-
376
-
377
- def cast(value, python_type):
378
- list_type = (get_origin(python_type) == list)
379
- if isinstance(value, MessageData):
380
- return value.cast(python_type)
381
- if list_type and isinstance(value, np.ndarray):
382
- return value.tolist()
383
- if list_type and isinstance(value, list):
384
- inner_type = get_args(python_type)[0]
385
- return [cast(item, inner_type) for item in value]
386
- return value