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
@@ -6,44 +6,44 @@ from clarifai.utils.logging import logger
|
|
6
6
|
|
7
7
|
|
8
8
|
def download_input(input):
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
_download_input_data(input.data)
|
10
|
+
if input.data.parts:
|
11
|
+
for i in range(len(input.data.parts)):
|
12
|
+
_download_input_data(input.data.parts[i].data)
|
13
13
|
|
14
14
|
|
15
15
|
def _download_input_data(input_data):
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
16
|
+
"""
|
17
|
+
This function will download any urls that are not already bytes.
|
18
|
+
"""
|
19
|
+
if input_data.image.url and not input_data.image.base64:
|
20
|
+
# Download the image
|
21
|
+
with fsspec.open(input_data.image.url, 'rb') as f:
|
22
|
+
input_data.image.base64 = f.read()
|
23
|
+
if input_data.video.url and not input_data.video.base64:
|
24
|
+
# Download the video
|
25
|
+
with fsspec.open(input_data.video.url, 'rb') as f:
|
26
|
+
input_data.video.base64 = f.read()
|
27
|
+
if input_data.audio.url and not input_data.audio.base64:
|
28
|
+
# Download the audio
|
29
|
+
with fsspec.open(input_data.audio.url, 'rb') as f:
|
30
|
+
input_data.audio.base64 = f.read()
|
31
|
+
if input_data.text.url and not input_data.text.raw:
|
32
|
+
# Download the text
|
33
|
+
with fsspec.open(input_data.text.url, 'r') as f:
|
34
|
+
input_data.text.raw = f.read()
|
35
35
|
|
36
36
|
|
37
37
|
def ensure_urls_downloaded(request, max_threads=128):
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
"""
|
39
|
+
This function will download any urls that are not already bytes and parallelize with a thread pool.
|
40
|
+
"""
|
41
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=max_threads) as executor:
|
42
|
+
futures = []
|
43
|
+
for input in request.inputs:
|
44
|
+
futures.append(executor.submit(download_input, input))
|
45
|
+
for future in concurrent.futures.as_completed(futures):
|
46
|
+
try:
|
47
|
+
future.result()
|
48
|
+
except Exception as e:
|
49
|
+
logger.exception(f"Error downloading input: {e}")
|
clarifai/schema/search.py
CHANGED
@@ -2,71 +2,64 @@ from schema import And, Optional, Regex, Schema
|
|
2
2
|
|
3
3
|
|
4
4
|
def get_schema() -> Schema:
|
5
|
-
|
5
|
+
"""Initialize the schema for rank and filter.
|
6
6
|
|
7
|
-
|
7
|
+
This schema validates:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
- Rank and filter must be a list
|
10
|
+
- Each item in the list must be a dict
|
11
|
+
- The dict can contain these optional keys:
|
12
|
+
- 'image_url': Valid URL string
|
13
|
+
- 'text_raw': Non-empty string
|
14
|
+
- 'metadata': Dict
|
15
|
+
- 'image_bytes': Bytes
|
16
|
+
- 'geo_point': Dict with 'longitude', 'latitude' and 'geo_limit' as float, float and int respectively
|
17
|
+
- 'concepts': List where each item is a concept dict
|
18
|
+
- Concept dict requires at least one of:
|
19
|
+
- 'name': Non-empty string with dashes/underscores
|
20
|
+
- 'id': Non-empty string
|
21
|
+
- 'language': Non-empty string
|
22
|
+
- 'value': 0 or 1 integer
|
23
|
+
- 'input_types': List of 'image', 'video', 'text' or 'audio'
|
24
|
+
- 'input_dataset_ids': List of strings
|
25
|
+
- 'input_status_code': Integer
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
And(str, len, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$'))
|
41
|
-
})
|
27
|
+
Returns:
|
28
|
+
Schema: The schema for rank and filter.
|
29
|
+
"""
|
30
|
+
# Schema for a single concept
|
31
|
+
concept_schema = Schema(
|
32
|
+
{
|
33
|
+
Optional('value'): And(int, lambda x: x in [0, 1]),
|
34
|
+
Optional('id'): And(str, len),
|
35
|
+
Optional('language'): And(str, len),
|
36
|
+
# Non-empty strings with internal dashes and underscores.
|
37
|
+
Optional('name'): And(str, len, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$')),
|
38
|
+
}
|
39
|
+
)
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
41
|
+
# Schema for a rank or filter item
|
42
|
+
rank_filter_item_schema = Schema(
|
43
|
+
{
|
44
|
+
Optional('image_url'): And(str, Regex(r'^https?://')),
|
45
|
+
Optional('text_raw'): And(str, len),
|
46
|
+
Optional('metadata'): dict,
|
47
|
+
Optional('image_bytes'): bytes,
|
48
|
+
Optional('geo_point'): {'longitude': float, 'latitude': float, 'geo_limit': int},
|
49
|
+
Optional("concepts"): And(
|
50
|
+
list, lambda x: all(concept_schema.is_valid(item) and len(item) > 0 for item in x)
|
51
|
+
),
|
52
|
+
## input filters
|
53
|
+
Optional('input_types'): And(
|
54
|
+
list,
|
55
|
+
lambda input_types: all(
|
56
|
+
input_type in ('image', 'video', 'text', 'audio') for input_type in input_types
|
57
|
+
),
|
58
|
+
),
|
59
|
+
Optional('input_dataset_ids'): list,
|
60
|
+
Optional('input_status_code'): int,
|
61
|
+
}
|
62
|
+
)
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
And(list, lambda input_types: all(input_type in ('image', 'video', 'text', 'audio')
|
64
|
-
for input_type in input_types)),
|
65
|
-
Optional('input_dataset_ids'):
|
66
|
-
list,
|
67
|
-
Optional('input_status_code'):
|
68
|
-
int,
|
69
|
-
})
|
70
|
-
|
71
|
-
# Schema for rank and filter args
|
72
|
-
return Schema([rank_filter_item_schema])
|
64
|
+
# Schema for rank and filter args
|
65
|
+
return Schema([rank_filter_item_schema])
|
clarifai/urls/helper.py
CHANGED
@@ -2,119 +2,142 @@ from urllib.parse import urlparse
|
|
2
2
|
|
3
3
|
|
4
4
|
class ClarifaiUrlHelper(object):
|
5
|
-
|
5
|
+
"""Lots of helper functionality for dealing with urls around modules."""
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def __init__(self, auth, module_manager_imv_id="module_manager_install"):
|
8
|
+
"""
|
9
|
+
Args:
|
10
|
+
auth: a ClarifaiAuthHelper object.
|
11
|
+
"""
|
12
|
+
self._auth = auth
|
13
|
+
self._module_manager_imv_id = module_manager_imv_id
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
@property
|
16
|
+
def auth(self):
|
17
|
+
return self._auth
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
def module_ui_url(self, user_id, app_id, module_id, module_version_id):
|
20
|
+
"""This is the path to the module in community."""
|
21
|
+
return "%s/%s/%s/modules/%s/versions/%s" % (
|
22
|
+
self.auth.ui,
|
23
|
+
user_id,
|
24
|
+
app_id,
|
25
|
+
module_id,
|
26
|
+
module_version_id,
|
27
|
+
)
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
def module_install_ui_url(self, dest_user_id, dest_app_id, module_url):
|
30
|
+
"""This is a url that allows for installation of the module from the community at 'module_url'
|
31
31
|
into the destination app_id of the destination user_id."""
|
32
|
-
|
33
|
-
|
32
|
+
return "%s/%s/%s/installed_module_versions/%s/install?install=%s" % (
|
33
|
+
self.auth.ui,
|
34
|
+
dest_user_id,
|
35
|
+
dest_app_id,
|
36
|
+
self._module_manager_imv_id,
|
37
|
+
module_url,
|
38
|
+
)
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
def imv_ui_url(self, dest_user_id, dest_app_id, imv_id):
|
41
|
+
return "%s/%s/%s/installed_module_versions/%s" % (
|
42
|
+
self.auth.ui,
|
43
|
+
dest_user_id,
|
44
|
+
dest_app_id,
|
45
|
+
imv_id,
|
46
|
+
)
|
38
47
|
|
39
|
-
|
40
|
-
|
48
|
+
def clarifai_url(self, user_id, app_id, resource_type, resource_id, version_id: str = None):
|
49
|
+
"""This is the path to the resource in community.
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
Args:
|
52
|
+
user_id: the author of the resource.
|
53
|
+
app_id: the author's app the resource was created in.
|
54
|
+
resource_type: the type of resource. One of "modules", "models", "concepts", "inputs", "workflows", "tasks", "installed_module_versions"
|
55
|
+
resource_id: the resource ID
|
56
|
+
version_id: the version of the resource.
|
57
|
+
"""
|
58
|
+
if resource_type not in [
|
59
|
+
"modules",
|
60
|
+
"models",
|
61
|
+
"concepts",
|
62
|
+
"inputs",
|
63
|
+
"workflows",
|
64
|
+
"tasks",
|
65
|
+
"installed_module_versions",
|
66
|
+
]:
|
67
|
+
raise ValueError(
|
68
|
+
"resource_type must be one of modules, models, concepts, inputs, workflows, tasks, installed_module_versions but was %s"
|
69
|
+
% resource_type
|
70
|
+
)
|
71
|
+
if version_id is None:
|
72
|
+
return "%s/%s/%s/%s/%s" % (self.auth.ui, user_id, app_id, resource_type, resource_id)
|
73
|
+
return "%s/%s/%s/%s/%s/versions/%s" % (
|
74
|
+
self.auth.ui,
|
75
|
+
user_id,
|
76
|
+
app_id,
|
77
|
+
resource_type,
|
78
|
+
resource_id,
|
79
|
+
version_id,
|
80
|
+
)
|
60
81
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
@classmethod
|
83
|
+
def split_clarifai_app_url(cls, url):
|
84
|
+
"""
|
85
|
+
clarifai.com uses fully qualified urls to resources.
|
86
|
+
They are in the format of:
|
87
|
+
https://clarifai.com/{user_id}/{app_id}/
|
88
|
+
"""
|
89
|
+
url = url.replace("https://", "", 1).replace("http://", "", 1)
|
90
|
+
o = urlparse(url)
|
91
|
+
path = o.path
|
92
|
+
path = path.lstrip("/")
|
93
|
+
parts = path.split("/")
|
94
|
+
if len(parts) != 3:
|
95
|
+
raise ValueError(
|
96
|
+
f"Provided url must have 2 parts after the domain name. The current parts are: {parts}"
|
97
|
+
)
|
98
|
+
return tuple(parts[1:])
|
77
99
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
100
|
+
@classmethod
|
101
|
+
def split_clarifai_url(cls, url):
|
102
|
+
"""
|
103
|
+
clarifai.com uses fully qualified urls to resources.
|
104
|
+
They are in the format of:
|
105
|
+
https://clarifai.com/{user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}
|
106
|
+
Those last two are optional.
|
85
107
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
108
|
+
"""
|
109
|
+
url = url.replace("https://", "", 1).replace("http://", "", 1)
|
110
|
+
o = urlparse(url)
|
111
|
+
path = o.path
|
112
|
+
path = path.lstrip("/")
|
113
|
+
parts = path.split("/")
|
114
|
+
if len(parts) != 5 and len(parts) != 7:
|
115
|
+
raise ValueError(
|
116
|
+
"Provided url must have 4 or 6 parts after the domain name. These are: {user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}"
|
117
|
+
)
|
118
|
+
user_id, app_id, resource_type, resource_id = parts[1:5]
|
119
|
+
if len(parts) == 7:
|
120
|
+
resource_version_id = parts[6]
|
121
|
+
else:
|
122
|
+
resource_version_id = None
|
123
|
+
return user_id, app_id, resource_type, resource_id, resource_version_id
|
102
124
|
|
103
|
-
|
104
|
-
|
105
|
-
|
125
|
+
@classmethod
|
126
|
+
def split_module_ui_url(cls, install):
|
127
|
+
"""Takes in a path like https://clarifai.com/zeiler/app/modules/module1/versions/2 to split it apart into it's IDs.
|
106
128
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
129
|
+
Returns:
|
130
|
+
user_id: the author of the module.
|
131
|
+
app_id: the author's app the module was created in.
|
132
|
+
module_id: the module ID
|
133
|
+
module_version_id: the version of the module.
|
134
|
+
"""
|
135
|
+
user_id, app_id, resource_type, resource_id, resource_version_id = cls.split_clarifai_url(
|
136
|
+
install
|
137
|
+
)
|
115
138
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
139
|
+
if resource_type != "modules" or resource_version_id is None:
|
140
|
+
raise ValueError(
|
141
|
+
"Provided install url must have 6 parts after the domain name. These are {user_id}/{app_id}/modules/{module_id}/versions/{module_version_id}"
|
142
|
+
)
|
143
|
+
return user_id, app_id, resource_id, resource_version_id
|