clarifai 11.1.7rc3__py3-none-any.whl → 11.1.7rc5__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "11.1.7rc3"
1
+ __version__ = "11.1.7rc5"
@@ -121,6 +121,17 @@ class ModelClient:
121
121
  raise TypeError(
122
122
  f"{method_name}() takes {len(method_argnames)} positional arguments but {len(args)} were given"
123
123
  )
124
+
125
+ if len(args) + len(kwargs) > len(method_argnames):
126
+ raise TypeError(
127
+ f"{method_name}() got an unexpected keyword argument {next(iter(kwargs))}")
128
+ if len(args) == 1 and (not kwargs) and isinstance(args[0], list):
129
+ batch_inputs = args[0]
130
+ # Validate each input is a dictionary
131
+ is_batch_input_valid = all(isinstance(input, dict) for input in batch_inputs)
132
+ if is_batch_input_valid:
133
+ return call_func(batch_inputs, method_name)
134
+
124
135
  for name, arg in zip(method_argnames, args): # handle positional with zip shortest
125
136
  if name in kwargs:
126
137
  raise TypeError(f"Multiple values for argument {name}")
@@ -176,6 +187,7 @@ class ModelClient:
176
187
  inputs, # TODO set up functions according to fetched signatures?
177
188
  method_name: str = 'predict',
178
189
  ) -> Any:
190
+
179
191
  input_signature = self._method_signatures[method_name].input_fields
180
192
  output_signature = self._method_signatures[method_name].output_fields
181
193
 
@@ -187,11 +199,11 @@ class ModelClient:
187
199
  proto_inputs = []
188
200
  for input in inputs:
189
201
  proto = resources_pb2.Input()
202
+
190
203
  serialize(input, input_signature, proto.data)
191
204
  proto_inputs.append(proto)
192
205
 
193
206
  response = self._predict_by_proto(proto_inputs, method_name)
194
- #print(response)
195
207
 
196
208
  outputs = []
197
209
  for output in response.outputs:
@@ -274,7 +286,6 @@ class ModelClient:
274
286
  proto_inputs.append(proto)
275
287
 
276
288
  response_stream = self._generate_by_proto(proto_inputs, method_name)
277
- #print(response)
278
289
 
279
290
  for response in response_stream:
280
291
  outputs = []
@@ -386,7 +397,6 @@ class ModelClient:
386
397
  yield proto
387
398
 
388
399
  response_stream = self._stream_by_proto(_input_proto_stream(), method_name)
389
- #print(response)
390
400
 
391
401
  for response in response_stream:
392
402
  assert len(response.outputs) == 1, 'streaming methods must have exactly one output'
@@ -68,11 +68,11 @@ class ModelBuilder:
68
68
  self.inference_compute_info = self._get_inference_compute_info()
69
69
  self.is_v3 = True # Do model build for v3
70
70
 
71
- def create_model_instance(self, load_model=True):
71
+ def create_model_instance(self, load_model=True, mocking=False):
72
72
  """
73
73
  Create an instance of the model class, as specified in the config file.
74
74
  """
75
- model_class = self.load_model_class()
75
+ model_class = self.load_model_class(mocking=mocking)
76
76
 
77
77
  # initialize the model
78
78
  model = model_class()
@@ -80,7 +80,7 @@ class ModelBuilder:
80
80
  model.load_model()
81
81
  return model
82
82
 
83
- def load_model_class(self):
83
+ def load_model_class(self, mocking=False):
84
84
  """
85
85
  Import the model class from the model.py file, dynamically handling missing dependencies
86
86
  """
@@ -108,9 +108,10 @@ class ModelBuilder:
108
108
 
109
109
  # Mock all third-party imports to avoid ImportErrors or other issues
110
110
  return MagicMock()
111
-
112
- # Replace the built-in __import__ function with our custom one
113
- builtins.__import__ = custom_import
111
+
112
+ if mocking:
113
+ # Replace the built-in __import__ function with our custom one
114
+ builtins.__import__ = custom_import
114
115
 
115
116
  try:
116
117
  spec.loader.exec_module(module)
@@ -306,16 +307,16 @@ class ModelBuilder:
306
307
  """
307
308
  Returns the method signatures for the model class in YAML format.
308
309
  """
309
- model_class = self.load_model_class()
310
+ model_class = self.load_model_class(mocking=True)
310
311
  method_info = model_class._get_method_info()
311
- signatures = {name: m.signature for name, m in method_info.values()}
312
+ signatures = {method.name: method.signature for method in method_info.values()}
312
313
  return signatures_to_yaml(signatures)
313
314
 
314
315
  def get_method_signatures(self):
315
316
  """
316
317
  Returns the method signatures for the model class.
317
318
  """
318
- model_class = self.load_model_class()
319
+ model_class = self.load_model_class(mocking=True)
319
320
  method_info = model_class._get_method_info()
320
321
  signatures = [method.signature for method in method_info.values()]
321
322
  return signatures
@@ -175,8 +175,20 @@ class Concept(MessageData):
175
175
 
176
176
  class Region(MessageData):
177
177
 
178
- def __init__(self, proto_region: RegionProto):
178
+ def __init__(self,
179
+ proto_region: RegionProto = None,
180
+ box: List[float] = None,
181
+ concepts: List[Concept] = None):
182
+ if proto_region is None:
183
+ proto_region = RegionProto()
179
184
  self.proto = proto_region
185
+ # use setters for init vals
186
+ if box and isinstance(
187
+ box, list) and len(box) == 4 and all(isinstance(val, (int, float)) for val in box):
188
+ self.box = box
189
+ if concepts and isinstance(concepts,
190
+ list) and all(isinstance(concept, Concept) for concept in concepts):
191
+ self.concepts = concepts
180
192
 
181
193
  @property
182
194
  def box(self) -> List[float]:
@@ -291,9 +303,16 @@ class Image(MessageData):
291
303
 
292
304
  class Audio(MessageData):
293
305
 
294
- def __init__(self, proto_audio: AudioProto):
306
+ def __init__(self, proto_audio: AudioProto = None, url: str = None, bytes: bytes = None):
307
+ if proto_audio is None:
308
+ proto_audio = AudioProto()
295
309
  self.proto = proto_audio
296
310
 
311
+ if url:
312
+ self.url = url
313
+ if bytes:
314
+ self.bytes = bytes
315
+
297
316
  @property
298
317
  def url(self) -> str:
299
318
  return self.proto.url
@@ -333,8 +352,21 @@ class Audio(MessageData):
333
352
 
334
353
  class Frame(MessageData):
335
354
 
336
- def __init__(self, proto_frame: FrameProto):
355
+ def __init__(self,
356
+ proto_frame: FrameProto = None,
357
+ image: Image = None,
358
+ regions: List[Region] = None,
359
+ time: float = None):
360
+ if proto_frame is None:
361
+ proto_frame = FrameProto()
337
362
  self.proto = proto_frame
363
+ # use setters for init vals
364
+ if image:
365
+ self.image = image
366
+ if regions:
367
+ self.regions = regions
368
+ if time:
369
+ self.time = time
338
370
 
339
371
  @property
340
372
  def time(self) -> float:
@@ -372,9 +404,16 @@ class Frame(MessageData):
372
404
 
373
405
  class Video(MessageData):
374
406
 
375
- def __init__(self, proto_video: VideoProto):
407
+ def __init__(self, proto_video: VideoProto = None, url: str = None, bytes: bytes = None):
408
+ if proto_video is None:
409
+ proto_video = VideoProto()
376
410
  self.proto = proto_video
377
411
 
412
+ if url:
413
+ self.url = url
414
+ if bytes:
415
+ self.bytes = bytes
416
+
378
417
  @property
379
418
  def url(self) -> str:
380
419
  return self.proto.url
@@ -330,7 +330,8 @@ def _normalize_data_type(tp):
330
330
 
331
331
  # jsonable list and dict, these can be serialized as json
332
332
  # (tuple we want to keep as a tuple for args and returns, so don't include here)
333
- if tp in (list, dict) or (get_origin(tp) in (list, dict) and _is_jsonable(tp)):
333
+ if tp in (list, dict) or (get_origin(tp) in (list, dict) and _is_jsonable(tp) and
334
+ get_args(tp) is None):
334
335
  return data_types.JSON
335
336
 
336
337
  # container types that need to be serialized as parts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 11.1.7rc3
3
+ Version: 11.1.7rc5
4
4
  Summary: Clarifai Python SDK
5
5
  Home-page: https://github.com/Clarifai/clarifai-python
6
6
  Author: Clarifai
@@ -32,7 +32,7 @@ Requires-Dist: tabulate>=0.9.0
32
32
  Requires-Dist: fsspec>=2024.6.1
33
33
  Requires-Dist: click>=8.1.7
34
34
  Requires-Dist: requests>=2.32.3
35
- Requires-Dist: aiohttp>=3.8.1
35
+ Requires-Dist: aiohttp>=3.10.0
36
36
  Provides-Extra: all
37
37
  Requires-Dist: pycocotools==2.0.6; extra == "all"
38
38
 
@@ -1,4 +1,4 @@
1
- clarifai/__init__.py,sha256=l0wL8EO4WdUNsKcblugjv356bjDqdfj1fg33DYBM7Uo,26
1
+ clarifai/__init__.py,sha256=L7ecgzwVF1qIM4sX3JzNrp3tI1YSfegldgbqVv-b-HQ,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
@@ -31,7 +31,7 @@ clarifai/client/deployment.py,sha256=w7Y6pA1rYG4KRK1SwusRZc2sQRXlG8wezuVdzSWpCo0
31
31
  clarifai/client/input.py,sha256=obMAHMDU1OwfXZ8KraOnGFlWzlW-3F7Ob_2lcOQMlhY,46339
32
32
  clarifai/client/lister.py,sha256=03KGMvs5RVyYqxLsSrWhNc34I8kiF1Ph0NeyEwu7nMU,2082
33
33
  clarifai/client/model.py,sha256=DFlZLIExMUvYXc9hDzVLYka6_AbfG3vqLlhZkk4GfIY,76835
34
- clarifai/client/model_client.py,sha256=aeKx8mx5gXqkRnipHLDYRPLIy28c0iO2MWCn3dRK9eE,17068
34
+ clarifai/client/model_client.py,sha256=FwI9XEDZjyrubK3ue0-gyTKwK_lShQcm8SoFc66aXiw,17537
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
@@ -138,7 +138,7 @@ clarifai/runners/dockerfile_template/Dockerfile.nim,sha256=CSdUAehj3uOwminioLnT5
138
138
  clarifai/runners/dockerfile_template/Dockerfile.template,sha256=5cjv7U8PmWa3DB_5B1CqSYh_6GE0E0np52TIAa7EIDE,2312
139
139
  clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
140
140
  clarifai/runners/models/base_typed_model.py,sha256=0QCWxch8CcyJSKvE1D4PILd2RSnQZHTmx4DXlQQ6dpo,7856
141
- clarifai/runners/models/model_builder.py,sha256=p4xl3Hvol7J25Z8E--CWvrPQr1SxWuchvwZC3Dx18l0,34777
141
+ clarifai/runners/models/model_builder.py,sha256=DDE4s1yzomsGyl4PbpjKdiofM6VhL0sgZujCP6wvF2k,34881
142
142
  clarifai/runners/models/model_class.py,sha256=qK5qk4geoFpqrRtl4VmKK90CIJKyWmD_vjJMqLWR_CQ,11854
143
143
  clarifai/runners/models/model_class_refract.py,sha256=HxuozxSW7ag5yWCPxjNwgLArQ6dORhyGXlnpPaZz2-c,3211
144
144
  clarifai/runners/models/model_run_locally.py,sha256=VZetm9Mko8MBjcjwr6PCnTU9gF3glgD5qvpbj-8tW2s,17962
@@ -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=nJS9n4oQHcwf2scxH8pl5TjHcY9l6ZdY401fTwpEoe4,11032
162
+ clarifai/runners/utils/data_types.py,sha256=A6IYU55pdPFfoh0K6HkEgTPlgQVv2JUG5lOlqTu1w44,12258
163
163
  clarifai/runners/utils/data_utils.py,sha256=R1iQ82TuQ9JwxCJk8yEB1Lyb0BYVhVbWJI9YDi1zGOs,318
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=EnVdLsyh7GzE7pY7fWqtcDN6t6gYKnGLU_yJnHxw7vI,17415
166
+ clarifai/runners/utils/method_signatures.py,sha256=hwrZnSbnt4OSGqnrN7INghtuJm8EJm0CEnTpwlsGgmw,17468
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.7rc3.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
233
- clarifai-11.1.7rc3.dist-info/METADATA,sha256=-t2evkzC5WdrGOlmiBDkINx4r8Pnpg-q7ZEvqz6RgMk,22214
234
- clarifai-11.1.7rc3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
235
- clarifai-11.1.7rc3.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
236
- clarifai-11.1.7rc3.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
237
- clarifai-11.1.7rc3.dist-info/RECORD,,
232
+ clarifai-11.1.7rc5.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
233
+ clarifai-11.1.7rc5.dist-info/METADATA,sha256=tOQbvNsbo_DjwJRDarrhk1uAgnSjSCDfdlcaUucYhI8,22215
234
+ clarifai-11.1.7rc5.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
235
+ clarifai-11.1.7rc5.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
236
+ clarifai-11.1.7rc5.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
237
+ clarifai-11.1.7rc5.dist-info/RECORD,,