clarifai 11.3.0rc2__py3-none-any.whl → 11.4.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 +1 -1
- clarifai/cli/__main__.py +1 -1
- clarifai/cli/base.py +144 -136
- clarifai/cli/compute_cluster.py +45 -31
- clarifai/cli/deployment.py +93 -76
- clarifai/cli/model.py +578 -180
- clarifai/cli/nodepool.py +100 -82
- clarifai/client/__init__.py +12 -2
- clarifai/client/app.py +973 -911
- clarifai/client/auth/helper.py +345 -342
- clarifai/client/auth/register.py +7 -7
- clarifai/client/auth/stub.py +107 -106
- clarifai/client/base.py +185 -178
- clarifai/client/compute_cluster.py +214 -180
- clarifai/client/dataset.py +793 -698
- clarifai/client/deployment.py +55 -50
- clarifai/client/input.py +1223 -1088
- clarifai/client/lister.py +47 -45
- clarifai/client/model.py +1939 -1717
- clarifai/client/model_client.py +525 -502
- clarifai/client/module.py +82 -73
- clarifai/client/nodepool.py +358 -213
- clarifai/client/runner.py +58 -0
- clarifai/client/search.py +342 -309
- clarifai/client/user.py +419 -414
- clarifai/client/workflow.py +294 -274
- clarifai/constants/dataset.py +11 -17
- clarifai/constants/model.py +8 -2
- clarifai/datasets/export/inputs_annotations.py +233 -217
- clarifai/datasets/upload/base.py +63 -51
- clarifai/datasets/upload/features.py +43 -38
- clarifai/datasets/upload/image.py +237 -207
- clarifai/datasets/upload/loaders/coco_captions.py +34 -32
- clarifai/datasets/upload/loaders/coco_detection.py +72 -65
- clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
- clarifai/datasets/upload/loaders/xview_detection.py +274 -132
- clarifai/datasets/upload/multimodal.py +55 -46
- clarifai/datasets/upload/text.py +55 -47
- clarifai/datasets/upload/utils.py +250 -234
- clarifai/errors.py +51 -50
- clarifai/models/api.py +260 -238
- clarifai/modules/css.py +50 -50
- clarifai/modules/pages.py +33 -33
- clarifai/rag/rag.py +312 -288
- clarifai/rag/utils.py +91 -84
- clarifai/runners/models/model_builder.py +906 -802
- clarifai/runners/models/model_class.py +370 -331
- clarifai/runners/models/model_run_locally.py +459 -419
- clarifai/runners/models/model_runner.py +170 -162
- clarifai/runners/models/model_servicer.py +78 -70
- clarifai/runners/server.py +111 -101
- clarifai/runners/utils/code_script.py +225 -187
- clarifai/runners/utils/const.py +4 -1
- clarifai/runners/utils/data_types/__init__.py +12 -0
- clarifai/runners/utils/data_types/data_types.py +598 -0
- clarifai/runners/utils/data_utils.py +387 -440
- clarifai/runners/utils/loader.py +247 -227
- clarifai/runners/utils/method_signatures.py +411 -386
- clarifai/runners/utils/openai_convertor.py +108 -109
- clarifai/runners/utils/serializers.py +175 -179
- clarifai/runners/utils/url_fetcher.py +35 -35
- clarifai/schema/search.py +56 -63
- clarifai/urls/helper.py +125 -102
- clarifai/utils/cli.py +129 -123
- clarifai/utils/config.py +127 -87
- clarifai/utils/constants.py +49 -0
- clarifai/utils/evaluation/helpers.py +503 -466
- clarifai/utils/evaluation/main.py +431 -393
- clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
- clarifai/utils/logging.py +324 -306
- clarifai/utils/misc.py +60 -56
- clarifai/utils/model_train.py +165 -146
- clarifai/utils/protobuf.py +126 -103
- clarifai/versions.py +3 -1
- clarifai/workflows/export.py +48 -50
- clarifai/workflows/utils.py +39 -36
- clarifai/workflows/validate.py +55 -43
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
- clarifai-11.4.0.dist-info/RECORD +109 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-311.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
- clarifai/client/cli/__init__.py +0 -0
- clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/base_cli.py +0 -88
- clarifai/client/cli/model_cli.py +0 -29
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
- clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/base_typed_model.py +0 -238
- clarifai/runners/models/model_class_refract.py +0 -80
- clarifai/runners/models/model_upload.py +0 -607
- clarifai/runners/models/temp.py +0 -25
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_handler.py +0 -231
- clarifai/runners/utils/data_handler_refract.py +0 -213
- clarifai/runners/utils/data_types.py +0 -469
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/openai_format.py +0 -87
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
- clarifai-11.3.0rc2.dist-info/RECORD +0 -322
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
@@ -1,217 +1,255 @@
|
|
1
1
|
import json
|
2
2
|
from typing import List
|
3
|
+
|
3
4
|
from clarifai_grpc.grpc.api import resources_pb2
|
5
|
+
|
4
6
|
from clarifai.runners.utils import data_types
|
5
7
|
|
6
8
|
|
7
|
-
def generate_client_script(
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def generate_client_script(
|
10
|
+
method_signatures: List[resources_pb2.MethodSignature],
|
11
|
+
user_id,
|
12
|
+
app_id,
|
13
|
+
model_id,
|
14
|
+
base_url: str = None,
|
15
|
+
deployment_id: str = None,
|
16
|
+
use_ctx: bool = False,
|
17
|
+
) -> str:
|
18
|
+
_CLIENT_TEMPLATE = """\
|
11
19
|
import os
|
12
|
-
from clarifai.client import Model
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
from clarifai.client import Model
|
22
|
+
from clarifai.runners.utils import data_types
|
23
|
+
{model_section}
|
17
24
|
"""
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
25
|
+
|
26
|
+
deployment_id = (
|
27
|
+
"os.environ['CLARIFAI_DEPLOYMENT_ID']" if deployment_id is None else deployment_id
|
28
|
+
)
|
29
|
+
|
30
|
+
base_url_str = ""
|
31
|
+
if base_url is not None:
|
32
|
+
base_url_str = f"base_url={base_url},"
|
33
|
+
|
34
|
+
if use_ctx:
|
35
|
+
model_section = """
|
36
|
+
model = Model.from_current_context()"""
|
37
|
+
else:
|
38
|
+
model_section = """
|
39
|
+
model = Model("https://clarifai.com/{user_id}/{app_id}/{model_id}",
|
40
|
+
deployment_id = {deployment_id}, # Only needed for dedicated deployed models
|
41
|
+
{base_url_str}
|
42
|
+
)
|
43
|
+
"""
|
44
|
+
model_section = _CLIENT_TEMPLATE.format(
|
45
|
+
user_id=user_id,
|
46
|
+
app_id=app_id,
|
47
|
+
model_id=model_id,
|
48
|
+
deployment_id=deployment_id,
|
49
|
+
base_url_str=base_url_str,
|
50
|
+
)
|
51
|
+
|
52
|
+
# Generate client template
|
53
|
+
client_template = _CLIENT_TEMPLATE.format(
|
54
|
+
model_section=model_section,
|
55
|
+
)
|
56
|
+
|
57
|
+
# Generate method signatures
|
58
|
+
method_signatures_str = []
|
59
|
+
for method_signature in method_signatures:
|
60
|
+
method_name = method_signature.name
|
61
|
+
if method_signature.method_type in [
|
62
|
+
resources_pb2.RunnerMethodType.UNARY_UNARY,
|
63
|
+
resources_pb2.RunnerMethodType.UNARY_STREAMING,
|
64
|
+
]:
|
65
|
+
client_script_str = f'response = model.{method_name}('
|
66
|
+
annotations = _get_annotations_source(method_signature)
|
67
|
+
for param_name, (param_type, default_value) in annotations.items():
|
68
|
+
if param_name == "return":
|
69
|
+
continue
|
70
|
+
if default_value is None:
|
71
|
+
default_value = _set_default_value(param_type)
|
72
|
+
if param_type == "str":
|
73
|
+
default_value = repr(default_value)
|
74
|
+
|
75
|
+
client_script_str += f"{param_name}={default_value}, "
|
76
|
+
client_script_str = client_script_str.rstrip(", ") + ")"
|
77
|
+
if method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_UNARY:
|
78
|
+
client_script_str += "\nprint(response)"
|
79
|
+
elif method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_STREAMING:
|
80
|
+
client_script_str += "\nfor res in response:\n print(res)"
|
81
|
+
client_script_str += "\n"
|
82
|
+
method_signatures_str.append(client_script_str)
|
83
|
+
|
84
|
+
method_signatures_str = "\n".join(method_signatures_str)
|
85
|
+
# Combine all parts
|
86
|
+
script_lines = []
|
87
|
+
script_lines.append("\n# Clarifai Model Client Script")
|
88
|
+
if not use_ctx:
|
89
|
+
script_lines.append(
|
90
|
+
"# Set the environment variables `CLARIFAI_DEPLOYMENT_ID` and `CLARIFAI_PAT` to run this script."
|
91
|
+
)
|
92
|
+
script_lines.append("# Example usage:")
|
93
|
+
script_lines.append(client_template)
|
94
|
+
script_lines.append("# Example model prediction from different model methods: \n")
|
95
|
+
script_lines.append(method_signatures_str)
|
96
|
+
script_lines.append("")
|
97
|
+
script = "\n".join(script_lines)
|
98
|
+
return script
|
63
99
|
|
64
100
|
|
65
101
|
# get annotations source with default values
|
66
102
|
def _get_annotations_source(method_signature: resources_pb2.MethodSignature) -> dict:
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
103
|
+
annotations = {}
|
104
|
+
for input_field in method_signature.input_fields:
|
105
|
+
param_name = input_field.name
|
106
|
+
param_type = _get_base_type(input_field)
|
107
|
+
if input_field.iterator:
|
108
|
+
param_type = f"Iterator[{param_type}]"
|
109
|
+
default_value = None
|
110
|
+
if input_field.default:
|
111
|
+
default_value = _parse_default_value(input_field)
|
112
|
+
|
113
|
+
annotations[param_name] = (param_type, default_value)
|
114
|
+
if not method_signature.output_fields:
|
115
|
+
raise ValueError("MethodSignature must have at least one output field")
|
116
|
+
for output_field in method_signature.output_fields:
|
117
|
+
param_name = output_field.name
|
118
|
+
param_type = _get_base_type(output_field)
|
119
|
+
if output_field.iterator:
|
120
|
+
param_type = f"Iterator[{param_type}]"
|
121
|
+
annotations[param_name] = (param_type, None)
|
122
|
+
return annotations
|
87
123
|
|
88
124
|
|
89
125
|
def _get_base_type(field: resources_pb2.ModelTypeField) -> str:
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
126
|
+
data_type = field.type
|
127
|
+
if data_type == resources_pb2.ModelTypeField.DataType.NAMED_FIELDS:
|
128
|
+
annotations = {}
|
129
|
+
for type_arg in field.type_args:
|
130
|
+
field_name = type_arg.name
|
131
|
+
field_type = _get_base_type(type_arg)
|
132
|
+
annotations[field_name] = field_type
|
133
|
+
class_name = f"NamedFields[{', '.join(f'{k}: {v}' for k, v in annotations.items())}]"
|
134
|
+
return class_name
|
135
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.TUPLE:
|
136
|
+
type_args_str = [_get_base_type(ta) for ta in field.type_args]
|
137
|
+
return f"Tuple[{', '.join(type_args_str)}]"
|
138
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.LIST:
|
139
|
+
if len(field.type_args) != 1:
|
140
|
+
raise ValueError("List type must have exactly one type argument")
|
141
|
+
element_type = _get_base_type(field.type_args[0])
|
142
|
+
return f"List[{element_type}]"
|
143
|
+
else:
|
144
|
+
type_map = {
|
145
|
+
resources_pb2.ModelTypeField.DataType.STR: "str",
|
146
|
+
resources_pb2.ModelTypeField.DataType.BYTES: "bytes",
|
147
|
+
resources_pb2.ModelTypeField.DataType.INT: "int",
|
148
|
+
resources_pb2.ModelTypeField.DataType.FLOAT: "float",
|
149
|
+
resources_pb2.ModelTypeField.DataType.BOOL: "bool",
|
150
|
+
resources_pb2.ModelTypeField.DataType.NDARRAY: "np.ndarray",
|
151
|
+
resources_pb2.ModelTypeField.DataType.JSON_DATA: "data_types.JSON",
|
152
|
+
resources_pb2.ModelTypeField.DataType.TEXT: "data_types.Text",
|
153
|
+
resources_pb2.ModelTypeField.DataType.IMAGE: "data_types.Image",
|
154
|
+
resources_pb2.ModelTypeField.DataType.CONCEPT: "data_types.Concept",
|
155
|
+
resources_pb2.ModelTypeField.DataType.REGION: "data_types.Region",
|
156
|
+
resources_pb2.ModelTypeField.DataType.FRAME: "data_types.Frame",
|
157
|
+
resources_pb2.ModelTypeField.DataType.AUDIO: "data_types.Audio",
|
158
|
+
resources_pb2.ModelTypeField.DataType.VIDEO: "data_types.Video",
|
159
|
+
}
|
160
|
+
return type_map.get(data_type, "Any")
|
125
161
|
|
126
162
|
|
127
163
|
def _map_default_value(field_type):
|
128
|
-
|
164
|
+
"""
|
129
165
|
Map the default value of a field type to a string representation.
|
130
166
|
"""
|
131
|
-
default_value = None
|
132
|
-
|
133
|
-
if field_type == "str":
|
134
|
-
default_value = 'What is the future of AI?'
|
135
|
-
elif field_type == "bytes":
|
136
|
-
default_value = b""
|
137
|
-
elif field_type == "int":
|
138
|
-
default_value = 0
|
139
|
-
elif field_type == "float":
|
140
|
-
default_value = 0.0
|
141
|
-
elif field_type == "bool":
|
142
|
-
default_value = False
|
143
|
-
elif field_type == "data_types.Image":
|
144
|
-
default_value = data_types.Image.from_url("https://samples.clarifai.com/metro-north.jpg")
|
145
|
-
elif field_type == "data_types.Text":
|
146
|
-
default_value = data_types.Text("What's the future of AI?")
|
147
|
-
elif field_type == "data_types.Audio":
|
148
|
-
default_value = data_types.Audio.from_url("https://samples.clarifai.com/audio.mp3")
|
149
|
-
elif field_type == "data_types.Video":
|
150
|
-
default_value = data_types.Video.from_url("https://samples.clarifai.com/video.mp4")
|
151
|
-
elif field_type == "data_types.Concept":
|
152
|
-
default_value = data_types.Concept(id="concept_id", name="dog", value=0.95)
|
153
|
-
elif field_type == "data_types.Region":
|
154
|
-
default_value = data_types.Region(box=[0.1, 0.1, 0.5, 0.5],)
|
155
|
-
elif field_type == "data_types.Frame":
|
156
|
-
default_value = data_types.Frame.from_url("https://samples.clarifai.com/video.mp4", 0)
|
157
|
-
elif field_type == "data_types.NDArray":
|
158
|
-
default_value = data_types.NDArray([1, 2, 3])
|
159
|
-
else:
|
160
167
|
default_value = None
|
161
|
-
|
168
|
+
|
169
|
+
if field_type == "str":
|
170
|
+
default_value = 'What is the future of AI?'
|
171
|
+
elif field_type == "bytes":
|
172
|
+
default_value = b""
|
173
|
+
elif field_type == "int":
|
174
|
+
default_value = 0
|
175
|
+
elif field_type == "float":
|
176
|
+
default_value = 0.0
|
177
|
+
elif field_type == "bool":
|
178
|
+
default_value = False
|
179
|
+
elif field_type == "data_types.Image":
|
180
|
+
default_value = data_types.Image.from_url("https://samples.clarifai.com/metro-north.jpg")
|
181
|
+
elif field_type == "data_types.Text":
|
182
|
+
default_value = data_types.Text("What's the future of AI?")
|
183
|
+
elif field_type == "data_types.Audio":
|
184
|
+
default_value = data_types.Audio.from_url("https://samples.clarifai.com/audio.mp3")
|
185
|
+
elif field_type == "data_types.Video":
|
186
|
+
default_value = data_types.Video.from_url("https://samples.clarifai.com/video.mp4")
|
187
|
+
elif field_type == "data_types.Concept":
|
188
|
+
default_value = data_types.Concept(id="concept_id", name="dog", value=0.95)
|
189
|
+
elif field_type == "data_types.Region":
|
190
|
+
default_value = data_types.Region(
|
191
|
+
box=[0.1, 0.1, 0.5, 0.5],
|
192
|
+
)
|
193
|
+
elif field_type == "data_types.Frame":
|
194
|
+
default_value = data_types.Frame.from_url("https://samples.clarifai.com/video.mp4", 0)
|
195
|
+
elif field_type == "data_types.NDArray":
|
196
|
+
default_value = data_types.NDArray([1, 2, 3])
|
197
|
+
else:
|
198
|
+
default_value = None
|
199
|
+
return default_value
|
162
200
|
|
163
201
|
|
164
202
|
def _set_default_value(field_type):
|
165
|
-
|
203
|
+
"""
|
166
204
|
Set the default value of a field if it is not set.
|
167
205
|
"""
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
206
|
+
default_value = None
|
207
|
+
default_value = _map_default_value(field_type)
|
208
|
+
if field_type.startswith("List["):
|
209
|
+
element_type = field_type[5:-1]
|
210
|
+
element_type_default_value = _map_default_value(element_type)
|
211
|
+
if element_type_default_value is not None:
|
212
|
+
default_value = f"[{element_type_default_value}]"
|
213
|
+
elif field_type.startswith("Tuple["):
|
214
|
+
element_types = field_type[6:-1].split(", ")
|
215
|
+
element_type_defaults = [_map_default_value(et) for et in element_types]
|
216
|
+
default_value = f"({', '.join([str(et) for et in element_type_defaults])})"
|
217
|
+
elif field_type.startswith("NamedFields["):
|
218
|
+
element_types = field_type[12:-1].split(", ")
|
219
|
+
element_type_defaults = [_map_default_value(et) for et in element_types]
|
220
|
+
default_value = f"{{{', '.join([str(et) for et in element_type_defaults])}}}"
|
221
|
+
|
222
|
+
return default_value
|
185
223
|
|
186
224
|
|
187
225
|
def _parse_default_value(field: resources_pb2.ModelTypeField):
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
226
|
+
if not field.default:
|
227
|
+
return None
|
228
|
+
default_str = field.default
|
229
|
+
data_type = field.type
|
230
|
+
|
231
|
+
try:
|
232
|
+
if data_type == resources_pb2.ModelTypeField.DataType.INT:
|
233
|
+
return str(int(default_str))
|
234
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.FLOAT:
|
235
|
+
return str(float(default_str))
|
236
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.BOOL:
|
237
|
+
return 'True' if default_str.lower() == 'true' else 'False'
|
238
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.STR:
|
239
|
+
return repr(default_str)
|
240
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.BYTES:
|
241
|
+
return f"b{repr(default_str.encode('utf-8'))}"
|
242
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.JSON_DATA:
|
243
|
+
parsed = json.loads(default_str)
|
244
|
+
return repr(parsed)
|
245
|
+
elif data_type in (
|
246
|
+
resources_pb2.ModelTypeField.DataType.LIST,
|
247
|
+
resources_pb2.ModelTypeField.DataType.TUPLE,
|
248
|
+
resources_pb2.ModelTypeField.DataType.NAMED_FIELDS,
|
249
|
+
):
|
250
|
+
parsed = json.loads(default_str)
|
251
|
+
return repr(parsed)
|
252
|
+
else:
|
253
|
+
return repr(default_str)
|
254
|
+
except (ValueError, json.JSONDecodeError):
|
255
|
+
return repr(default_str)
|
clarifai/runners/utils/const.py
CHANGED
@@ -30,5 +30,8 @@ AVAILABLE_TORCH_IMAGES = [
|
|
30
30
|
'2.7.0-py3.12-rocm6.3',
|
31
31
|
]
|
32
32
|
CONCEPTS_REQUIRED_MODEL_TYPE = [
|
33
|
-
'visual-classifier',
|
33
|
+
'visual-classifier',
|
34
|
+
'visual-detector',
|
35
|
+
'visual-segmenter',
|
36
|
+
'text-classifier',
|
34
37
|
]
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from .data_types import JSON # noqa
|
2
|
+
from .data_types import Audio # noqa
|
3
|
+
from .data_types import Concept # noqa
|
4
|
+
from .data_types import Frame # noqa
|
5
|
+
from .data_types import Image # noqa
|
6
|
+
from .data_types import MessageData # noqa
|
7
|
+
from .data_types import NamedFields # noqa
|
8
|
+
from .data_types import NamedFieldsMeta # noqa
|
9
|
+
from .data_types import Region # noqa
|
10
|
+
from .data_types import Text # noqa
|
11
|
+
from .data_types import Video # noqa
|
12
|
+
from .data_types import cast # noqa
|