clarifai 10.11.0__py3-none-any.whl → 10.11.2rc1__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/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/model.py +206 -10
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/dataset.py +4 -4
- clarifai/client/model.py +94 -13
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/features.py +1 -1
- clarifai/datasets/upload/multimodal.py +2 -1
- clarifai/datasets/upload/text.py +3 -2
- clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/README.md +158 -0
- clarifai/models/model_serving/__init__.py +14 -0
- clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__init__.py +12 -0
- clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/_utils.py +53 -0
- clarifai/models/model_serving/cli/base.py +14 -0
- clarifai/models/model_serving/cli/build.py +79 -0
- clarifai/models/model_serving/cli/clarifai_clis.py +33 -0
- clarifai/models/model_serving/cli/create.py +171 -0
- clarifai/models/model_serving/cli/example_cli.py +34 -0
- clarifai/models/model_serving/cli/login.py +26 -0
- clarifai/models/model_serving/cli/upload.py +183 -0
- clarifai/models/model_serving/constants.py +21 -0
- clarifai/models/model_serving/docs/cli.md +161 -0
- clarifai/models/model_serving/docs/concepts.md +229 -0
- clarifai/models/model_serving/docs/dependencies.md +11 -0
- clarifai/models/model_serving/docs/inference_parameters.md +139 -0
- clarifai/models/model_serving/docs/model_types.md +19 -0
- clarifai/models/model_serving/model_config/__init__.py +16 -0
- clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/base.py +369 -0
- clarifai/models/model_serving/model_config/config.py +312 -0
- clarifai/models/model_serving/model_config/inference_parameter.py +129 -0
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +25 -0
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +20 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +22 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +32 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +19 -0
- clarifai/models/model_serving/model_config/output.py +133 -0
- clarifai/models/model_serving/model_config/triton/__init__.py +14 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/serializer.py +136 -0
- clarifai/models/model_serving/model_config/triton/triton_config.py +182 -0
- clarifai/models/model_serving/model_config/triton/wrappers.py +281 -0
- clarifai/models/model_serving/repo_build/__init__.py +14 -0
- clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/build.py +198 -0
- clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
- clarifai/models/model_serving/repo_build/static_files/_requirements.txt +2 -0
- clarifai/models/model_serving/repo_build/static_files/base_test.py +169 -0
- clarifai/models/model_serving/repo_build/static_files/inference.py +26 -0
- clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +25 -0
- clarifai/models/model_serving/repo_build/static_files/test.py +40 -0
- clarifai/models/model_serving/repo_build/static_files/triton/model.py +75 -0
- clarifai/models/model_serving/utils.py +31 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/rag/rag.py +6 -2
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
- clarifai/runners/deepgram_live_transcribe.py +98 -0
- clarifai/runners/deepgram_live_transcribe.py~ +98 -0
- clarifai/runners/deepgram_runner.py +131 -0
- clarifai/runners/deepgram_runner.py~ +130 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +79 -0
- clarifai/runners/dockerfile_template/Dockerfile.template +2 -0
- clarifai/runners/example_llama2.py~ +72 -0
- clarifai/runners/matt_example.py +89 -0
- clarifai/runners/matt_example.py~ +87 -0
- clarifai/runners/matt_llm_example.py +129 -0
- clarifai/runners/matt_llm_example.py~ +128 -0
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/model_run_locally.py +358 -33
- clarifai/runners/models/model_upload.py +116 -65
- clarifai/runners/server.py +2 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/const.py +42 -0
- clarifai/runners/utils/loader.py +31 -16
- clarifai/runners/utils/logging.py +6 -0
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/logging.py +7 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- {clarifai-10.11.0.dist-info → clarifai-10.11.2rc1.dist-info}/METADATA +86 -16
- clarifai-10.11.2rc1.dist-info/RECORD +242 -0
- {clarifai-10.11.0.dist-info → clarifai-10.11.2rc1.dist-info}/WHEEL +1 -1
- clarifai-10.11.0.dist-info/RECORD +0 -99
- {clarifai-10.11.0.dist-info → clarifai-10.11.2rc1.dist-info}/LICENSE +0 -0
- {clarifai-10.11.0.dist-info → clarifai-10.11.2rc1.dist-info}/entry_points.txt +0 -0
- {clarifai-10.11.0.dist-info → clarifai-10.11.2rc1.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "10.11.
|
1
|
+
__version__ = "10.11.2rc1"
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/cli/model.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import click
|
2
|
+
|
2
3
|
from clarifai.cli.base import cli
|
3
4
|
|
4
5
|
|
5
6
|
@cli.group(['model'])
|
6
7
|
def model():
|
7
|
-
"""Manage models: upload, test locally"""
|
8
|
+
"""Manage models: upload, test locally, run_locally, predict"""
|
8
9
|
pass
|
9
10
|
|
10
11
|
|
@@ -39,17 +40,43 @@ def upload(model_path, download_checkpoints, skip_dockerfile):
|
|
39
40
|
type=click.Path(exists=True),
|
40
41
|
required=True,
|
41
42
|
help='Path to the model directory.')
|
43
|
+
@click.option(
|
44
|
+
'--mode',
|
45
|
+
type=click.Choice(['env', 'container'], case_sensitive=False),
|
46
|
+
default='env',
|
47
|
+
show_default=True,
|
48
|
+
help=
|
49
|
+
'Specify how to test the model locally: "env" for virtual environment or "container" for Docker container. Defaults to "env".'
|
50
|
+
)
|
42
51
|
@click.option(
|
43
52
|
'--keep_env',
|
44
53
|
is_flag=True,
|
45
|
-
help=
|
46
|
-
|
47
|
-
|
54
|
+
help=
|
55
|
+
'Keep the virtual environment after testing the model locally (applicable for virtualenv mode). Defaults to False.'
|
56
|
+
)
|
57
|
+
@click.option(
|
58
|
+
'--keep_image',
|
59
|
+
is_flag=True,
|
60
|
+
help=
|
61
|
+
'Keep the Docker image after testing the model locally (applicable for container mode). Defaults to False.'
|
62
|
+
)
|
63
|
+
def test_locally(model_path, keep_env=False, keep_image=False, mode='env'):
|
48
64
|
"""Test model locally."""
|
49
65
|
try:
|
50
66
|
from clarifai.runners.models import model_run_locally
|
51
|
-
|
52
|
-
|
67
|
+
if mode == 'env' and keep_image:
|
68
|
+
raise ValueError("'keep_image' is applicable only for 'container' mode")
|
69
|
+
if mode == 'container' and keep_env:
|
70
|
+
raise ValueError("'keep_env' is applicable only for 'env' mode")
|
71
|
+
|
72
|
+
if mode == "env":
|
73
|
+
click.echo("Testing model locally in a virtual environment...")
|
74
|
+
model_run_locally.main(model_path, run_model_server=False, keep_env=keep_env)
|
75
|
+
elif mode == "container":
|
76
|
+
click.echo("Testing model locally inside a container...")
|
77
|
+
model_run_locally.main(
|
78
|
+
model_path, inside_container=True, run_model_server=False, keep_image=keep_image)
|
79
|
+
click.echo("Model tested successfully.")
|
53
80
|
except Exception as e:
|
54
81
|
click.echo(f"Failed to test model locally: {e}", err=True)
|
55
82
|
|
@@ -60,11 +87,180 @@ def test_locally(model_path, keep_env=False):
|
|
60
87
|
type=click.Path(exists=True),
|
61
88
|
required=True,
|
62
89
|
help='Path to the model directory.')
|
63
|
-
|
64
|
-
|
90
|
+
@click.option(
|
91
|
+
'--port',
|
92
|
+
'-p',
|
93
|
+
type=int,
|
94
|
+
default=8000,
|
95
|
+
show_default=True,
|
96
|
+
help="The port to host the gRPC server for running the model locally. Defaults to 8000.")
|
97
|
+
@click.option(
|
98
|
+
'--mode',
|
99
|
+
type=click.Choice(['env', 'container'], case_sensitive=False),
|
100
|
+
default='env',
|
101
|
+
show_default=True,
|
102
|
+
help=
|
103
|
+
'Specifies how to run the model: "env" for virtual environment or "container" for Docker container. Defaults to "env".'
|
104
|
+
)
|
105
|
+
@click.option(
|
106
|
+
'--keep_env',
|
107
|
+
is_flag=True,
|
108
|
+
help=
|
109
|
+
'Keep the virtual environment after testing the model locally (applicable for virtualenv mode). Defaults to False.'
|
110
|
+
)
|
111
|
+
@click.option(
|
112
|
+
'--keep_image',
|
113
|
+
is_flag=True,
|
114
|
+
help=
|
115
|
+
'Keep the Docker image after testing the model locally (applicable for container mode). Defaults to False.'
|
116
|
+
)
|
117
|
+
def run_locally(model_path, port, mode, keep_env, keep_image):
|
118
|
+
"""Run the model locally and start a gRPC server to serve the model."""
|
65
119
|
try:
|
66
120
|
from clarifai.runners.models import model_run_locally
|
67
|
-
|
68
|
-
|
121
|
+
if mode == 'env' and keep_image:
|
122
|
+
raise ValueError("'keep_image' is applicable only for 'container' mode")
|
123
|
+
if mode == 'container' and keep_env:
|
124
|
+
raise ValueError("'keep_env' is applicable only for 'env' mode")
|
125
|
+
|
126
|
+
if mode == "env":
|
127
|
+
click.echo("Running model locally in a virtual environment...")
|
128
|
+
model_run_locally.main(model_path, run_model_server=True, keep_env=keep_env, port=port)
|
129
|
+
elif mode == "container":
|
130
|
+
click.echo("Running model locally inside a container...")
|
131
|
+
model_run_locally.main(
|
132
|
+
model_path,
|
133
|
+
inside_container=True,
|
134
|
+
run_model_server=True,
|
135
|
+
port=port,
|
136
|
+
keep_image=keep_image)
|
137
|
+
click.echo(f"Model server started locally from {model_path} in {mode} mode.")
|
69
138
|
except Exception as e:
|
70
139
|
click.echo(f"Failed to starts model server locally: {e}", err=True)
|
140
|
+
|
141
|
+
|
142
|
+
@model.command()
|
143
|
+
@click.option(
|
144
|
+
'--config',
|
145
|
+
type=click.Path(exists=True),
|
146
|
+
required=False,
|
147
|
+
help='Path to the model predict config file.')
|
148
|
+
@click.option('--model_id', required=False, help='Model ID of the model used to predict.')
|
149
|
+
@click.option('--user_id', required=False, help='User ID of the model used to predict.')
|
150
|
+
@click.option('--app_id', required=False, help='App ID of the model used to predict.')
|
151
|
+
@click.option('--model_url', required=False, help='Model URL of the model used to predict.')
|
152
|
+
@click.option('--file_path', required=False, help='File path of file for the model to predict')
|
153
|
+
@click.option('--url', required=False, help='URL to the file for the model to predict')
|
154
|
+
@click.option('--bytes', required=False, help='Bytes to the file for the model to predict')
|
155
|
+
@click.option(
|
156
|
+
'--input_id', required=False, help='Existing input id in the app for the model to predict')
|
157
|
+
@click.option('--input_type', required=False, help='Type of input')
|
158
|
+
@click.option(
|
159
|
+
'-cc_id',
|
160
|
+
'--compute_cluster_id',
|
161
|
+
required=False,
|
162
|
+
help='Compute Cluster ID to use for the model')
|
163
|
+
@click.option('-np_id', '--nodepool_id', required=False, help='Nodepool ID to use for the model')
|
164
|
+
@click.option(
|
165
|
+
'-dpl_id', '--deployment_id', required=False, help='Deployment ID to use for the model')
|
166
|
+
@click.option(
|
167
|
+
'--inference_params', required=False, default='{}', help='Inference parameters to override')
|
168
|
+
@click.option('--output_config', required=False, default='{}', help='Output config to override')
|
169
|
+
@click.pass_context
|
170
|
+
def predict(ctx, config, model_id, user_id, app_id, model_url, file_path, url, bytes, input_id,
|
171
|
+
input_type, compute_cluster_id, nodepool_id, deployment_id, inference_params,
|
172
|
+
output_config):
|
173
|
+
"""Predict using the given model"""
|
174
|
+
import json
|
175
|
+
|
176
|
+
from clarifai.client.deployment import Deployment
|
177
|
+
from clarifai.client.input import Input
|
178
|
+
from clarifai.client.model import Model
|
179
|
+
from clarifai.client.nodepool import Nodepool
|
180
|
+
from clarifai.utils.cli import from_yaml
|
181
|
+
if config:
|
182
|
+
config = from_yaml(config)
|
183
|
+
model_id, user_id, app_id, model_url, file_path, url, bytes, input_id, input_type, compute_cluster_id, nodepool_id, deployment_id, inference_params, output_config = (
|
184
|
+
config.get(k, v)
|
185
|
+
for k, v in [('model_id', model_id), ('user_id', user_id), ('app_id', app_id), (
|
186
|
+
'model_url', model_url), ('file_path', file_path), ('url', url), ('bytes', bytes), (
|
187
|
+
'input_id',
|
188
|
+
input_id), ('input_type',
|
189
|
+
input_type), ('compute_cluster_id',
|
190
|
+
compute_cluster_id), ('nodepool_id', nodepool_id), (
|
191
|
+
'deployment_id',
|
192
|
+
deployment_id), ('inference_params',
|
193
|
+
inference_params), ('output_config',
|
194
|
+
output_config)])
|
195
|
+
if sum([opt[1] for opt in [(model_id, 1), (user_id, 1), (app_id, 1), (model_url, 3)]
|
196
|
+
if opt[0]]) != 3:
|
197
|
+
raise ValueError("Either --model_id & --user_id & --app_id or --model_url must be provided.")
|
198
|
+
if sum([1 for opt in [file_path, url, bytes, input_id] if opt]) != 1:
|
199
|
+
raise ValueError("Exactly one of --file_path, --url, --bytes or --input_id must be provided.")
|
200
|
+
if compute_cluster_id or nodepool_id or deployment_id:
|
201
|
+
if sum([
|
202
|
+
opt[1] for opt in [(compute_cluster_id, 0.5), (nodepool_id, 0.5), (deployment_id, 1)]
|
203
|
+
if opt[0]
|
204
|
+
]) != 1:
|
205
|
+
raise ValueError(
|
206
|
+
"Either --compute_cluster_id & --nodepool_id or --deployment_id must be provided.")
|
207
|
+
if model_url:
|
208
|
+
model = Model(url=model_url, pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
|
209
|
+
else:
|
210
|
+
model = Model(
|
211
|
+
model_id=model_id,
|
212
|
+
user_id=user_id,
|
213
|
+
app_id=app_id,
|
214
|
+
pat=ctx.obj['pat'],
|
215
|
+
base_url=ctx.obj['base_url'])
|
216
|
+
|
217
|
+
if inference_params:
|
218
|
+
inference_params = json.loads(inference_params)
|
219
|
+
if output_config:
|
220
|
+
output_config = json.loads(output_config)
|
221
|
+
|
222
|
+
if file_path:
|
223
|
+
model_prediction = model.predict_by_filepath(
|
224
|
+
filepath=file_path,
|
225
|
+
input_type=input_type,
|
226
|
+
compute_cluster_id=compute_cluster_id,
|
227
|
+
nodepool_id=nodepool_id,
|
228
|
+
deployment_id=deployment_id,
|
229
|
+
inference_params=inference_params,
|
230
|
+
output_config=output_config)
|
231
|
+
elif url:
|
232
|
+
model_prediction = model.predict_by_url(
|
233
|
+
url=url,
|
234
|
+
input_type=input_type,
|
235
|
+
compute_cluster_id=compute_cluster_id,
|
236
|
+
nodepool_id=nodepool_id,
|
237
|
+
deployment_id=deployment_id,
|
238
|
+
inference_params=inference_params,
|
239
|
+
output_config=output_config)
|
240
|
+
elif bytes:
|
241
|
+
bytes = str.encode(bytes)
|
242
|
+
model_prediction = model.predict_by_bytes(
|
243
|
+
input_bytes=bytes,
|
244
|
+
input_type=input_type,
|
245
|
+
compute_cluster_id=compute_cluster_id,
|
246
|
+
nodepool_id=nodepool_id,
|
247
|
+
deployment_id=deployment_id,
|
248
|
+
inference_params=inference_params,
|
249
|
+
output_config=output_config)
|
250
|
+
elif input_id:
|
251
|
+
inputs = [Input.get_input(input_id)]
|
252
|
+
runner_selector = None
|
253
|
+
if deployment_id:
|
254
|
+
runner_selector = Deployment.get_runner_selector(
|
255
|
+
user_id=ctx.obj['user_id'], deployment_id=deployment_id)
|
256
|
+
elif compute_cluster_id and nodepool_id:
|
257
|
+
runner_selector = Nodepool.get_runner_selector(
|
258
|
+
user_id=ctx.obj['user_id'],
|
259
|
+
compute_cluster_id=compute_cluster_id,
|
260
|
+
nodepool_id=nodepool_id)
|
261
|
+
model_prediction = model.predict(
|
262
|
+
inputs=inputs,
|
263
|
+
runner_selector=runner_selector,
|
264
|
+
inference_params=inference_params,
|
265
|
+
output_config=output_config)
|
266
|
+
click.echo(model_prediction)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/client/dataset.py
CHANGED
@@ -281,9 +281,9 @@ class Dataset(Lister, BaseClient):
|
|
281
281
|
failed_input_ids = list(set(failed_input_ids) - set(duplicate_input_ids))
|
282
282
|
duplicate_details = [[
|
283
283
|
input_ids[id], id, "Input has a duplicate ID.",
|
284
|
-
dataset_obj.data_generator[input_ids[id]]
|
285
|
-
dataset_obj.data_generator[input_ids[id]]
|
286
|
-
dataset_obj.data_generator[input_ids[id]]
|
284
|
+
getattr(dataset_obj.data_generator[input_ids[id]], 'image_path', None),
|
285
|
+
getattr(dataset_obj.data_generator[input_ids[id]], 'labels', None),
|
286
|
+
getattr(dataset_obj.data_generator[input_ids[id]], 'metadata', None)
|
287
287
|
] for id in duplicate_input_ids]
|
288
288
|
duplicate_table = tabulate(
|
289
289
|
duplicate_details,
|
@@ -386,7 +386,7 @@ class Dataset(Lister, BaseClient):
|
|
386
386
|
tablefmt="grid")
|
387
387
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
388
388
|
self.logger.warning(
|
389
|
-
f"{timestamp}\nFailed to upload {len(failed_retrying_inputs)} inputs in current batch {batch_no}:\n{failed_table}\n\n"
|
389
|
+
f"{timestamp}\nFailed to upload {len(failed_retrying_inputs)} inputs in current batch {batch_no} due to {retry_response}:\n{failed_table}\n\n"
|
390
390
|
)
|
391
391
|
|
392
392
|
def _data_upload(self,
|
clarifai/client/model.py
CHANGED
@@ -503,6 +503,7 @@ class Model(Lister, BaseClient):
|
|
503
503
|
compute_cluster_id: str = None,
|
504
504
|
nodepool_id: str = None,
|
505
505
|
deployment_id: str = None,
|
506
|
+
user_id: str = None,
|
506
507
|
inference_params: Dict = {},
|
507
508
|
output_config: Dict = {}):
|
508
509
|
"""Predicts the model based on the given filepath.
|
@@ -534,7 +535,7 @@ class Model(Lister, BaseClient):
|
|
534
535
|
file_bytes = f.read()
|
535
536
|
|
536
537
|
return self.predict_by_bytes(file_bytes, input_type, compute_cluster_id, nodepool_id,
|
537
|
-
deployment_id, inference_params, output_config)
|
538
|
+
deployment_id, user_id, inference_params, output_config)
|
538
539
|
|
539
540
|
def predict_by_bytes(self,
|
540
541
|
input_bytes: bytes,
|
@@ -542,6 +543,7 @@ class Model(Lister, BaseClient):
|
|
542
543
|
compute_cluster_id: str = None,
|
543
544
|
nodepool_id: str = None,
|
544
545
|
deployment_id: str = None,
|
546
|
+
user_id: str = None,
|
545
547
|
inference_params: Dict = {},
|
546
548
|
output_config: Dict = {}):
|
547
549
|
"""Predicts the model based on the given bytes.
|
@@ -581,11 +583,23 @@ class Model(Lister, BaseClient):
|
|
581
583
|
|
582
584
|
runner_selector = None
|
583
585
|
if deployment_id:
|
586
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
587
|
+
raise UserError(
|
588
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
589
|
+
)
|
590
|
+
if not user_id:
|
591
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
584
592
|
runner_selector = Deployment.get_runner_selector(
|
585
|
-
user_id=
|
593
|
+
user_id=user_id, deployment_id=deployment_id)
|
586
594
|
elif compute_cluster_id and nodepool_id:
|
595
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
596
|
+
raise UserError(
|
597
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
598
|
+
)
|
599
|
+
if not user_id:
|
600
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
587
601
|
runner_selector = Nodepool.get_runner_selector(
|
588
|
-
user_id=
|
602
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
589
603
|
|
590
604
|
return self.predict(
|
591
605
|
inputs=[input_proto],
|
@@ -599,6 +613,7 @@ class Model(Lister, BaseClient):
|
|
599
613
|
compute_cluster_id: str = None,
|
600
614
|
nodepool_id: str = None,
|
601
615
|
deployment_id: str = None,
|
616
|
+
user_id: str = None,
|
602
617
|
inference_params: Dict = {},
|
603
618
|
output_config: Dict = {}):
|
604
619
|
"""Predicts the model based on the given URL.
|
@@ -639,11 +654,23 @@ class Model(Lister, BaseClient):
|
|
639
654
|
|
640
655
|
runner_selector = None
|
641
656
|
if deployment_id:
|
657
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
658
|
+
raise UserError(
|
659
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
660
|
+
)
|
661
|
+
if not user_id:
|
662
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
642
663
|
runner_selector = Deployment.get_runner_selector(
|
643
|
-
user_id=
|
664
|
+
user_id=user_id, deployment_id=deployment_id)
|
644
665
|
elif compute_cluster_id and nodepool_id:
|
666
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
667
|
+
raise UserError(
|
668
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
669
|
+
)
|
670
|
+
if not user_id:
|
671
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
645
672
|
runner_selector = Nodepool.get_runner_selector(
|
646
|
-
user_id=
|
673
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
647
674
|
|
648
675
|
return self.predict(
|
649
676
|
inputs=[input_proto],
|
@@ -712,6 +739,7 @@ class Model(Lister, BaseClient):
|
|
712
739
|
compute_cluster_id: str = None,
|
713
740
|
nodepool_id: str = None,
|
714
741
|
deployment_id: str = None,
|
742
|
+
user_id: str = None,
|
715
743
|
inference_params: Dict = {},
|
716
744
|
output_config: Dict = {}):
|
717
745
|
"""Generate the stream output on model based on the given filepath.
|
@@ -748,6 +776,7 @@ class Model(Lister, BaseClient):
|
|
748
776
|
compute_cluster_id=compute_cluster_id,
|
749
777
|
nodepool_id=nodepool_id,
|
750
778
|
deployment_id=deployment_id,
|
779
|
+
user_id=user_id,
|
751
780
|
inference_params=inference_params,
|
752
781
|
output_config=output_config)
|
753
782
|
|
@@ -757,6 +786,7 @@ class Model(Lister, BaseClient):
|
|
757
786
|
compute_cluster_id: str = None,
|
758
787
|
nodepool_id: str = None,
|
759
788
|
deployment_id: str = None,
|
789
|
+
user_id: str = None,
|
760
790
|
inference_params: Dict = {},
|
761
791
|
output_config: Dict = {}):
|
762
792
|
"""Generate the stream output on model based on the given bytes.
|
@@ -798,11 +828,21 @@ class Model(Lister, BaseClient):
|
|
798
828
|
|
799
829
|
runner_selector = None
|
800
830
|
if deployment_id:
|
831
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
832
|
+
raise UserError(
|
833
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
834
|
+
)
|
801
835
|
runner_selector = Deployment.get_runner_selector(
|
802
|
-
user_id=
|
836
|
+
user_id=user_id, deployment_id=deployment_id)
|
803
837
|
elif compute_cluster_id and nodepool_id:
|
838
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
839
|
+
raise UserError(
|
840
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
841
|
+
)
|
842
|
+
if not user_id:
|
843
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
804
844
|
runner_selector = Nodepool.get_runner_selector(
|
805
|
-
user_id=
|
845
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
806
846
|
|
807
847
|
return self.generate(
|
808
848
|
inputs=[input_proto],
|
@@ -816,6 +856,7 @@ class Model(Lister, BaseClient):
|
|
816
856
|
compute_cluster_id: str = None,
|
817
857
|
nodepool_id: str = None,
|
818
858
|
deployment_id: str = None,
|
859
|
+
user_id: str = None,
|
819
860
|
inference_params: Dict = {},
|
820
861
|
output_config: Dict = {}):
|
821
862
|
"""Generate the stream output on model based on the given URL.
|
@@ -857,11 +898,23 @@ class Model(Lister, BaseClient):
|
|
857
898
|
|
858
899
|
runner_selector = None
|
859
900
|
if deployment_id:
|
901
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
902
|
+
raise UserError(
|
903
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
904
|
+
)
|
905
|
+
if not user_id:
|
906
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
860
907
|
runner_selector = Deployment.get_runner_selector(
|
861
|
-
user_id=
|
908
|
+
user_id=user_id, deployment_id=deployment_id)
|
862
909
|
elif compute_cluster_id and nodepool_id:
|
910
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
911
|
+
raise UserError(
|
912
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
913
|
+
)
|
914
|
+
if not user_id:
|
915
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
863
916
|
runner_selector = Nodepool.get_runner_selector(
|
864
|
-
user_id=
|
917
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
865
918
|
|
866
919
|
return self.generate(
|
867
920
|
inputs=[input_proto],
|
@@ -930,6 +983,7 @@ class Model(Lister, BaseClient):
|
|
930
983
|
compute_cluster_id: str = None,
|
931
984
|
nodepool_id: str = None,
|
932
985
|
deployment_id: str = None,
|
986
|
+
user_id: str = None,
|
933
987
|
inference_params: Dict = {},
|
934
988
|
output_config: Dict = {}):
|
935
989
|
"""Stream the model output based on the given filepath.
|
@@ -964,6 +1018,7 @@ class Model(Lister, BaseClient):
|
|
964
1018
|
compute_cluster_id=compute_cluster_id,
|
965
1019
|
nodepool_id=nodepool_id,
|
966
1020
|
deployment_id=deployment_id,
|
1021
|
+
user_id=user_id,
|
967
1022
|
inference_params=inference_params,
|
968
1023
|
output_config=output_config)
|
969
1024
|
|
@@ -973,6 +1028,7 @@ class Model(Lister, BaseClient):
|
|
973
1028
|
compute_cluster_id: str = None,
|
974
1029
|
nodepool_id: str = None,
|
975
1030
|
deployment_id: str = None,
|
1031
|
+
user_id: str = None,
|
976
1032
|
inference_params: Dict = {},
|
977
1033
|
output_config: Dict = {}):
|
978
1034
|
"""Stream the model output based on the given bytes.
|
@@ -1016,11 +1072,23 @@ class Model(Lister, BaseClient):
|
|
1016
1072
|
|
1017
1073
|
runner_selector = None
|
1018
1074
|
if deployment_id:
|
1075
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
1076
|
+
raise UserError(
|
1077
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
1078
|
+
)
|
1079
|
+
if not user_id:
|
1080
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
1019
1081
|
runner_selector = Deployment.get_runner_selector(
|
1020
|
-
user_id=
|
1082
|
+
user_id=user_id, deployment_id=deployment_id)
|
1021
1083
|
elif compute_cluster_id and nodepool_id:
|
1084
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
1085
|
+
raise UserError(
|
1086
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
1087
|
+
)
|
1088
|
+
if not user_id:
|
1089
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
1022
1090
|
runner_selector = Nodepool.get_runner_selector(
|
1023
|
-
user_id=
|
1091
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
1024
1092
|
|
1025
1093
|
return self.stream(
|
1026
1094
|
inputs=input_generator(),
|
@@ -1034,6 +1102,7 @@ class Model(Lister, BaseClient):
|
|
1034
1102
|
compute_cluster_id: str = None,
|
1035
1103
|
nodepool_id: str = None,
|
1036
1104
|
deployment_id: str = None,
|
1105
|
+
user_id: str = None,
|
1037
1106
|
inference_params: Dict = {},
|
1038
1107
|
output_config: Dict = {}):
|
1039
1108
|
"""Stream the model output based on the given URL.
|
@@ -1075,11 +1144,23 @@ class Model(Lister, BaseClient):
|
|
1075
1144
|
|
1076
1145
|
runner_selector = None
|
1077
1146
|
if deployment_id:
|
1147
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
1148
|
+
raise UserError(
|
1149
|
+
"User ID is required for model prediction with deployment ID, please provide user_id in the method call."
|
1150
|
+
)
|
1151
|
+
if not user_id:
|
1152
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
1078
1153
|
runner_selector = Deployment.get_runner_selector(
|
1079
|
-
user_id=
|
1154
|
+
user_id=user_id, deployment_id=deployment_id)
|
1080
1155
|
elif compute_cluster_id and nodepool_id:
|
1156
|
+
if not user_id and not os.environ.get('CLARIFAI_USER_ID'):
|
1157
|
+
raise UserError(
|
1158
|
+
"User ID is required for model prediction with compute cluster ID and nodepool ID, please provide user_id in the method call."
|
1159
|
+
)
|
1160
|
+
if not user_id:
|
1161
|
+
user_id = os.environ.get('CLARIFAI_USER_ID')
|
1081
1162
|
runner_selector = Nodepool.get_runner_selector(
|
1082
|
-
user_id=
|
1163
|
+
user_id=user_id, compute_cluster_id=compute_cluster_id, nodepool_id=nodepool_id)
|
1083
1164
|
|
1084
1165
|
return self.stream(
|
1085
1166
|
inputs=input_generator(),
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -7,7 +7,7 @@ from typing import List, Optional, Union
|
|
7
7
|
class TextFeatures:
|
8
8
|
"""Text classification datasets preprocessing output features."""
|
9
9
|
text: str
|
10
|
-
labels: List[Union[str, int]] # List[str or int] to cater for multi-class tasks
|
10
|
+
labels: List[Union[str, int]] = None # List[str or int] to cater for multi-class tasks
|
11
11
|
id: Optional[int] = None # text_id
|
12
12
|
metadata: Optional[dict] = None
|
13
13
|
label_ids: Optional[List[str]] = None
|
@@ -34,7 +34,8 @@ class MultiModalDataset(ClarifaiDataset):
|
|
34
34
|
metadata = Struct()
|
35
35
|
image_bytes = data_item.image_bytes
|
36
36
|
text = data_item.text
|
37
|
-
labels = data_item.labels if
|
37
|
+
labels = data_item.labels if ((data_item.labels is None) or
|
38
|
+
isinstance(data_item.labels, list)) else [data_item.labels]
|
38
39
|
input_id = f"{self.dataset_id}-{id}" if data_item.id is None else f"{self.dataset_id}-{str(data_item.id)}"
|
39
40
|
if data_item.metadata is not None:
|
40
41
|
metadata.update(data_item.metadata)
|
clarifai/datasets/upload/text.py
CHANGED
@@ -34,8 +34,9 @@ class TextClassificationDataset(ClarifaiDataset):
|
|
34
34
|
data_item = self.data_generator[id]
|
35
35
|
metadata = Struct()
|
36
36
|
text = data_item.text
|
37
|
-
labels = data_item.labels if
|
38
|
-
|
37
|
+
labels = data_item.labels if ((data_item.labels is None) or
|
38
|
+
isinstance(data_item.labels, list)) else [data_item.labels
|
39
|
+
] # clarifai concept
|
39
40
|
label_ids = data_item.label_ids
|
40
41
|
input_id = f"{self.dataset_id}-{get_uuid(8)}" if data_item.id is None else f"{self.dataset_id}-{str(data_item.id)}"
|
41
42
|
if data_item.metadata is not None:
|
Binary file
|