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
clarifai/client/workflow.py
CHANGED
@@ -20,278 +20,298 @@ from clarifai.workflows.export import Exporter
|
|
20
20
|
|
21
21
|
|
22
22
|
class Workflow(Lister, BaseClient):
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
url: str = None,
|
27
|
-
workflow_id: str = None,
|
28
|
-
workflow_version: Dict = {'id': ""},
|
29
|
-
output_config: Dict = {'min_value': 0},
|
30
|
-
base_url: str = "https://api.clarifai.com",
|
31
|
-
pat: str = None,
|
32
|
-
token: str = None,
|
33
|
-
root_certificates_path: str = None,
|
34
|
-
**kwargs):
|
35
|
-
"""Initializes a Workflow object.
|
36
|
-
|
37
|
-
Args:
|
38
|
-
url (str): The URL to initialize the workflow object.
|
39
|
-
workflow_id (str): The Workflow ID to interact with.
|
40
|
-
workflow_version (dict): The Workflow Version to interact with.
|
41
|
-
output_config (dict): The output config to interact with.
|
42
|
-
min_value (float): The minimum value of the prediction confidence to filter.
|
43
|
-
max_concepts (int): The maximum number of concepts to return.
|
44
|
-
select_concepts (list[Concept]): The concepts to select.
|
45
|
-
sample_ms (int): The number of milliseconds to sample.
|
46
|
-
base_url (str): Base API url. Default "https://api.clarifai.com"
|
47
|
-
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
48
|
-
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
|
49
|
-
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
50
|
-
**kwargs: Additional keyword arguments to be passed to the Workflow.
|
51
|
-
"""
|
52
|
-
if url and workflow_id:
|
53
|
-
raise UserError("You can only specify one of url or workflow_id.")
|
54
|
-
if not url and not workflow_id:
|
55
|
-
raise UserError("You must specify one of url or workflow_id.")
|
56
|
-
if url:
|
57
|
-
user_id, app_id, _, workflow_id, workflow_version_id = ClarifaiUrlHelper.split_clarifai_url(
|
58
|
-
url)
|
59
|
-
workflow_version = {'id': workflow_version_id}
|
60
|
-
kwargs = {'user_id': user_id, 'app_id': app_id}
|
61
|
-
self.kwargs = {**kwargs, 'id': workflow_id, 'version': workflow_version}
|
62
|
-
self.output_config = output_config
|
63
|
-
self.workflow_info = resources_pb2.Workflow(**self.kwargs)
|
64
|
-
self.logger = logger
|
65
|
-
self.input_types = None
|
66
|
-
BaseClient.__init__(
|
23
|
+
"""Workflow is a class that provides access to Clarifai API endpoints related to Workflow information."""
|
24
|
+
|
25
|
+
def __init__(
|
67
26
|
self,
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
27
|
+
url: str = None,
|
28
|
+
workflow_id: str = None,
|
29
|
+
workflow_version: Dict = {'id': ""},
|
30
|
+
output_config: Dict = {'min_value': 0},
|
31
|
+
base_url: str = "https://api.clarifai.com",
|
32
|
+
pat: str = None,
|
33
|
+
token: str = None,
|
34
|
+
root_certificates_path: str = None,
|
35
|
+
**kwargs,
|
36
|
+
):
|
37
|
+
"""Initializes a Workflow object.
|
38
|
+
|
39
|
+
Args:
|
40
|
+
url (str): The URL to initialize the workflow object.
|
41
|
+
workflow_id (str): The Workflow ID to interact with.
|
42
|
+
workflow_version (dict): The Workflow Version to interact with.
|
43
|
+
output_config (dict): The output config to interact with.
|
44
|
+
min_value (float): The minimum value of the prediction confidence to filter.
|
45
|
+
max_concepts (int): The maximum number of concepts to return.
|
46
|
+
select_concepts (list[Concept]): The concepts to select.
|
47
|
+
sample_ms (int): The number of milliseconds to sample.
|
48
|
+
base_url (str): Base API url. Default "https://api.clarifai.com"
|
49
|
+
pat (str): A personal access token for authentication. Can be set as env var CLARIFAI_PAT
|
50
|
+
token (str): A session token for authentication. Accepts either a session token or a pat. Can be set as env var CLARIFAI_SESSION_TOKEN
|
51
|
+
root_certificates_path (str): Path to the SSL root certificates file, used to establish secure gRPC connections.
|
52
|
+
**kwargs: Additional keyword arguments to be passed to the Workflow.
|
53
|
+
"""
|
54
|
+
if url and workflow_id:
|
55
|
+
raise UserError("You can only specify one of url or workflow_id.")
|
56
|
+
if not url and not workflow_id:
|
57
|
+
raise UserError("You must specify one of url or workflow_id.")
|
58
|
+
if url:
|
59
|
+
user_id, app_id, _, workflow_id, workflow_version_id = (
|
60
|
+
ClarifaiUrlHelper.split_clarifai_url(url)
|
61
|
+
)
|
62
|
+
workflow_version = {'id': workflow_version_id}
|
63
|
+
kwargs = {'user_id': user_id, 'app_id': app_id}
|
64
|
+
self.kwargs = {**kwargs, 'id': workflow_id, 'version': workflow_version}
|
65
|
+
self.output_config = output_config
|
66
|
+
self.workflow_info = resources_pb2.Workflow(**self.kwargs)
|
67
|
+
self.logger = logger
|
68
|
+
self.input_types = None
|
69
|
+
BaseClient.__init__(
|
70
|
+
self,
|
71
|
+
user_id=self.user_id,
|
72
|
+
app_id=self.app_id,
|
73
|
+
base=base_url,
|
74
|
+
pat=pat,
|
75
|
+
token=token,
|
76
|
+
root_certificates_path=root_certificates_path,
|
77
|
+
)
|
78
|
+
Lister.__init__(self)
|
79
|
+
|
80
|
+
def predict(self, inputs: List[Input], workflow_state_id: str = None):
|
81
|
+
"""Predicts the workflow based on the given inputs.
|
82
|
+
|
83
|
+
Args:
|
84
|
+
inputs (list[Input]): The inputs to predict.
|
85
|
+
workflow_state_id (str): key for the workflow state cache that stores the workflow node predictions.
|
86
|
+
"""
|
87
|
+
if len(inputs) > MAX_WORKFLOW_PREDICT_INPUTS:
|
88
|
+
raise UserError(
|
89
|
+
f"Too many inputs. Max is {MAX_WORKFLOW_PREDICT_INPUTS}."
|
90
|
+
) # TODO Use Chunker for inputs len > 32
|
91
|
+
request = service_pb2.PostWorkflowResultsRequest(
|
92
|
+
user_app_id=self.user_app_id,
|
93
|
+
workflow_id=self.id,
|
94
|
+
version_id=self.version.id,
|
95
|
+
inputs=inputs,
|
96
|
+
output_config=self.output_config,
|
97
|
+
)
|
98
|
+
|
99
|
+
if workflow_state_id:
|
100
|
+
request.workflow_state.id = workflow_state_id
|
101
|
+
|
102
|
+
start_time = time.time()
|
103
|
+
backoff_iterator = BackoffIterator(10)
|
104
|
+
|
105
|
+
while True:
|
106
|
+
response = self._grpc_request(self.STUB.PostWorkflowResults, request)
|
107
|
+
|
108
|
+
if (
|
109
|
+
status_is_retryable(response.status.code) and time.time() - start_time < 60 * 10
|
110
|
+
): # 10 minutes
|
111
|
+
self.logger.info(f"{self.id} Workflow is still deploying, please wait...")
|
112
|
+
time.sleep(next(backoff_iterator))
|
113
|
+
continue
|
114
|
+
|
115
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
116
|
+
raise Exception(f"Workflow Predict failed with response {response.status!r}")
|
117
|
+
else:
|
118
|
+
break
|
119
|
+
|
120
|
+
return response
|
121
|
+
|
122
|
+
def predict_by_filepath(self, filepath: str, input_type: str = None):
|
123
|
+
"""Predicts the workflow based on the given filepath.
|
124
|
+
|
125
|
+
Args:
|
126
|
+
filepath (str): The filepath to predict.
|
127
|
+
input_type (str, optional): The type of input. Can be 'image', 'text', 'video' or 'audio.
|
128
|
+
|
129
|
+
Example:
|
130
|
+
>>> from clarifai.client.workflow import Workflow
|
131
|
+
>>> workflow = Workflow("url") # Example: https://clarifai.com/clarifai/main/workflows/Face-Sentiment
|
132
|
+
or
|
133
|
+
>>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id')
|
134
|
+
>>> workflow_prediction = workflow.predict_by_filepath('filepath')
|
135
|
+
"""
|
136
|
+
if not input_type:
|
137
|
+
self.load_info()
|
138
|
+
if len(self.input_types) > 1:
|
139
|
+
raise UserError(
|
140
|
+
"Workflow has multiple input types. Please use workflow.predict()."
|
141
|
+
)
|
142
|
+
input_type = self.input_types[0]
|
143
|
+
|
144
|
+
if input_type not in {'image', 'text', 'video', 'audio'}:
|
145
|
+
raise UserError('Invalid input type it should be image, text, video or audio.')
|
146
|
+
if not os.path.isfile(filepath):
|
147
|
+
raise UserError('Invalid filepath.')
|
148
|
+
|
149
|
+
with open(filepath, "rb") as f:
|
150
|
+
file_bytes = f.read()
|
151
|
+
|
152
|
+
return self.predict_by_bytes(file_bytes, input_type)
|
153
|
+
|
154
|
+
def predict_by_bytes(self, input_bytes: bytes, input_type: str = None):
|
155
|
+
"""Predicts the workflow based on the given bytes.
|
156
|
+
|
157
|
+
Args:
|
158
|
+
input_bytes (bytes): Bytes to predict on.
|
159
|
+
input_type (str, optional): The type of input. Can be 'image', 'text', 'video' or 'audio.
|
160
|
+
"""
|
161
|
+
if not input_type:
|
162
|
+
self.load_info()
|
163
|
+
if len(self.input_types) > 1:
|
164
|
+
raise UserError(
|
165
|
+
"Workflow has multiple input types. Please use workflow.predict()."
|
166
|
+
)
|
167
|
+
input_type = self.input_types[0]
|
168
|
+
|
169
|
+
if input_type not in {'image', 'text', 'video', 'audio'}:
|
170
|
+
raise UserError('Invalid input type it should be image, text, video or audio.')
|
171
|
+
if not isinstance(input_bytes, bytes):
|
172
|
+
raise UserError('Invalid bytes.')
|
173
|
+
|
174
|
+
if input_type == "image":
|
175
|
+
input_proto = Inputs.get_input_from_bytes("", image_bytes=input_bytes)
|
176
|
+
elif input_type == "text":
|
177
|
+
input_proto = Inputs.get_input_from_bytes("", text_bytes=input_bytes)
|
178
|
+
elif input_type == "video":
|
179
|
+
input_proto = Inputs.get_input_from_bytes("", video_bytes=input_bytes)
|
180
|
+
elif input_type == "audio":
|
181
|
+
input_proto = Inputs.get_input_from_bytes("", audio_bytes=input_bytes)
|
182
|
+
|
183
|
+
return self.predict(inputs=[input_proto])
|
184
|
+
|
185
|
+
def predict_by_url(self, url: str, input_type: str = None):
|
186
|
+
"""Predicts the workflow based on the given URL.
|
187
|
+
|
188
|
+
Args:
|
189
|
+
url (str): The URL to predict.
|
190
|
+
input_type (str, optional): The type of input. Can be 'image', 'text', 'video' or 'audio.
|
191
|
+
|
192
|
+
Example:
|
193
|
+
>>> from clarifai.client.workflow import Workflow
|
194
|
+
>>> workflow = Workflow("url") # Example: https://clarifai.com/clarifai/main/workflows/Face-Sentiment
|
195
|
+
or
|
196
|
+
>>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id')
|
197
|
+
>>> workflow_prediction = workflow.predict_by_url('url')
|
198
|
+
"""
|
199
|
+
if not input_type:
|
200
|
+
self.load_info()
|
201
|
+
if len(self.input_types) > 1:
|
202
|
+
raise UserError(
|
203
|
+
"Workflow has multiple input types. Please use workflow.predict()."
|
204
|
+
)
|
205
|
+
input_type = self.input_types[0]
|
206
|
+
|
207
|
+
if input_type not in {'image', 'text', 'video', 'audio'}:
|
208
|
+
raise UserError('Invalid input type it should be image, text, video or audio.')
|
209
|
+
|
210
|
+
if input_type == "image":
|
211
|
+
input_proto = Inputs.get_input_from_url("", image_url=url)
|
212
|
+
elif input_type == "text":
|
213
|
+
input_proto = Inputs.get_input_from_url("", text_url=url)
|
214
|
+
elif input_type == "video":
|
215
|
+
input_proto = Inputs.get_input_from_url("", video_url=url)
|
216
|
+
elif input_type == "audio":
|
217
|
+
input_proto = Inputs.get_input_from_url("", audio_url=url)
|
218
|
+
|
219
|
+
return self.predict(inputs=[input_proto])
|
220
|
+
|
221
|
+
def list_versions(
|
222
|
+
self, page_no: int = None, per_page: int = None
|
223
|
+
) -> Generator['Workflow', None, None]:
|
224
|
+
"""Lists all the versions of the workflow.
|
225
|
+
|
226
|
+
Args:
|
227
|
+
page_no (int): The page number to list.
|
228
|
+
per_page (int): The number of items per page.
|
229
|
+
|
230
|
+
Yields:
|
231
|
+
Workflow: Workflow objects for versions of the workflow.
|
232
|
+
|
233
|
+
Example:
|
234
|
+
>>> from clarifai.client.workflow import Workflow
|
235
|
+
>>> workflow = Workflow(user_id='user_id', app_id='app_id', workflow_id='workflow_id')
|
236
|
+
>>> workflow_versions = list(workflow.list_versions())
|
237
|
+
|
238
|
+
Note:
|
239
|
+
Defaults to 16 per page if page_no is specified and per_page is not specified.
|
240
|
+
If both page_no and per_page are None, then lists all the resources.
|
241
|
+
"""
|
242
|
+
request_data = dict(
|
243
|
+
user_app_id=self.user_app_id,
|
244
|
+
workflow_id=self.id,
|
245
|
+
)
|
246
|
+
all_workflow_versions_info = self.list_pages_generator(
|
247
|
+
self.STUB.ListWorkflowVersions,
|
248
|
+
service_pb2.ListWorkflowVersionsRequest,
|
249
|
+
request_data,
|
250
|
+
per_page=per_page,
|
251
|
+
page_no=page_no,
|
252
|
+
)
|
253
|
+
|
254
|
+
for workflow_version_info in all_workflow_versions_info:
|
255
|
+
workflow_version_info['id'] = workflow_version_info['workflow_version_id']
|
256
|
+
del workflow_version_info['workflow_version_id']
|
257
|
+
yield Workflow.from_auth_helper(
|
258
|
+
auth=self.auth_helper,
|
259
|
+
workflow_id=self.id,
|
260
|
+
**dict(self.kwargs, version=workflow_version_info),
|
261
|
+
)
|
262
|
+
|
263
|
+
def export(self, out_path: str):
|
264
|
+
"""Exports the workflow to a yaml file.
|
265
|
+
|
266
|
+
Args:
|
267
|
+
out_path (str): The path to save the yaml file to.
|
268
|
+
|
269
|
+
Example:
|
270
|
+
>>> from clarifai.client.workflow import Workflow
|
271
|
+
>>> workflow = Workflow("https://clarifai.com/clarifai/main/workflows/Demographics")
|
272
|
+
>>> workflow.export('out_path.yml')
|
273
|
+
"""
|
274
|
+
request = service_pb2.GetWorkflowRequest(user_app_id=self.user_app_id, workflow_id=self.id)
|
275
|
+
response = self._grpc_request(self.STUB.GetWorkflow, request)
|
276
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
277
|
+
raise Exception(f"Workflow Export failed with response {response.status!r}")
|
278
|
+
|
279
|
+
with Exporter(response) as e:
|
280
|
+
e.parse()
|
281
|
+
e.export(out_path)
|
282
|
+
|
283
|
+
self.logger.info(f"Exported workflow to {out_path}")
|
284
|
+
|
285
|
+
def load_info(self) -> None:
|
286
|
+
"""Loads the workflow info."""
|
287
|
+
if not self.input_types:
|
288
|
+
request = service_pb2.GetWorkflowRequest(
|
289
|
+
user_app_id=self.user_app_id, workflow_id=self.id
|
290
|
+
)
|
291
|
+
response = self._grpc_request(self.STUB.GetWorkflow, request)
|
292
|
+
if response.status.code != status_code_pb2.SUCCESS:
|
293
|
+
raise Exception(f"Workflow Get failed with response {response.status!r}")
|
294
|
+
|
295
|
+
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
296
|
+
self.kwargs = self.process_response_keys(dict_response['workflow'])
|
297
|
+
self.workflow_info = resources_pb2.Workflow(**self.kwargs)
|
298
|
+
|
299
|
+
model = Model(
|
300
|
+
model_id=self.kwargs['nodes'][0]['model']['id'],
|
301
|
+
**self.kwargs['nodes'][0]['model'],
|
302
|
+
pat=self.pat,
|
303
|
+
)
|
304
|
+
model.load_input_types()
|
305
|
+
self.input_types = model.input_types
|
306
|
+
|
307
|
+
def __getattr__(self, name):
|
308
|
+
return getattr(self.workflow_info, name)
|
309
|
+
|
310
|
+
def __str__(self):
|
311
|
+
init_params = [param for param in self.kwargs.keys()]
|
312
|
+
attribute_strings = [
|
313
|
+
f"{param}={getattr(self.workflow_info, param)}"
|
314
|
+
for param in init_params
|
315
|
+
if hasattr(self.workflow_info, param)
|
316
|
+
]
|
317
|
+
return f"Workflow Details: \n{', '.join(attribute_strings)}\n"
|
clarifai/constants/dataset.py
CHANGED
@@ -1,24 +1,18 @@
|
|
1
1
|
DATASET_UPLOAD_TASKS = [
|
2
|
-
"visual_classification",
|
3
|
-
"
|
2
|
+
"visual_classification",
|
3
|
+
"text_classification",
|
4
|
+
"visual_detection",
|
5
|
+
"visual_segmentation",
|
6
|
+
"visual_captioning",
|
7
|
+
"multimodal_dataset",
|
4
8
|
]
|
5
9
|
|
6
10
|
TASK_TO_ANNOTATION_TYPE = {
|
7
|
-
"visual_classification": {
|
8
|
-
|
9
|
-
},
|
10
|
-
"
|
11
|
-
|
12
|
-
},
|
13
|
-
"visual_captioning": {
|
14
|
-
"concepts": "labels"
|
15
|
-
},
|
16
|
-
"visual_detection": {
|
17
|
-
"bboxes": "bboxes"
|
18
|
-
},
|
19
|
-
"visual_segmentation": {
|
20
|
-
"polygons": "polygons"
|
21
|
-
},
|
11
|
+
"visual_classification": {"concepts": "labels"},
|
12
|
+
"text_classification": {"concepts": "labels"},
|
13
|
+
"visual_captioning": {"concepts": "labels"},
|
14
|
+
"visual_detection": {"bboxes": "bboxes"},
|
15
|
+
"visual_segmentation": {"polygons": "polygons"},
|
22
16
|
}
|
23
17
|
|
24
18
|
MAX_RETRIES = 2
|
clarifai/constants/model.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
TRAINABLE_MODEL_TYPES = [
|
2
|
-
'visual-classifier',
|
3
|
-
'
|
2
|
+
'visual-classifier',
|
3
|
+
'visual-detector',
|
4
|
+
'visual-segmenter',
|
5
|
+
'visual-embedder',
|
6
|
+
'clusterer',
|
7
|
+
'text-classifier',
|
8
|
+
'embedding-classifier',
|
9
|
+
'text-to-text',
|
4
10
|
]
|
5
11
|
MAX_MODEL_PREDICT_INPUTS = 128
|
6
12
|
MODEL_EXPORT_TIMEOUT = 1800
|