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/models/api.py
CHANGED
@@ -23,261 +23,283 @@ from clarifai.client.auth.helper import ClarifaiAuthHelper
|
|
23
23
|
|
24
24
|
|
25
25
|
def _make_default_value_proto(dtype, value):
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
if dtype == 1:
|
27
|
+
return Value(bool_value=value)
|
28
|
+
elif dtype == 2 or dtype == 21:
|
29
|
+
return Value(string_value=value)
|
30
|
+
elif dtype == 3:
|
31
|
+
return Value(number_value=value)
|
32
32
|
|
33
33
|
|
34
34
|
class Models:
|
35
|
-
"""
|
36
|
-
Interface to Clarifai models api
|
37
|
-
"""
|
38
|
-
|
39
|
-
def __init__(self, auth: Type[ClarifaiAuthHelper]) -> None:
|
40
|
-
self.auth = auth
|
41
|
-
self.stub = create_stub(self.auth)
|
42
|
-
|
43
|
-
def list_model_types(self) -> Dict:
|
44
35
|
"""
|
45
|
-
|
36
|
+
Interface to Clarifai models api
|
37
|
+
"""
|
46
38
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
def __init__(self, auth: Type[ClarifaiAuthHelper]) -> None:
|
40
|
+
self.auth = auth
|
41
|
+
self.stub = create_stub(self.auth)
|
42
|
+
|
43
|
+
def list_model_types(self) -> Dict:
|
44
|
+
"""
|
45
|
+
List all API Model Types that support input and output.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
- A dict of;
|
49
|
+
model_type, [{expected_input_name: value}, {expected_output_name: value}, model_descripton]
|
50
|
+
key, value pairs respectively.i.e.
|
51
|
+
{model_type: [{inp_field_name: value}, {output_field_name: value,...}, model_description]}
|
52
|
+
|
53
|
+
- model_type: supported input shapes and data types dict. Structure;
|
54
|
+
{model_type: [(supported_input_N_dims, dtypes_N),...]}
|
55
|
+
|
56
|
+
- model_type: supported output shapes and data types dict. Structure;
|
57
|
+
{model_type: [(supported_output_N_dims, dtypes_N),...]}
|
58
|
+
"""
|
59
|
+
## List model types from API
|
60
|
+
model_types_response = self.stub.ListModelTypes(
|
61
|
+
service_pb2.ListModelTypesRequest(), # (user_app_id=auth.user_app_id),
|
62
|
+
metadata=self.auth.metadata,
|
63
|
+
)
|
64
|
+
# model types dict structure:
|
65
|
+
# {model_type: [{inp_field_name: value,}, {output_field_name: value,...}, desc]}
|
66
|
+
model_types = {}
|
67
|
+
in_dims_dtype = {} # {model_type: [(supported_input_N_dims, dtypes_N),...]}
|
68
|
+
out_dims_dtype = {} # {model_type: [(supported_output_N_dims, dtypes_N),...]}
|
69
|
+
types_dict = MessageToDict(model_types_response, preserving_proto_field_name=True)[
|
70
|
+
'model_types'
|
71
|
+
]
|
72
|
+
for i in range(len(types_dict)):
|
73
|
+
model_id = types_dict[i]['id']
|
74
|
+
model_desc = types_dict[i]['description']
|
75
|
+
if 'expected_output_layers' in types_dict[i].keys():
|
76
|
+
# expected_input_layers exist for all expected_output_layers
|
77
|
+
# hence one conditional check
|
78
|
+
model_types[model_id] = []
|
79
|
+
in_dims_dtype[model_id] = []
|
80
|
+
out_dims_dtype[model_id] = []
|
81
|
+
expected_input = types_dict[i]['expected_input_layers']
|
82
|
+
expected_output = types_dict[i]['expected_output_layers']
|
83
|
+
for inp in expected_input:
|
84
|
+
if 'data_field_name' in inp.keys():
|
85
|
+
model_types[model_id].append({inp['data_field_name']: None})
|
86
|
+
if 'shapes' in inp.keys():
|
87
|
+
for dim in inp['shapes']:
|
88
|
+
if 'dims' in dim.keys():
|
89
|
+
if 'max_dims' in dim.keys():
|
90
|
+
in_dims_dtype[model_id].append(
|
91
|
+
(dim['dims'], dim['max_dims'], dim['data_type'])
|
92
|
+
)
|
93
|
+
else:
|
94
|
+
in_dims_dtype[model_id].append((dim['dims'], dim['data_type']))
|
95
|
+
continue
|
96
|
+
temp_out = {}
|
97
|
+
for each in expected_output:
|
98
|
+
if 'data_field_name' in each.keys():
|
99
|
+
temp_out[each['data_field_name']] = None
|
100
|
+
if 'shapes' in each.keys():
|
101
|
+
for dim in each['shapes']:
|
102
|
+
if 'dims' in dim.keys():
|
103
|
+
out_dims_dtype[model_id].append((dim['dims'], dim['data_type']))
|
104
|
+
else:
|
105
|
+
continue
|
106
|
+
model_types[model_id].append(temp_out)
|
107
|
+
model_types[model_id].append(model_desc)
|
108
|
+
|
109
|
+
return {
|
110
|
+
"Model Types": model_types,
|
111
|
+
"Input Metadata": in_dims_dtype,
|
112
|
+
"Output Metadata": out_dims_dtype,
|
113
|
+
}
|
114
|
+
|
115
|
+
def init_model(
|
116
|
+
self,
|
117
|
+
model_id: str,
|
118
|
+
model_type: str,
|
119
|
+
description: str = "",
|
120
|
+
):
|
121
|
+
"""Init a new model on Clarifai platform.
|
122
|
+
|
123
|
+
Args:
|
124
|
+
model_id (str): Clarifai model id
|
125
|
+
model_type (str): Clarifai model type
|
126
|
+
description (str, optional): a description of the model. Defaults to "".
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
dict: Clarifai api response
|
130
|
+
"""
|
131
|
+
user_data_object = self.auth.get_user_app_id_proto()
|
132
|
+
post_models_response = self.stub.PostModels(
|
133
|
+
service_pb2.PostModelsRequest(
|
134
|
+
user_app_id=user_data_object,
|
135
|
+
models=[
|
136
|
+
resources_pb2.Model(id=model_id, notes=description, model_type_id=model_type)
|
137
|
+
],
|
138
|
+
),
|
139
|
+
metadata=self.auth.metadata,
|
140
|
+
)
|
52
141
|
|
53
|
-
|
54
|
-
|
142
|
+
return MessageToDict(post_models_response, preserving_proto_field_name=True)
|
143
|
+
|
144
|
+
def post_model_version(
|
145
|
+
self,
|
146
|
+
model_id: str,
|
147
|
+
model_zip_url: str,
|
148
|
+
input: dict,
|
149
|
+
outputs: dict,
|
150
|
+
param_specs: List[dict] = None,
|
151
|
+
):
|
152
|
+
"""Post a new version of an existing model in the Clarifai platform.
|
153
|
+
|
154
|
+
Args:
|
155
|
+
model_id (str): Clarifai model id
|
156
|
+
model_zip_url (str]): url of zip of model
|
157
|
+
model_zip_url (str): url of zip of model
|
158
|
+
input (dict): a dict where the key is clarifai input field and the value is triton model input,
|
159
|
+
{clarifai_input_field: triton_input_filed}.
|
160
|
+
outputs (dict): a dict where the keys are clarifai output fields and the values are triton model outputs,
|
161
|
+
{clarifai_output_field1: triton_output_filed1, clarifai_output_field2: triton_output_filed2,...}.
|
162
|
+
param_specs (List[dict]): list of dicts - keys are path, field_type, default_value, description. Default is None
|
163
|
+
Returns:
|
164
|
+
dict: clarifai api response
|
165
|
+
"""
|
166
|
+
user_data_object = self.auth.get_user_app_id_proto()
|
167
|
+
|
168
|
+
def _parse_fields_map(x):
|
169
|
+
"""parse input, outputs to Struct"""
|
170
|
+
_fields_map = Struct()
|
171
|
+
_fields_map.update(x)
|
172
|
+
return _fields_map
|
173
|
+
|
174
|
+
input_fields_map = _parse_fields_map(input)
|
175
|
+
output_fields_map = _parse_fields_map(outputs)
|
176
|
+
# resources_pb2.ModelTypeField(path="abc", default_value=1, description="test")
|
177
|
+
if param_specs:
|
178
|
+
iterative_proto_params = []
|
179
|
+
for param in param_specs:
|
180
|
+
dtype = param.get("field_type")
|
181
|
+
proto_param = resources_pb2.ModelTypeField(
|
182
|
+
path=param.get("path"),
|
183
|
+
field_type=dtype,
|
184
|
+
default_value=_make_default_value_proto(
|
185
|
+
dtype=dtype, value=param.get("default_value")
|
186
|
+
),
|
187
|
+
description=param.get("description"),
|
188
|
+
)
|
189
|
+
iterative_proto_params.append(proto_param)
|
190
|
+
param_specs = iterative_proto_params
|
191
|
+
|
192
|
+
post_model_versions = self.stub.PostModelVersions(
|
193
|
+
service_pb2.PostModelVersionsRequest(
|
194
|
+
user_app_id=user_data_object,
|
195
|
+
model_id=model_id,
|
196
|
+
model_versions=[
|
197
|
+
resources_pb2.ModelVersion(
|
198
|
+
pretrained_model_config=resources_pb2.PretrainedModelConfig(
|
199
|
+
model_zip_url=model_zip_url,
|
200
|
+
input_fields_map=input_fields_map,
|
201
|
+
output_fields_map=output_fields_map,
|
202
|
+
),
|
203
|
+
output_info=resources_pb2.OutputInfo(params_specs=param_specs),
|
204
|
+
)
|
205
|
+
],
|
206
|
+
),
|
207
|
+
metadata=self.auth.metadata,
|
208
|
+
)
|
55
209
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
else:
|
90
|
-
in_dims_dtype[model_id].append((dim['dims'], dim['data_type']))
|
91
|
-
continue
|
92
|
-
temp_out = {}
|
93
|
-
for each in expected_output:
|
94
|
-
if 'data_field_name' in each.keys():
|
95
|
-
temp_out[each['data_field_name']] = None
|
96
|
-
if 'shapes' in each.keys():
|
97
|
-
for dim in each['shapes']:
|
98
|
-
|
99
|
-
if 'dims' in dim.keys():
|
100
|
-
out_dims_dtype[model_id].append((dim['dims'], dim['data_type']))
|
101
|
-
else:
|
102
|
-
continue
|
103
|
-
model_types[model_id].append(temp_out)
|
104
|
-
model_types[model_id].append(model_desc)
|
105
|
-
|
106
|
-
return {
|
107
|
-
"Model Types": model_types,
|
108
|
-
"Input Metadata": in_dims_dtype,
|
109
|
-
"Output Metadata": out_dims_dtype
|
110
|
-
}
|
111
|
-
|
112
|
-
def init_model(
|
113
|
-
self,
|
114
|
-
model_id: str,
|
115
|
-
model_type: str,
|
116
|
-
description: str = "",
|
117
|
-
):
|
118
|
-
"""Init a new model on Clarifai platform.
|
119
|
-
|
120
|
-
Args:
|
121
|
-
model_id (str): Clarifai model id
|
122
|
-
model_type (str): Clarifai model type
|
123
|
-
description (str, optional): a description of the model. Defaults to "".
|
124
|
-
|
125
|
-
Returns:
|
126
|
-
dict: Clarifai api response
|
127
|
-
"""
|
128
|
-
user_data_object = self.auth.get_user_app_id_proto()
|
129
|
-
post_models_response = self.stub.PostModels(
|
130
|
-
service_pb2.PostModelsRequest(
|
131
|
-
user_app_id=user_data_object,
|
132
|
-
models=[resources_pb2.Model(id=model_id, notes=description,
|
133
|
-
model_type_id=model_type)]),
|
134
|
-
metadata=self.auth.metadata)
|
135
|
-
|
136
|
-
return MessageToDict(post_models_response, preserving_proto_field_name=True)
|
137
|
-
|
138
|
-
def post_model_version(self,
|
139
|
-
model_id: str,
|
140
|
-
model_zip_url: str,
|
141
|
-
input: dict,
|
142
|
-
outputs: dict,
|
143
|
-
param_specs: List[dict] = None):
|
144
|
-
"""Post a new version of an existing model in the Clarifai platform.
|
145
|
-
|
146
|
-
Args:
|
147
|
-
model_id (str): Clarifai model id
|
148
|
-
model_zip_url (str]): url of zip of model
|
149
|
-
model_zip_url (str): url of zip of model
|
150
|
-
input (dict): a dict where the key is clarifai input field and the value is triton model input,
|
151
|
-
{clarifai_input_field: triton_input_filed}.
|
152
|
-
outputs (dict): a dict where the keys are clarifai output fields and the values are triton model outputs,
|
153
|
-
{clarifai_output_field1: triton_output_filed1, clarifai_output_field2: triton_output_filed2,...}.
|
154
|
-
param_specs (List[dict]): list of dicts - keys are path, field_type, default_value, description. Default is None
|
155
|
-
Returns:
|
156
|
-
dict: clarifai api response
|
157
|
-
"""
|
158
|
-
user_data_object = self.auth.get_user_app_id_proto()
|
159
|
-
|
160
|
-
def _parse_fields_map(x):
|
161
|
-
"""parse input, outputs to Struct"""
|
162
|
-
_fields_map = Struct()
|
163
|
-
_fields_map.update(x)
|
164
|
-
return _fields_map
|
165
|
-
|
166
|
-
input_fields_map = _parse_fields_map(input)
|
167
|
-
output_fields_map = _parse_fields_map(outputs)
|
168
|
-
#resources_pb2.ModelTypeField(path="abc", default_value=1, description="test")
|
169
|
-
if param_specs:
|
170
|
-
iterative_proto_params = []
|
171
|
-
for param in param_specs:
|
172
|
-
dtype = param.get("field_type")
|
173
|
-
proto_param = resources_pb2.ModelTypeField(
|
174
|
-
path=param.get("path"),
|
175
|
-
field_type=dtype,
|
176
|
-
default_value=_make_default_value_proto(dtype=dtype, value=param.get("default_value")),
|
177
|
-
description=param.get("description"),
|
210
|
+
return MessageToDict(post_model_versions, preserving_proto_field_name=True)
|
211
|
+
|
212
|
+
def upload_model(
|
213
|
+
self,
|
214
|
+
model_id: str,
|
215
|
+
model_zip_url: str,
|
216
|
+
input: dict,
|
217
|
+
outputs: dict,
|
218
|
+
model_type: str,
|
219
|
+
description: str = "",
|
220
|
+
param_specs: List[dict] = None,
|
221
|
+
):
|
222
|
+
"""Doing 2 requests for initializing and creating version for a new trained model to the Clarifai platform.
|
223
|
+
|
224
|
+
Args:
|
225
|
+
model_id (str): Clarifai model id
|
226
|
+
model_zip_url (str): url of zip of model
|
227
|
+
input (dict): a dict where the key is clarifai input field and the value is triton model input,
|
228
|
+
{clarifai_input_field: triton_input_filed}
|
229
|
+
outputs (dict): a dict where the keys are clarifai output fields and the values are triton model outputs,
|
230
|
+
{clarifai_output_field1: triton_output_filed1, clarifai_output_field2: triton_output_filed2,...}
|
231
|
+
model_type (str): Clarifai model type.
|
232
|
+
description (str, optional): a description of the model. Defaults to "".
|
233
|
+
param_specs (List[dict]): list of dicts - keys are path, field_type, default_value, description. Default is None
|
234
|
+
|
235
|
+
Returns:
|
236
|
+
dict: Clarifai api response
|
237
|
+
"""
|
238
|
+
init_resp = self.init_model(model_id, model_type, description)
|
239
|
+
if init_resp["status"]["code"] != "SUCCESS":
|
240
|
+
return init_resp
|
241
|
+
version_resp = self.post_model_version(
|
242
|
+
model_id, model_zip_url, input, outputs, param_specs
|
178
243
|
)
|
179
|
-
iterative_proto_params.append(proto_param)
|
180
|
-
param_specs = iterative_proto_params
|
181
|
-
|
182
|
-
post_model_versions = self.stub.PostModelVersions(
|
183
|
-
service_pb2.PostModelVersionsRequest(
|
184
|
-
user_app_id=user_data_object,
|
185
|
-
model_id=model_id,
|
186
|
-
model_versions=[
|
187
|
-
resources_pb2.ModelVersion(
|
188
|
-
pretrained_model_config=resources_pb2.PretrainedModelConfig(
|
189
|
-
model_zip_url=model_zip_url,
|
190
|
-
input_fields_map=input_fields_map,
|
191
|
-
output_fields_map=output_fields_map),
|
192
|
-
output_info=resources_pb2.OutputInfo(params_specs=param_specs))
|
193
|
-
]),
|
194
|
-
metadata=self.auth.metadata)
|
195
|
-
|
196
|
-
return MessageToDict(post_model_versions, preserving_proto_field_name=True)
|
197
|
-
|
198
|
-
def upload_model(self,
|
199
|
-
model_id: str,
|
200
|
-
model_zip_url: str,
|
201
|
-
input: dict,
|
202
|
-
outputs: dict,
|
203
|
-
model_type: str,
|
204
|
-
description: str = "",
|
205
|
-
param_specs: List[dict] = None):
|
206
|
-
"""Doing 2 requests for initializing and creating version for a new trained model to the Clarifai platform.
|
207
|
-
|
208
|
-
Args:
|
209
|
-
model_id (str): Clarifai model id
|
210
|
-
model_zip_url (str): url of zip of model
|
211
|
-
input (dict): a dict where the key is clarifai input field and the value is triton model input,
|
212
|
-
{clarifai_input_field: triton_input_filed}
|
213
|
-
outputs (dict): a dict where the keys are clarifai output fields and the values are triton model outputs,
|
214
|
-
{clarifai_output_field1: triton_output_filed1, clarifai_output_field2: triton_output_filed2,...}
|
215
|
-
model_type (str): Clarifai model type.
|
216
|
-
description (str, optional): a description of the model. Defaults to "".
|
217
|
-
param_specs (List[dict]): list of dicts - keys are path, field_type, default_value, description. Default is None
|
218
|
-
|
219
|
-
Returns:
|
220
|
-
dict: Clarifai api response
|
221
|
-
"""
|
222
|
-
init_resp = self.init_model(model_id, model_type, description)
|
223
|
-
if init_resp["status"]["code"] != "SUCCESS":
|
224
|
-
return init_resp
|
225
|
-
version_resp = self.post_model_version(model_id, model_zip_url, input, outputs, param_specs)
|
226
244
|
|
227
|
-
|
245
|
+
return version_resp
|
228
246
|
|
229
|
-
|
230
|
-
|
247
|
+
def delete_model(self, model_id: str):
|
248
|
+
"""Delete model api by model id
|
231
249
|
|
232
|
-
|
233
|
-
|
250
|
+
Args:
|
251
|
+
model_id (str): Clarifai model id
|
234
252
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
253
|
+
Returns:
|
254
|
+
dict: clarifai api response
|
255
|
+
"""
|
256
|
+
user_data_object = self.auth.get_user_app_id_proto()
|
257
|
+
delete_model_response = self.stub.DeleteModel(
|
258
|
+
service_pb2.DeleteModelRequest(
|
259
|
+
user_app_id=user_data_object,
|
260
|
+
model_id=model_id,
|
261
|
+
),
|
262
|
+
metadata=self.auth.metadata,
|
263
|
+
)
|
245
264
|
|
246
|
-
|
265
|
+
return MessageToDict(delete_model_response, preserving_proto_field_name=True)
|
247
266
|
|
248
|
-
|
249
|
-
|
267
|
+
def delete_model_version(self, model_id: str, version_id: str):
|
268
|
+
"""Delete specific version of model
|
250
269
|
|
251
|
-
|
252
|
-
|
253
|
-
|
270
|
+
Args:
|
271
|
+
model_id (str): Clarifai model id
|
272
|
+
version_id (str): version id of model that will be removed
|
254
273
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
274
|
+
Returns:
|
275
|
+
dict: Clarifai API response
|
276
|
+
"""
|
277
|
+
user_data_object = self.auth.get_user_app_id_proto()
|
278
|
+
delete_model_response = self.stub.DeleteModelVersion(
|
279
|
+
service_pb2.DeleteModelVersionRequest(
|
280
|
+
user_app_id=user_data_object, model_id=model_id, version_id=version_id
|
281
|
+
),
|
282
|
+
metadata=self.auth.metadata,
|
283
|
+
)
|
263
284
|
|
264
|
-
|
285
|
+
return MessageToDict(delete_model_response, preserving_proto_field_name=True)
|
265
286
|
|
266
|
-
|
267
|
-
|
287
|
+
def get_model(self, model_id: str):
|
288
|
+
"""Get model by id
|
268
289
|
|
269
|
-
|
270
|
-
|
290
|
+
Args:
|
291
|
+
model_id (str): Clarifai model id
|
271
292
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
293
|
+
Returns:
|
294
|
+
dict: Clarifai API response
|
295
|
+
"""
|
296
|
+
user_data_object = self.auth.get_user_app_id_proto()
|
297
|
+
response = self.stub.GetModel(
|
298
|
+
service_pb2.GetModelRequest(
|
299
|
+
user_app_id=user_data_object,
|
300
|
+
model_id=model_id,
|
301
|
+
),
|
302
|
+
metadata=self.auth.metadata,
|
303
|
+
)
|
304
|
+
|
305
|
+
return MessageToDict(response, preserving_proto_field_name=True)
|
clarifai/modules/css.py
CHANGED
@@ -2,59 +2,59 @@ import os
|
|
2
2
|
|
3
3
|
|
4
4
|
class ClarifaiStreamlitCSS(object):
|
5
|
-
|
6
|
-
|
7
|
-
"""
|
8
|
-
|
9
|
-
@classmethod
|
10
|
-
def insert_default_css(cls, st):
|
11
|
-
""" Inserts the default style provided in style.css in this folder into the streamlit page
|
12
|
-
|
13
|
-
Example:
|
14
|
-
ClarifaiStreamlitCSS.insert_default_css()
|
15
|
-
|
16
|
-
Note:
|
17
|
-
This must be placed in both the app.py AND all the pages/*.py files to get the custom styles.
|
18
|
-
"""
|
19
|
-
file_name = os.path.join(os.path.dirname(__file__), "style.css")
|
20
|
-
cls.insert_css_file(file_name, st)
|
21
|
-
|
22
|
-
@classmethod
|
23
|
-
def insert_css_file(cls, css_file, st):
|
24
|
-
""" Open the full filename to the css file and insert it's contents the style of the page.
|
25
|
-
"""
|
26
|
-
with open(css_file) as f:
|
27
|
-
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
28
|
-
|
29
|
-
@classmethod
|
30
|
-
def buttonlink(cls, st, label, link, target="_parent", style=""):
|
31
|
-
"""
|
32
|
-
This is a streamlit button that will link to another page (or _self if target is _self).
|
33
|
-
It is styled to look like the other stButton>button buttons that are created with st.button().
|
34
|
-
|
35
|
-
You must insert_default_css(st) before using on a page.
|
36
|
-
|
37
|
-
Example:
|
38
|
-
ClarifaiStreamlitCSS.insert_default_css(st)
|
39
|
-
cols = st.columns(4)
|
40
|
-
ClarifaiStreamlitCSS.buttonlink(cols[3], "Button", "https://clarifai.com", "_blank")
|
41
|
-
|
42
|
-
Args:
|
43
|
-
st: the streamlit package.
|
44
|
-
label: the text string to display in the button.
|
45
|
-
link: the url to link the button to.
|
46
|
-
target: to open the link in same page (_parent) or new tab (_blank).
|
47
|
-
style: additional style to apply to the button link.
|
48
|
-
Ex: "background-color: rgb(45, 164, 78); color:white;" makes the button green background with white text.
|
5
|
+
"""ClarifaiStreamlitCSS helps get a consistent style by default for Clarifai provided
|
6
|
+
streamlit apps.
|
49
7
|
"""
|
50
|
-
astyle = ""
|
51
|
-
if style:
|
52
|
-
astyle = f'style="{style}"'
|
53
8
|
|
54
|
-
|
55
|
-
|
9
|
+
@classmethod
|
10
|
+
def insert_default_css(cls, st):
|
11
|
+
"""Inserts the default style provided in style.css in this folder into the streamlit page
|
12
|
+
|
13
|
+
Example:
|
14
|
+
ClarifaiStreamlitCSS.insert_default_css()
|
15
|
+
|
16
|
+
Note:
|
17
|
+
This must be placed in both the app.py AND all the pages/*.py files to get the custom styles.
|
18
|
+
"""
|
19
|
+
file_name = os.path.join(os.path.dirname(__file__), "style.css")
|
20
|
+
cls.insert_css_file(file_name, st)
|
21
|
+
|
22
|
+
@classmethod
|
23
|
+
def insert_css_file(cls, css_file, st):
|
24
|
+
"""Open the full filename to the css file and insert it's contents the style of the page."""
|
25
|
+
with open(css_file) as f:
|
26
|
+
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
27
|
+
|
28
|
+
@classmethod
|
29
|
+
def buttonlink(cls, st, label, link, target="_parent", style=""):
|
30
|
+
"""
|
31
|
+
This is a streamlit button that will link to another page (or _self if target is _self).
|
32
|
+
It is styled to look like the other stButton>button buttons that are created with st.button().
|
33
|
+
|
34
|
+
You must insert_default_css(st) before using on a page.
|
35
|
+
|
36
|
+
Example:
|
37
|
+
ClarifaiStreamlitCSS.insert_default_css(st)
|
38
|
+
cols = st.columns(4)
|
39
|
+
ClarifaiStreamlitCSS.buttonlink(cols[3], "Button", "https://clarifai.com", "_blank")
|
40
|
+
|
41
|
+
Args:
|
42
|
+
st: the streamlit package.
|
43
|
+
label: the text string to display in the button.
|
44
|
+
link: the url to link the button to.
|
45
|
+
target: to open the link in same page (_parent) or new tab (_blank).
|
46
|
+
style: additional style to apply to the button link.
|
47
|
+
Ex: "background-color: rgb(45, 164, 78); color:white;" makes the button green background with white text.
|
48
|
+
"""
|
49
|
+
astyle = ""
|
50
|
+
if style:
|
51
|
+
astyle = f'style="{style}"'
|
52
|
+
|
53
|
+
st.markdown(
|
54
|
+
f'''
|
56
55
|
<div class="stButton">
|
57
56
|
<a href="{link}" target="{target}" {astyle}>{label}</a>
|
58
57
|
</div>
|
59
58
|
''',
|
60
|
-
|
59
|
+
unsafe_allow_html=True,
|
60
|
+
)
|