clarifai 10.5.4__py3-none-any.whl → 10.7.0__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
@@ -0,0 +1 @@
1
+ __version__ = "10.7.0"
clarifai/client/app.py CHANGED
@@ -592,6 +592,32 @@ class App(Lister, BaseClient):
592
592
  """
593
593
  return Inputs.from_auth_helper(self.auth_helper)
594
594
 
595
+ def patch_dataset(self, dataset_id: str, action: str = 'merge', **kwargs) -> Dataset:
596
+ """Patches a dataset for the app.
597
+
598
+ Args:
599
+ dataset_id (str): The dataset ID for the dataset to create.
600
+ action (str): The action to perform on the dataset (merge/overwrite/remove).
601
+ **kwargs: Additional keyword arguments to be passed to patch the Dataset.
602
+
603
+ Returns:
604
+ Dataset: A Dataset object for the specified dataset ID.
605
+ """
606
+ if "visibility" in kwargs:
607
+ kwargs["visibility"] = resources_pb2.Visibility(gettable=kwargs["visibility"])
608
+ if "image_url" in kwargs:
609
+ kwargs["image"] = resources_pb2.Image(url=kwargs.pop("image_url"))
610
+ request = service_pb2.PatchDatasetsRequest(
611
+ user_app_id=self.user_app_id,
612
+ datasets=[resources_pb2.Dataset(id=dataset_id, **kwargs)],
613
+ action=action)
614
+ response = self._grpc_request(self.STUB.PatchDatasets, request)
615
+ if response.status.code != status_code_pb2.SUCCESS:
616
+ raise Exception(response.status)
617
+ self.logger.info("\nDataset patched\n%s", response.status)
618
+
619
+ return Dataset.from_auth_helper(self.auth_helper, dataset_id=dataset_id, **kwargs)
620
+
595
621
  def delete_dataset(self, dataset_id: str) -> None:
596
622
  """Deletes an dataset for the user.
597
623
 
clarifai/client/base.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from datetime import datetime
2
2
  from typing import Any, Callable
3
3
 
4
+ from clarifai_grpc.grpc.api import resources_pb2
4
5
  from google.protobuf import struct_pb2
5
6
  from google.protobuf.timestamp_pb2 import Timestamp
6
7
  from google.protobuf.wrappers_pb2 import BoolValue
@@ -176,6 +177,10 @@ class BaseClient:
176
177
  continue
177
178
  elif key == 'size':
178
179
  value = int(value)
180
+ elif key == 'image_info':
181
+ value = resources_pb2.ImageInfo(**value)
182
+ elif key == 'hosted_image_info':
183
+ continue
179
184
  elif key in ['metadata']:
180
185
  if isinstance(value, dict) and value != {}:
181
186
  value_s = struct_pb2.Struct()
clarifai/client/search.py CHANGED
@@ -277,7 +277,8 @@ class Search(Lister, BaseClient):
277
277
  Get successful inputs of type image or text
278
278
  >>> from clarifai.client.search import Search
279
279
  >>> search = Search(user_id='user_id', app_id='app_id', top_k=10, metric='cosine')
280
- >>> res = search.query(filters=[{'input_types': ['image', 'text']}, {'input_status_code': 30000}])
280
+ # This performs OR operation on input_types and input_status_code
281
+ >>> res = search.query(filters=[{'input_types': ['image', 'text'], 'input_status_code': 30000}])
281
282
 
282
283
  Vector search over inputs
283
284
  >>> from clarifai.client.search import Search
@@ -298,43 +299,27 @@ class Search(Lister, BaseClient):
298
299
  raise UserError(f"Invalid rank or filter input: {err}")
299
300
 
300
301
  # For each rank, create a Rank proto message
301
- rank_annot_proto = []
302
+ # For ranks it only allows resources_pb2.Annotation proto, so no need of splitting protos into annotation and input.
303
+ all_ranks = []
302
304
  for rank_dict in ranks:
303
- rank_annot_proto.append(self._get_annot_proto(**rank_dict))
304
- all_ranks = [resources_pb2.Rank(annotation=rank_annot) for rank_annot in rank_annot_proto]
305
-
306
- # Calls PostInputsSearches for annotation ranks, input filters
307
- if any(["input" in k for k in filters[0].keys()]):
308
- filters_input_proto = []
309
- for filter_dict in filters:
310
- filters_input_proto.append(self._get_input_proto(**filter_dict))
311
- all_filters = [
312
- resources_pb2.Filter(input=filter_input) for filter_input in filters_input_proto
313
- ]
314
- request_data = dict(
315
- user_app_id=self.user_app_id,
316
- searches=[
317
- resources_pb2.Search(
318
- query=resources_pb2.Query(ranks=all_ranks, filters=all_filters),
319
- algorithm=self.algorithm,
320
- metric=self.metric_distance)
321
- ])
322
- if self.pagination:
323
- return self._list_all_pages_generator(self.STUB.PostInputsSearches,
324
- service_pb2.PostInputsSearchesRequest, request_data,
325
- page_no, per_page)
326
- return self._list_topk_generator(self.STUB.PostInputsSearches,
327
- service_pb2.PostInputsSearchesRequest, request_data)
328
-
329
- # Calls PostAnnotationsSearches for annotation ranks, filters
330
- filters_annot_proto = []
331
- for filter_dict in filters:
332
- filters_annot_proto.append(self._get_annot_proto(**filter_dict))
333
-
334
- all_filters = [
335
- resources_pb2.Filter(annotation=filter_annot) for filter_annot in filters_annot_proto
336
- ]
337
-
305
+ rank_annot_proto = self._get_annot_proto(**rank_dict)
306
+ all_ranks.append(resources_pb2.Rank(annotation=rank_annot_proto))
307
+
308
+ all_filters = []
309
+ # check for filters which is compatible with input proto
310
+ for each_filter in filters:
311
+ input_dict = {
312
+ key: each_filter.pop(key)
313
+ for key in ['input_types', 'input_dataset_ids', 'input_status_code']
314
+ if key in each_filter
315
+ }
316
+
317
+ all_filters.append(
318
+ resources_pb2.Filter(
319
+ annotation=self._get_annot_proto(**each_filter),
320
+ input=self._get_input_proto(**input_dict)))
321
+
322
+ # Create a PostInputsSearchesRequest proto message
338
323
  request_data = dict(
339
324
  user_app_id=self.user_app_id,
340
325
  searches=[
@@ -343,9 +328,10 @@ class Search(Lister, BaseClient):
343
328
  algorithm=self.algorithm,
344
329
  metric=self.metric_distance)
345
330
  ])
331
+ # Calls PostInputsSearches for annotation ranks, input filters
346
332
  if self.pagination:
347
- return self._list_all_pages_generator(self.STUB.PostAnnotationsSearches,
348
- service_pb2.PostAnnotationsSearchesRequest,
349
- request_data, page_no, per_page)
350
- return self._list_topk_generator(self.STUB.PostAnnotationsSearches,
351
- service_pb2.PostAnnotationsSearchesRequest, request_data)
333
+ return self._list_all_pages_generator(self.STUB.PostInputsSearches,
334
+ service_pb2.PostInputsSearchesRequest, request_data,
335
+ page_no, per_page)
336
+ return self._list_topk_generator(self.STUB.PostInputsSearches,
337
+ service_pb2.PostInputsSearchesRequest, request_data)
clarifai/client/user.py CHANGED
@@ -3,6 +3,7 @@ from typing import Any, Dict, Generator, List
3
3
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2
4
4
  from clarifai_grpc.grpc.api.status import status_code_pb2
5
5
  from google.protobuf.json_format import MessageToDict
6
+ from google.protobuf.wrappers_pb2 import BoolValue
6
7
 
7
8
  from clarifai.client.app import App
8
9
  from clarifai.client.base import BaseClient
@@ -222,6 +223,38 @@ class User(Lister, BaseClient):
222
223
 
223
224
  return dict(self.auth_helper, check_runner_exists=False, **kwargs)
224
225
 
226
+ def patch_app(self, app_id: str, action: str = 'overwrite', **kwargs) -> App:
227
+ """Patch an app for the user.
228
+
229
+ Args:
230
+ app_id (str): The app ID for the app to patch.
231
+ action (str): The action to perform on the app (overwrite/remove).
232
+ **kwargs: Additional keyword arguments to be passed to patch the App.
233
+
234
+ Returns:
235
+ App: Patched App object for the specified app ID.
236
+ """
237
+ if "base_workflow" in kwargs:
238
+ kwargs["default_workflow"] = resources_pb2.Workflow(
239
+ id=kwargs.pop("base_workflow"), app_id="main", user_id="clarifai")
240
+ if "visibility" in kwargs:
241
+ kwargs["visibility"] = resources_pb2.Visibility(gettable=kwargs["visibility"])
242
+ if "image_url" in kwargs:
243
+ kwargs["image"] = resources_pb2.Image(url=kwargs.pop("image_url"))
244
+ if "is_template" in kwargs:
245
+ kwargs["is_template"] = BoolValue(value=kwargs["is_template"])
246
+ request = service_pb2.PatchAppRequest(
247
+ user_app_id=resources_pb2.UserAppIDSet(user_id=self.id, app_id=app_id),
248
+ app=resources_pb2.App(id=app_id, **kwargs),
249
+ action=action,
250
+ reindex=False)
251
+ response = self._grpc_request(self.STUB.PatchApp, request)
252
+ if response.status.code != status_code_pb2.SUCCESS:
253
+ raise Exception(response.status)
254
+ self.logger.info("\nApp patched\n%s", response.status)
255
+
256
+ return App.from_auth_helper(auth=self.auth_helper, app_id=app_id)
257
+
225
258
  def delete_app(self, app_id: str) -> None:
226
259
  """Deletes an app for the user.
227
260
 
clarifai/versions.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
+ from clarifai import __version__
2
3
 
3
- CLIENT_VERSION = "10.5.4"
4
+ CLIENT_VERSION = __version__
4
5
  OS_VER = os.sys.platform
5
6
  PYTHON_VERSION = '.'.join(
6
7
  map(str, [os.sys.version_info.major, os.sys.version_info.minor, os.sys.version_info.micro]))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 10.5.4
3
+ Version: 10.7.0
4
4
  Summary: Clarifai Python SDK
5
5
  Home-page: https://github.com/Clarifai/clarifai-python
6
6
  Author: Clarifai
@@ -20,7 +20,7 @@ Classifier: Operating System :: OS Independent
20
20
  Requires-Python: >=3.8
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: clarifai-grpc >=10.5.0
23
+ Requires-Dist: clarifai-grpc >=10.7.0
24
24
  Requires-Dist: numpy >=1.22.0
25
25
  Requires-Dist: tqdm >=4.65.0
26
26
  Requires-Dist: tritonclient >=2.34.0
@@ -1,17 +1,17 @@
1
- clarifai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1
+ clarifai/__init__.py,sha256=9VjBfsEYJF5PsmYbaZqem3HOFjLlVd77_XvGC9hBJrQ,23
2
2
  clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  clarifai/errors.py,sha256=RwzTajwds51wLD0MVlMC5kcpBnzRpreDLlazPSBZxrg,2605
4
- clarifai/versions.py,sha256=_ce_y-64EmSRIfWAk92G7sa7D3E2Wk4HRM5Sh2iBBTo,186
4
+ clarifai/versions.py,sha256=jctnczzfGk_S3EnVqb2FjRKfSREkNmvNEwAAa_VoKiQ,222
5
5
  clarifai/client/__init__.py,sha256=xI1U0l5AZdRThvQAXCLsd9axxyFzXXJ22m8LHqVjQRU,662
6
- clarifai/client/app.py,sha256=br3C2paGmWzKu4eG0kUN1m8kDPKqpGPq28f7Xiy2v54,27329
7
- clarifai/client/base.py,sha256=wStnn_gS6sYo36OlYRzEkOFShXOQg3DKUp8i6DomAxQ,7178
6
+ clarifai/client/app.py,sha256=UQ1TKYfZu-tYvoyMyEVN0Zsq_Wm_Tl_T70ff1UIjomw,28497
7
+ clarifai/client/base.py,sha256=JXbbjg2CXo8rOdw-XgKWWtLVAhPv3OZua5LFT5w4U2Q,7380
8
8
  clarifai/client/dataset.py,sha256=XX-J-9Ict1CQrEycq-JbdxUTuucSgLeDSvnlHE1ucQY,29903
9
9
  clarifai/client/input.py,sha256=ZLqa1jGx4NgCbunOTpJxCq4lDQ5xAf4GQ0rsZY8AHCM,44456
10
10
  clarifai/client/lister.py,sha256=03KGMvs5RVyYqxLsSrWhNc34I8kiF1Ph0NeyEwu7nMU,2082
11
11
  clarifai/client/model.py,sha256=Q0XEOWaZvSFPx7cLp4xJcwV5SVD1iU_6-DdDJmF-Hfk,72623
12
12
  clarifai/client/module.py,sha256=360JaOasX0DZCNE_Trj0LNTr-T_tUDZLfGpz0CdIi78,4248
13
- clarifai/client/search.py,sha256=iwZqwuEodbjIOEPMIjpic8caFGg3u51RK816pr-574o,14964
14
- clarifai/client/user.py,sha256=EQTeotfYTNedGcbTICYOUJqKgWhfVHvaMRTJ1hdoIdQ,10372
13
+ clarifai/client/search.py,sha256=GaPWN6JmTQGZaCHr6U1yv0zqR6wKFl7i9IVLg2ul1CI,14254
14
+ clarifai/client/user.py,sha256=Fr3vDEHieqD7HRRKnlp9h-AIX4AuYBirRYtG4KLwSe8,11836
15
15
  clarifai/client/workflow.py,sha256=e3axkhU6c6WcxK9P5tgmnV464k-afslSzsSXx6nSMgA,10560
16
16
  clarifai/client/auth/__init__.py,sha256=7EwR0NrozkAUwpUnCsqXvE_p0wqx_SelXlSpKShKJK0,136
17
17
  clarifai/client/auth/helper.py,sha256=hqwI7Zlsvivc-O9aAdtxyJT3zkpuMvbxjRaiCTsWYGk,14183
@@ -107,9 +107,9 @@ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
107
107
  clarifai/workflows/export.py,sha256=vICRhIreqDSShxLKjHNM2JwzKsf1B4fdXB0ciMcA70k,1945
108
108
  clarifai/workflows/utils.py,sha256=nGeB_yjVgUO9kOeKTg4OBBaBz-AwXI3m-huSVj-9W18,1924
109
109
  clarifai/workflows/validate.py,sha256=yJq03MaJqi5AK3alKGJJBR89xmmjAQ31sVufJUiOqY8,2556
110
- clarifai-10.5.4.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
111
- clarifai-10.5.4.dist-info/METADATA,sha256=y6nmwxvlO3GuzTeIyHPpEPagkFL_lOr_v_ztEIwc1Pg,19372
112
- clarifai-10.5.4.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
113
- clarifai-10.5.4.dist-info/entry_points.txt,sha256=qZOr_MIPG0dBBE1zringDJS_wXNGTAA_SQ-zcbmDHOw,82
114
- clarifai-10.5.4.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
115
- clarifai-10.5.4.dist-info/RECORD,,
110
+ clarifai-10.7.0.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
111
+ clarifai-10.7.0.dist-info/METADATA,sha256=HGrn1G9zveDMvPIpY76CNRr9i7gp5JhddSicHTNhLCo,19372
112
+ clarifai-10.7.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
113
+ clarifai-10.7.0.dist-info/entry_points.txt,sha256=qZOr_MIPG0dBBE1zringDJS_wXNGTAA_SQ-zcbmDHOw,82
114
+ clarifai-10.7.0.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
115
+ clarifai-10.7.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5