clarifai 10.10.1__tar.gz → 10.11.0__tar.gz

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 (119) hide show
  1. {clarifai-10.10.1/clarifai.egg-info → clarifai-10.11.0}/PKG-INFO +2 -2
  2. clarifai-10.11.0/clarifai/__init__.py +1 -0
  3. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/model.py +7 -2
  4. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/model.py +1 -1
  5. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/export/inputs_annotations.py +8 -0
  6. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/base_typed_model.py +6 -3
  7. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/model_run_locally.py +24 -9
  8. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/model_upload.py +1 -1
  9. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/utils/url_fetcher.py +19 -12
  10. {clarifai-10.10.1 → clarifai-10.11.0/clarifai.egg-info}/PKG-INFO +2 -2
  11. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai.egg-info/requires.txt +1 -1
  12. {clarifai-10.10.1 → clarifai-10.11.0}/pyproject.toml +1 -1
  13. {clarifai-10.10.1 → clarifai-10.11.0}/requirements.txt +1 -1
  14. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_app.py +22 -11
  15. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_data_upload.py +6 -5
  16. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_eval.py +6 -5
  17. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_model_predict.py +26 -35
  18. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_model_train.py +6 -5
  19. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_rag.py +8 -2
  20. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_search.py +18 -4
  21. clarifai-10.10.1/clarifai/__init__.py +0 -1
  22. {clarifai-10.10.1 → clarifai-10.11.0}/LICENSE +0 -0
  23. {clarifai-10.10.1 → clarifai-10.11.0}/MANIFEST.in +0 -0
  24. {clarifai-10.10.1 → clarifai-10.11.0}/README.md +0 -0
  25. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/README.md +0 -0
  26. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/__init__.py +0 -0
  27. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/base.py +0 -0
  28. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/compute_cluster.py +0 -0
  29. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/deployment.py +0 -0
  30. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli/nodepool.py +0 -0
  31. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/cli.py +0 -0
  32. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/__init__.py +0 -0
  33. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/app.py +0 -0
  34. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/auth/__init__.py +0 -0
  35. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/auth/helper.py +0 -0
  36. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/auth/register.py +0 -0
  37. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/auth/stub.py +0 -0
  38. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/base.py +0 -0
  39. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/compute_cluster.py +0 -0
  40. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/dataset.py +0 -0
  41. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/deployment.py +0 -0
  42. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/input.py +0 -0
  43. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/lister.py +0 -0
  44. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/module.py +0 -0
  45. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/nodepool.py +0 -0
  46. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/search.py +0 -0
  47. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/user.py +0 -0
  48. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/client/workflow.py +0 -0
  49. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/base.py +0 -0
  50. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/dataset.py +0 -0
  51. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/input.py +0 -0
  52. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/model.py +0 -0
  53. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/rag.py +0 -0
  54. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/search.py +0 -0
  55. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/constants/workflow.py +0 -0
  56. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/__init__.py +0 -0
  57. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/export/__init__.py +0 -0
  58. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/__init__.py +0 -0
  59. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/base.py +0 -0
  60. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/features.py +0 -0
  61. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/image.py +0 -0
  62. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/README.md +0 -0
  63. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/__init__.py +0 -0
  64. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/coco_captions.py +0 -0
  65. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/coco_detection.py +0 -0
  66. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/imagenet_classification.py +0 -0
  67. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/loaders/xview_detection.py +0 -0
  68. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/multimodal.py +0 -0
  69. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/text.py +0 -0
  70. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/datasets/upload/utils.py +0 -0
  71. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/errors.py +0 -0
  72. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/models/__init__.py +0 -0
  73. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/models/api.py +0 -0
  74. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/modules/README.md +0 -0
  75. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/modules/__init__.py +0 -0
  76. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/modules/css.py +0 -0
  77. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/modules/pages.py +0 -0
  78. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/modules/style.css +0 -0
  79. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/rag/__init__.py +0 -0
  80. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/rag/rag.py +0 -0
  81. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/rag/utils.py +0 -0
  82. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/__init__.py +0 -0
  83. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/dockerfile_template/Dockerfile.template +0 -0
  84. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/__init__.py +0 -0
  85. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/model_class.py +0 -0
  86. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/model_runner.py +0 -0
  87. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/models/model_servicer.py +0 -0
  88. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/server.py +0 -0
  89. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/utils/__init__.py +0 -0
  90. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/utils/data_handler.py +0 -0
  91. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/utils/data_utils.py +0 -0
  92. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/runners/utils/loader.py +0 -0
  93. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/schema/search.py +0 -0
  94. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/urls/helper.py +0 -0
  95. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/__init__.py +0 -0
  96. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/cli.py +0 -0
  97. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/constants.py +0 -0
  98. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/evaluation/__init__.py +0 -0
  99. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/evaluation/helpers.py +0 -0
  100. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/evaluation/main.py +0 -0
  101. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/evaluation/testset_annotation_parser.py +0 -0
  102. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/logging.py +0 -0
  103. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/misc.py +0 -0
  104. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/utils/model_train.py +0 -0
  105. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/versions.py +0 -0
  106. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/workflows/__init__.py +0 -0
  107. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/workflows/export.py +0 -0
  108. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/workflows/utils.py +0 -0
  109. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai/workflows/validate.py +0 -0
  110. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai.egg-info/SOURCES.txt +0 -0
  111. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai.egg-info/dependency_links.txt +0 -0
  112. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai.egg-info/entry_points.txt +0 -0
  113. {clarifai-10.10.1 → clarifai-10.11.0}/clarifai.egg-info/top_level.txt +0 -0
  114. {clarifai-10.10.1 → clarifai-10.11.0}/setup.cfg +0 -0
  115. {clarifai-10.10.1 → clarifai-10.11.0}/setup.py +0 -0
  116. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_auth.py +0 -0
  117. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_misc.py +0 -0
  118. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_modules.py +0 -0
  119. {clarifai-10.10.1 → clarifai-10.11.0}/tests/test_stub.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 10.10.1
3
+ Version: 10.11.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.9.11
23
+ Requires-Dist: clarifai-grpc>=10.10.2
24
24
  Requires-Dist: clarifai-protocol>=0.0.6
25
25
  Requires-Dist: numpy>=1.22.0
26
26
  Requires-Dist: tqdm>=4.65.0
@@ -0,0 +1 @@
1
+ __version__ = "10.11.0"
@@ -39,11 +39,16 @@ def upload(model_path, download_checkpoints, skip_dockerfile):
39
39
  type=click.Path(exists=True),
40
40
  required=True,
41
41
  help='Path to the model directory.')
42
- def test_locally(model_path):
42
+ @click.option(
43
+ '--keep_env',
44
+ is_flag=True,
45
+ help='Flag to keep the virtual environment after testing the model\
46
+ locally. Defaults to False, which will delete the virtual environment after testing.')
47
+ def test_locally(model_path, keep_env=False):
43
48
  """Test model locally."""
44
49
  try:
45
50
  from clarifai.runners.models import model_run_locally
46
- model_run_locally.main(model_path)
51
+ model_run_locally.main(model_path, keep_env=keep_env)
47
52
  click.echo(f"Model tested locally from {model_path}.")
48
53
  except Exception as e:
49
54
  click.echo(f"Failed to test model locally: {e}", err=True)
@@ -743,7 +743,7 @@ class Model(Lister, BaseClient):
743
743
  file_bytes = f.read()
744
744
 
745
745
  return self.generate_by_bytes(
746
- filepath=file_bytes,
746
+ input_bytes=file_bytes,
747
747
  input_type=input_type,
748
748
  compute_cluster_id=compute_cluster_id,
749
749
  nodepool_id=nodepool_id,
@@ -165,6 +165,14 @@ class InputAnnotationDownloader:
165
165
  def _save_annotation_to_archive(self, new_archive: zipfile.ZipFile, annot_data: List[Dict],
166
166
  file_name: str) -> None:
167
167
  """Gets the annotation response bytestring (from requests) and append to zip file."""
168
+ # Fill zero values for missing bounding box keys
169
+ for annot in annot_data:
170
+ if annot.get('regionInfo') and annot['regionInfo'].get('boundingBox'):
171
+ bbox = annot['regionInfo']['boundingBox']
172
+ bbox.setdefault('topRow', 0)
173
+ bbox.setdefault('leftCol', 0)
174
+ bbox.setdefault('bottomRow', 0)
175
+ bbox.setdefault('rightCol', 0)
168
176
  # Serialize the dictionary to a JSON string
169
177
  json_str = json.dumps(annot_data)
170
178
  # Convert the JSON string to bytes
@@ -24,7 +24,8 @@ class AnyAnyModel(ModelRunner):
24
24
  list_input_dict = [
25
25
  InputDataHandler.from_proto(input).to_python() for input in input_request.inputs
26
26
  ]
27
- inference_params = json_format.MessageToDict(input_request.model.output_info.params)
27
+ inference_params = json_format.MessageToDict(
28
+ input_request.model.model_version.output_info.params)
28
29
 
29
30
  return list_input_dict, inference_params
30
31
 
@@ -141,7 +142,8 @@ class VisualInputModel(AnyAnyModel):
141
142
  list_input_dict = [
142
143
  InputDataHandler.from_proto(input).image(format="np") for input in input_request.inputs
143
144
  ]
144
- inference_params = json_format.MessageToDict(input_request.model.output_info.params)
145
+ inference_params = json_format.MessageToDict(
146
+ input_request.model.model_version.output_info.params)
145
147
 
146
148
  return list_input_dict, inference_params
147
149
 
@@ -181,7 +183,8 @@ class TextInputModel(AnyAnyModel):
181
183
  def parse_input_request(
182
184
  self, input_request: service_pb2.PostModelOutputsRequest) -> Tuple[List[Dict], Dict]:
183
185
  list_input_text = [InputDataHandler.from_proto(input).text for input in input_request.inputs]
184
- inference_params = json_format.MessageToDict(input_request.model.output_info.params)
186
+ inference_params = json_format.MessageToDict(
187
+ input_request.model.model_version.output_info.params)
185
188
 
186
189
  return list_input_text, inference_params
187
190
 
@@ -1,3 +1,4 @@
1
+ import hashlib
1
2
  import importlib.util
2
3
  import inspect
3
4
  import os
@@ -13,6 +14,7 @@ from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
13
14
  from clarifai_protocol import BaseRunner
14
15
 
15
16
  from clarifai.runners.models.model_upload import ModelUploader
17
+ from clarifai.runners.utils.url_fetcher import ensure_urls_downloaded
16
18
  from clarifai.utils.logging import logger
17
19
 
18
20
 
@@ -24,17 +26,26 @@ class ModelRunLocally:
24
26
 
25
27
  def create_temp_venv(self):
26
28
  """Create a temporary virtual environment."""
27
- logger.info("Creating temporary virtual environment...")
28
- temp_dir = tempfile.mkdtemp()
29
+ with open(self.requirements_file, "r") as f:
30
+ requirements_hash = hashlib.md5(f.read().encode('utf-8')).hexdigest()
31
+
32
+ temp_dir = os.path.join(tempfile.gettempdir(), str(requirements_hash))
29
33
  venv_dir = os.path.join(temp_dir, "venv")
30
- venv.create(venv_dir, with_pip=True)
34
+
35
+ if os.path.exists(temp_dir):
36
+ logger.info(f"Using previous virtual environment at {temp_dir}")
37
+ use_existing_venv = True
38
+ else:
39
+ logger.info("Creating temporary virtual environment...")
40
+ use_existing_venv = False
41
+ venv.create(venv_dir, with_pip=True)
42
+ logger.info(f"Created temporary virtual environment at {venv_dir}")
31
43
 
32
44
  self.venv_dir = venv_dir
33
45
  self.temp_dir = temp_dir
34
46
  self.python_executable = os.path.join(venv_dir, "bin", "python")
35
47
 
36
- logger.info(f"Created temporary virtual environment at {venv_dir}")
37
- return venv_dir, temp_dir
48
+ return use_existing_venv
38
49
 
39
50
  def install_requirements(self):
40
51
  """Install the dependencies from requirements.txt and Clarifai."""
@@ -102,6 +113,8 @@ class ModelRunLocally:
102
113
  """Perform inference using the runner."""
103
114
  request = self._build_request()
104
115
 
116
+ ensure_urls_downloaded(request)
117
+
105
118
  try:
106
119
  return runner.predict(request)
107
120
  except Exception as e:
@@ -175,16 +188,18 @@ class ModelRunLocally:
175
188
  shutil.rmtree(self.temp_dir)
176
189
 
177
190
 
178
- def main(model_path, run_model_server=False):
191
+ def main(model_path, run_model_server=False, keep_env=False):
179
192
 
180
193
  manager = ModelRunLocally(model_path)
181
- manager.create_temp_venv()
194
+ use_existing_env = manager.create_temp_venv()
182
195
 
183
196
  try:
184
- manager.install_requirements()
197
+ if not use_existing_env:
198
+ manager.install_requirements()
185
199
  if run_model_server:
186
200
  manager.run_model_server()
187
201
  else:
188
202
  manager.test_model()
189
203
  finally:
190
- manager.clean_up()
204
+ if not keep_env:
205
+ manager.clean_up()
@@ -126,7 +126,7 @@ class ModelUploader:
126
126
  user_id = model.get('user_id')
127
127
  app_id = model.get('app_id')
128
128
 
129
- base = os.environ.get('CLARIFAI_API_BASE', 'https://api-dev.clarifai.com')
129
+ base = os.environ.get('CLARIFAI_API_BASE', 'https://api.clarifai.com')
130
130
 
131
131
  self._client = BaseClient(user_id=user_id, app_id=app_id, base=base)
132
132
 
@@ -6,25 +6,32 @@ from clarifai.utils.logging import logger
6
6
 
7
7
 
8
8
  def download_input(input):
9
+ _download_input_data(input.data)
10
+ if input.data.parts:
11
+ for i in range(len(input.data.parts)):
12
+ _download_input_data(input.data.parts[i].data)
13
+
14
+
15
+ def _download_input_data(input_data):
9
16
  """
10
17
  This function will download any urls that are not already bytes.
11
18
  """
12
- if input.data.image.url and not input.data.image.base64:
19
+ if input_data.image.url and not input_data.image.base64:
13
20
  # Download the image
14
- with fsspec.open(input.data.image.url, 'rb') as f:
15
- input.data.image.base64 = f.read()
16
- if input.data.video.url and not input.data.video.base64:
21
+ with fsspec.open(input_data.image.url, 'rb') as f:
22
+ input_data.image.base64 = f.read()
23
+ if input_data.video.url and not input_data.video.base64:
17
24
  # Download the video
18
- with fsspec.open(input.data.video.url, 'rb') as f:
19
- input.data.video.base64 = f.read()
20
- if input.data.audio.url and not input.data.audio.base64:
25
+ with fsspec.open(input_data.video.url, 'rb') as f:
26
+ input_data.video.base64 = f.read()
27
+ if input_data.audio.url and not input_data.audio.base64:
21
28
  # Download the audio
22
- with fsspec.open(input.data.audio.url, 'rb') as f:
23
- input.data.audio.base64 = f.read()
24
- if input.data.text.url and not input.data.text.raw:
29
+ with fsspec.open(input_data.audio.url, 'rb') as f:
30
+ input_data.audio.base64 = f.read()
31
+ if input_data.text.url and not input_data.text.raw:
25
32
  # Download the text
26
- with fsspec.open(input.data.text.url, 'r') as f:
27
- input.data.text.raw = f.read()
33
+ with fsspec.open(input_data.text.url, 'r') as f:
34
+ input_data.text.raw = f.read()
28
35
 
29
36
 
30
37
  def ensure_urls_downloaded(request, max_threads=128):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 10.10.1
3
+ Version: 10.11.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.9.11
23
+ Requires-Dist: clarifai-grpc>=10.10.2
24
24
  Requires-Dist: clarifai-protocol>=0.0.6
25
25
  Requires-Dist: numpy>=1.22.0
26
26
  Requires-Dist: tqdm>=4.65.0
@@ -1,4 +1,4 @@
1
- clarifai-grpc>=10.9.11
1
+ clarifai-grpc>=10.10.2
2
2
  clarifai-protocol>=0.0.6
3
3
  numpy>=1.22.0
4
4
  tqdm>=4.65.0
@@ -1,2 +1,2 @@
1
1
  [tool.pytest.ini_options]
2
- markers = ["requires_secrets: mark a test as requiring secrets to run"]
2
+ markers = ["requires_secrets: mark a test as requiring secrets to run", "coverage_only: mark a test as required to run for coverage purpose only"]
@@ -1,4 +1,4 @@
1
- clarifai-grpc>=10.9.11
1
+ clarifai-grpc>=10.10.2
2
2
  clarifai-protocol>=0.0.6
3
3
  numpy>=1.22.0
4
4
  tqdm>=4.65.0
@@ -28,21 +28,32 @@ OBJECT_CONCEPT_ID = 'food'
28
28
  PREDICATE = "hypernym"
29
29
 
30
30
  CLARIFAI_PAT = os.environ["CLARIFAI_PAT"]
31
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
31
32
 
32
33
 
33
34
  @pytest.fixture
34
35
  def create_app():
35
- return App(user_id=CREATE_APP_USER_ID, app_id=CREATE_APP_ID, pat=CLARIFAI_PAT)
36
+ return App(
37
+ user_id=CREATE_APP_USER_ID,
38
+ app_id=CREATE_APP_ID,
39
+ pat=CLARIFAI_PAT,
40
+ base_url=CLARIFAI_API_BASE)
36
41
 
37
42
 
38
43
  @pytest.fixture
39
44
  def app():
40
- return App(user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, pat=CLARIFAI_PAT)
45
+ return App(
46
+ user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, pat=CLARIFAI_PAT, base_url=CLARIFAI_API_BASE)
47
+
48
+
49
+ @pytest.fixture
50
+ def create_client():
51
+ return User(user_id=CREATE_APP_USER_ID, pat=CLARIFAI_PAT, base_url=CLARIFAI_API_BASE)
41
52
 
42
53
 
43
54
  @pytest.fixture
44
55
  def client():
45
- return User(user_id=MAIN_APP_USER_ID, pat=CLARIFAI_PAT)
56
+ return User(user_id=MAIN_APP_USER_ID, pat=CLARIFAI_PAT, base_url=CLARIFAI_API_BASE)
46
57
 
47
58
 
48
59
  @pytest.mark.requires_secrets
@@ -60,7 +71,7 @@ class TestApp:
60
71
 
61
72
  def test_list_models(self, app):
62
73
  all_models = list(app.list_models(page_no=1))
63
- assert len(all_models) == 15 #default per_page is 15
74
+ assert len(all_models) >= 15 #default per_page is 16
64
75
 
65
76
  def test_list_workflows(self, app):
66
77
  all_workflows = list(app.list_workflows(page_no=1, per_page=10))
@@ -68,7 +79,7 @@ class TestApp:
68
79
 
69
80
  def test_list_modules(self, app):
70
81
  all_modules = list(app.list_modules())
71
- assert len(all_modules) == 1
82
+ assert len(all_modules) >= 0
72
83
 
73
84
  def test_list_installed_module_versions(self, app):
74
85
  all_installed_module_versions = list(app.list_installed_module_versions())
@@ -95,8 +106,8 @@ class TestApp:
95
106
  assert len(versions) == 1 #test for list_versions
96
107
  assert workflow.id == General_Workflow_ID and workflow.app_id == MAIN_APP_ID and workflow.user_id == MAIN_APP_USER_ID
97
108
 
98
- def test_create_app(self):
99
- app = User(user_id=CREATE_APP_USER_ID, pat=CLARIFAI_PAT).create_app(app_id=CREATE_APP_ID)
109
+ def test_create_app(self, create_client):
110
+ app = create_client.create_app(app_id=CREATE_APP_ID)
100
111
  assert app.id == CREATE_APP_ID and app.user_id == CREATE_APP_USER_ID
101
112
 
102
113
  def test_create_search(self, create_app):
@@ -149,9 +160,9 @@ class TestApp:
149
160
  all_concept_relations = list(create_app.search_concept_relations(show_tree=True))
150
161
  assert len(all_concept_relations) == 1
151
162
 
152
- def test_patch_app(self, caplog):
163
+ def test_patch_app(self, create_client, caplog):
153
164
  with caplog.at_level(logging.INFO):
154
- User(user_id=CREATE_APP_USER_ID).patch_app(
165
+ create_client.patch_app(
155
166
  app_id=CREATE_APP_ID,
156
167
  action='overwrite',
157
168
  default_language='en',
@@ -221,7 +232,7 @@ class TestApp:
221
232
  # client.delete_runner(CREATE_RUNNER_ID)
222
233
  # assert "SUCCESS" in caplog.text
223
234
 
224
- def test_delete_app(self, caplog):
235
+ def test_delete_app(self, caplog, create_client):
225
236
  with caplog.at_level(logging.INFO):
226
- User(user_id=CREATE_APP_USER_ID).delete_app(CREATE_APP_ID)
237
+ create_client.delete_app(CREATE_APP_ID)
227
238
  assert "SUCCESS" in caplog.text
@@ -33,10 +33,11 @@ COCO_DET_DIR = os.path.dirname(__file__) + "/assets/coco_detection"
33
33
  IMAGENET_DIR = os.path.dirname(__file__) + "/assets/imagenet_classification"
34
34
  TEXTS_FOLDER_PATH = os.path.dirname(__file__) + "/assets/sample_texts"
35
35
 
36
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
36
37
 
37
- def create_app():
38
- client = User(user_id=CREATE_APP_USER_ID)
39
- return client.create_app(app_id=CREATE_APP_ID, base_workflow="Empty")
38
+
39
+ def client():
40
+ return User(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
40
41
 
41
42
 
42
43
  @pytest.mark.requires_secrets
@@ -58,7 +59,7 @@ class Testdataupload:
58
59
 
59
60
  @classmethod
60
61
  def setup_class(self):
61
- self.app = create_app()
62
+ self.app = client().create_app(app_id=CREATE_APP_ID, base_workflow="Empty")
62
63
  self.input_object = self.app.inputs()
63
64
  self.dataset = self.app.create_dataset(dataset_id=CREATE_DATASET_ID)
64
65
  self.dataset_new = self.app.create_dataset(dataset_id=CREATE_DATASET_NEW_ID)
@@ -285,4 +286,4 @@ class Testdataupload:
285
286
  @classmethod
286
287
  def teardown_class(self):
287
288
  self.app.delete_dataset(dataset_id=CREATE_DATASET_ID)
288
- User(user_id=CREATE_APP_USER_ID).delete_app(app_id=CREATE_APP_ID)
289
+ client().delete_app(app_id=CREATE_APP_ID)
@@ -17,10 +17,11 @@ CREATE_DATASET_NEW_ID = "ci_input_test_dataset_new"
17
17
  CREATE_MODEL_ID = "ci_input_test_model_1"
18
18
  CSV_FILE_PATH = os.path.dirname(__file__) + "/assets/sample.csv"
19
19
 
20
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
20
21
 
21
- def create_app():
22
- client = User(user_id=CREATE_APP_USER_ID)
23
- return client.create_app(app_id=CREATE_APP_ID, base_workflow="Universal")
22
+
23
+ def client():
24
+ return User(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
24
25
 
25
26
 
26
27
  @pytest.mark.requires_secrets
@@ -30,7 +31,7 @@ class TestEval:
30
31
 
31
32
  @classmethod
32
33
  def setup_class(self):
33
- self.app = create_app()
34
+ self.app = client().create_app(app_id=CREATE_APP_ID, base_workflow="Universal")
34
35
  self.input_object = self.app.inputs()
35
36
  self.dataset = self.app.create_dataset(dataset_id=CREATE_DATASET_ID)
36
37
  self.dataset_new = self.app.create_dataset(dataset_id=CREATE_DATASET_NEW_ID)
@@ -126,4 +127,4 @@ class TestEval:
126
127
  def teardown_class(self):
127
128
  self.app.delete_model(model_id=CREATE_MODEL_ID)
128
129
  self.app.delete_dataset(dataset_id=CREATE_DATASET_ID)
129
- User(user_id=CREATE_APP_USER_ID).delete_app(app_id=CREATE_APP_ID)
130
+ client().delete_app(app_id=CREATE_APP_ID)
@@ -21,12 +21,27 @@ RAW_TEXT = "Hi my name is Jim."
21
21
  RAW_TEXT_BYTES = b"Hi my name is Jim."
22
22
 
23
23
  CLARIFAI_PAT = os.environ["CLARIFAI_PAT"]
24
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
24
25
 
25
26
 
26
27
  @pytest.fixture
27
28
  def model():
28
29
  return Model(
29
- user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, model_id=GENERAL_MODEL_ID, pat=CLARIFAI_PAT)
30
+ user_id=MAIN_APP_USER_ID,
31
+ app_id=MAIN_APP_ID,
32
+ model_id=GENERAL_MODEL_ID,
33
+ pat=CLARIFAI_PAT,
34
+ base_url=CLARIFAI_API_BASE)
35
+
36
+
37
+ @pytest.fixture
38
+ def clip_embed_model():
39
+ return Model(
40
+ user_id=MAIN_APP_USER_ID,
41
+ app_id=MAIN_APP_ID,
42
+ model_id=CLIP_EMBED_MODEL_ID,
43
+ pat=CLARIFAI_PAT,
44
+ base_url=CLARIFAI_API_BASE)
30
45
 
31
46
 
32
47
  def validate_concepts_length(response):
@@ -51,15 +66,13 @@ class TestModelPredict:
51
66
  response = model.predict_by_bytes(image_bytes, 'image')
52
67
  validate_concepts_length(response)
53
68
 
54
- def test_predict_image_url_with_selected_concepts(self):
69
+ def test_predict_image_url_with_selected_concepts(self, model):
55
70
  selected_concepts = [
56
71
  resources_pb2.Concept(name="dog"),
57
72
  resources_pb2.Concept(name="cat"),
58
73
  ]
59
- model_with_selected_concepts = Model(
60
- user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, model_id=GENERAL_MODEL_ID)
61
74
 
62
- response = model_with_selected_concepts.predict_by_url(
75
+ response = model.predict_by_url(
63
76
  DOG_IMAGE_URL, 'image', output_config=dict(select_concepts=selected_concepts))
64
77
  concepts = response.outputs[0].data.concepts
65
78
 
@@ -68,25 +81,14 @@ class TestModelPredict:
68
81
  cat_concept = next(c for c in concepts if c.name == "cat")
69
82
  assert dog_concept.value > cat_concept.value
70
83
 
71
- def test_predict_image_url_with_min_value(self):
72
- model_with_min_value = Model(
73
- user_id=MAIN_APP_USER_ID,
74
- app_id=MAIN_APP_ID,
75
- model_id=GENERAL_MODEL_ID,
76
- )
77
-
78
- response = model_with_min_value.predict_by_url(
79
- DOG_IMAGE_URL, 'image', output_config=dict(min_value=0.98))
84
+ def test_predict_image_url_with_min_value(self, model):
85
+ response = model.predict_by_url(DOG_IMAGE_URL, 'image', output_config=dict(min_value=0.98))
80
86
  assert len(response.outputs[0].data.concepts) > 0
81
87
  for c in response.outputs[0].data.concepts:
82
88
  assert c.value >= 0.98
83
89
 
84
- def test_predict_image_url_with_max_concepts(self):
85
- model_with_max_concepts = Model(
86
- user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, model_id=GENERAL_MODEL_ID)
87
-
88
- response = model_with_max_concepts.predict_by_url(
89
- DOG_IMAGE_URL, 'image', output_config=dict(max_concepts=3))
90
+ def test_predict_image_url_with_max_concepts(self, model):
91
+ response = model.predict_by_url(DOG_IMAGE_URL, 'image', output_config=dict(max_concepts=3))
90
92
  assert len(response.outputs[0].data.concepts) == 3
91
93
 
92
94
  def test_failed_predicts(self, model):
@@ -103,15 +105,9 @@ class TestModelPredict:
103
105
  with pytest.raises(UserError):
104
106
  model.predict_by_url(DOG_IMAGE_URL, 'invalid_input_type')
105
107
 
106
- def test_predict_video_url_with_custom_sample_ms(self):
107
- model_with_custom_sample_ms = Model(
108
- user_id=MAIN_APP_USER_ID,
109
- app_id=MAIN_APP_ID,
110
- model_id=GENERAL_MODEL_ID,
111
- )
108
+ def test_predict_video_url_with_custom_sample_ms(self, model):
112
109
  video_proto = Inputs.get_input_from_url("", video_url=BEER_VIDEO_URL)
113
- response = model_with_custom_sample_ms.predict(
114
- [video_proto], output_config=dict(sample_ms=2000))
110
+ response = model.predict([video_proto], output_config=dict(sample_ms=2000))
115
111
  # The expected time per frame is the middle between the start and the end of the frame
116
112
  # (in milliseconds).
117
113
  expected_time = 1000
@@ -121,11 +117,8 @@ class TestModelPredict:
121
117
  assert frame.frame_info.time == expected_time
122
118
  expected_time += 2000
123
119
 
124
- def test_text_embed_predict_with_raw_text(self):
120
+ def test_text_embed_predict_with_raw_text(self, clip_embed_model):
125
121
  clip_dim = 512
126
- clip_embed_model = Model(
127
- user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, model_id=CLIP_EMBED_MODEL_ID)
128
-
129
122
  input_text_proto = Inputs.get_input_from_bytes(
130
123
  "", text_bytes=RAW_TEXT.encode(encoding='UTF-8'))
131
124
  response = clip_embed_model.predict([input_text_proto])
@@ -134,9 +127,7 @@ class TestModelPredict:
134
127
  response = clip_embed_model.predict([input_text_proto])
135
128
  assert response.outputs[0].data.embeddings[0].num_dimensions == clip_dim
136
129
 
137
- def test_model_load_info(self):
138
- clip_embed_model = Model(
139
- user_id=MAIN_APP_USER_ID, app_id=MAIN_APP_ID, model_id=CLIP_EMBED_MODEL_ID)
130
+ def test_model_load_info(self, clip_embed_model):
140
131
  assert len(clip_embed_model.kwargs) == 4
141
132
  clip_embed_model.load_info()
142
133
  assert len(clip_embed_model.kwargs) > 10
@@ -16,10 +16,11 @@ CREATE_MODEL_ID = "ci_input_test_model"
16
16
  CREATE_MODEL_ID_1 = "ci_input_test_model_1"
17
17
  CSV_FILE_PATH = os.path.dirname(__file__) + "/assets/sample.csv"
18
18
 
19
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
19
20
 
20
- def create_app():
21
- client = User(user_id=CREATE_APP_USER_ID)
22
- return client.create_app(app_id=CREATE_APP_ID, base_workflow="Empty")
21
+
22
+ def client():
23
+ return User(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
23
24
 
24
25
 
25
26
  @pytest.mark.requires_secrets
@@ -29,7 +30,7 @@ class Testmodeltrain:
29
30
 
30
31
  @classmethod
31
32
  def setup_class(self):
32
- self.app = create_app()
33
+ self.app = client().create_app(app_id=CREATE_APP_ID, base_workflow="Empty")
33
34
  self.input_object = self.app.inputs()
34
35
  self.dataset = self.app.create_dataset(dataset_id=CREATE_DATASET_ID)
35
36
  self.visual_classifier_model = self.app.create_model(
@@ -103,4 +104,4 @@ class Testmodeltrain:
103
104
  self.app.delete_dataset(dataset_id=CREATE_DATASET_ID)
104
105
  self.app.delete_model(model_id=CREATE_MODEL_ID)
105
106
  self.app.delete_model(model_id=CREATE_MODEL_ID_1)
106
- User(user_id=CREATE_APP_USER_ID).delete_app(app_id=CREATE_APP_ID)
107
+ client().delete_app(app_id=CREATE_APP_ID)
@@ -13,15 +13,21 @@ CREATE_APP_USER_ID = os.environ["CLARIFAI_USER_ID"]
13
13
  TEXT_FILE_PATH = os.path.dirname(__file__) + "/assets/sample.txt"
14
14
  PDF_URL = "https://samples.clarifai.com/test_doc.pdf"
15
15
 
16
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
17
+
16
18
  auth_obj = namedtuple("auth", "ui")
17
19
 
18
20
 
21
+ def client():
22
+ return User(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
23
+
24
+
19
25
  @pytest.mark.requires_secrets
20
26
  class TestRAG:
21
27
 
22
28
  @classmethod
23
29
  def setup_class(self):
24
- self.rag = RAG.setup(user_id=CREATE_APP_USER_ID)
30
+ self.rag = RAG.setup(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
25
31
  wf = self.rag._prompt_workflow
26
32
  auth = auth_obj(ui="https://clarifai.com")
27
33
  self.workflow_url = ClarifaiUrlHelper(auth).clarifai_url(wf.user_id, wf.app_id, "workflows",
@@ -57,4 +63,4 @@ class TestRAG:
57
63
 
58
64
  @classmethod
59
65
  def teardown_class(self):
60
- User(user_id=CREATE_APP_USER_ID).delete_app(self.rag._app.id)
66
+ client().delete_app(self.rag._app.id)
@@ -16,6 +16,8 @@ CREATE_DATASET_ID = "ci_search_dataset"
16
16
  DOG_IMG_URL = "https://samples.clarifai.com/dog.tiff"
17
17
  DATASET_IMAGES_DIR = os.path.dirname(__file__) + "/assets/voc/images"
18
18
 
19
+ CLARIFAI_API_BASE = os.environ.get("CLARIFAI_API_BASE", "https://api.clarifai.com")
20
+
19
21
 
20
22
  def get_filters_for_test() -> [(typing.List[typing.Dict], int)]:
21
23
  return [
@@ -109,13 +111,25 @@ class TestAnnotationSearch:
109
111
 
110
112
  @classmethod
111
113
  def setup_class(cls):
112
- cls.client = User(user_id=CREATE_APP_USER_ID)
114
+ cls.client = User(user_id=CREATE_APP_USER_ID, base_url=CLARIFAI_API_BASE)
113
115
  cls.search = Search(
114
- user_id=CREATE_APP_USER_ID, app_id=CREATE_APP_ID, top_k=1, metric="euclidean")
116
+ user_id=CREATE_APP_USER_ID,
117
+ app_id=CREATE_APP_ID,
118
+ base_url=CLARIFAI_API_BASE,
119
+ top_k=1,
120
+ metric="euclidean")
115
121
  cls.search_with_pagination = Search(
116
- user_id=CREATE_APP_USER_ID, app_id=CREATE_APP_ID, metric="euclidean", pagination=True)
122
+ user_id=CREATE_APP_USER_ID,
123
+ app_id=CREATE_APP_ID,
124
+ base_url=CLARIFAI_API_BASE,
125
+ metric="euclidean",
126
+ pagination=True)
117
127
  cls.search_deduplicate = Search(
118
- user_id=CREATE_APP_USER_ID, app_id=CREATE_APP_ID, top_k=2, metric="euclidean")
128
+ user_id=CREATE_APP_USER_ID,
129
+ app_id=CREATE_APP_ID,
130
+ base_url=CLARIFAI_API_BASE,
131
+ top_k=2,
132
+ metric="euclidean")
119
133
  cls.upload_data()
120
134
 
121
135
  @classmethod
@@ -1 +0,0 @@
1
- __version__ = "10.10.1"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes