clarifai 9.10.2__py3-none-any.whl → 9.10.3__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/client/__init__.py +3 -2
- clarifai/client/app.py +39 -23
- clarifai/client/base.py +6 -6
- clarifai/client/dataset.py +113 -55
- clarifai/client/input.py +47 -55
- clarifai/client/model.py +27 -25
- clarifai/client/module.py +13 -11
- clarifai/client/runner.py +5 -3
- clarifai/client/search.py +7 -3
- clarifai/client/user.py +14 -8
- clarifai/client/workflow.py +22 -20
- clarifai/constants/dataset.py +22 -0
- clarifai/datasets/upload/base.py +9 -7
- clarifai/datasets/upload/features.py +3 -3
- clarifai/datasets/upload/image.py +49 -50
- clarifai/datasets/upload/loaders/coco_captions.py +26 -80
- clarifai/datasets/upload/loaders/coco_detection.py +56 -115
- clarifai/datasets/upload/loaders/coco_segmentation.py +69 -137
- clarifai/datasets/upload/loaders/imagenet_classification.py +2 -3
- clarifai/datasets/upload/loaders/xview_detection.py +3 -3
- clarifai/datasets/upload/text.py +16 -16
- clarifai/datasets/upload/utils.py +196 -21
- clarifai/utils/misc.py +21 -0
- clarifai/versions.py +1 -1
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/METADATA +3 -3
- clarifai-9.10.3.dist-info/RECORD +96 -0
- clarifai-9.10.3.dist-info/top_level.txt +1 -0
- clarifai/auth/__init__.py +0 -6
- clarifai/auth/helper.py +0 -367
- clarifai/auth/register.py +0 -23
- clarifai/auth/stub.py +0 -127
- clarifai/datasets/upload/examples/README.md +0 -31
- clarifai/datasets/upload/examples/image_classification/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_test.csv +0 -10
- clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_train.csv +0 -10
- clarifai/datasets/upload/examples/image_classification/cifar10/dataset.py +0 -46
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- clarifai/datasets/upload/examples/text_classification/__init__.py +0 -0
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +0 -42
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/test.csv +0 -201
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/train.csv +0 -201
- clarifai/datasets/upload/loaders/README.md +0 -49
- clarifai/models/model_serving/README.md +0 -155
- clarifai/models/model_serving/docs/custom_config.md +0 -33
- clarifai/models/model_serving/docs/dependencies.md +0 -11
- clarifai/models/model_serving/docs/inference_parameters.md +0 -134
- clarifai/models/model_serving/docs/model_types.md +0 -20
- clarifai/models/model_serving/docs/output.md +0 -28
- clarifai/models/model_serving/examples/README.md +0 -7
- clarifai/models/model_serving/examples/image_classification/README.md +0 -9
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/README.md +0 -11
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/config.json +0 -42
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/preprocessor_config.json +0 -15
- clarifai/models/model_serving/examples/image_classification/age_vit/config.pbtxt +0 -23
- clarifai/models/model_serving/examples/image_classification/age_vit/labels.txt +0 -9
- clarifai/models/model_serving/examples/image_classification/age_vit/requirements.txt +0 -7
- clarifai/models/model_serving/examples/text_classification/README.md +0 -9
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/README.md +0 -12
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/config.json +0 -34
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/special_tokens_map.json +0 -1
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/config.pbtxt +0 -21
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/labels.txt +0 -3
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +0 -7
- clarifai/models/model_serving/examples/text_embedding/README.md +0 -9
- clarifai/models/model_serving/examples/text_to_image/README.md +0 -9
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/__init__.py +0 -0
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/inference.py +0 -52
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/model.py +0 -60
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/config.pbtxt +0 -22
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +0 -6
- clarifai/models/model_serving/examples/text_to_text/README.md +0 -10
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/config.pbtxt +0 -20
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +0 -4
- clarifai/models/model_serving/examples/visual_detection/README.md +0 -11
- clarifai/models/model_serving/examples/visual_detection/yolov5x/config.pbtxt +0 -36
- clarifai/models/model_serving/examples/visual_detection/yolov5x/labels.txt +0 -80
- clarifai/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +0 -12
- clarifai/models/model_serving/examples/visual_embedding/README.md +0 -9
- clarifai/models/model_serving/examples/visual_embedding/vit-base/config.pbtxt +0 -22
- clarifai/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +0 -5
- clarifai/models/model_serving/examples/visual_segmentation/README.md +0 -9
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/config.pbtxt +0 -24
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/labels.txt +0 -18
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +0 -5
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -24
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -28
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -18
- clarifai/modules/README.md +0 -5
- clarifai/modules/style.css +0 -217
- clarifai-9.10.2.dist-info/RECORD +0 -386
- clarifai-9.10.2.dist-info/top_level.txt +0 -2
- clarifai_utils/__init__.py +0 -0
- clarifai_utils/auth/__init__.py +0 -6
- clarifai_utils/auth/helper.py +0 -367
- clarifai_utils/auth/register.py +0 -23
- clarifai_utils/auth/stub.py +0 -127
- clarifai_utils/cli.py +0 -0
- clarifai_utils/client/__init__.py +0 -16
- clarifai_utils/client/app.py +0 -684
- clarifai_utils/client/auth/__init__.py +0 -4
- clarifai_utils/client/auth/helper.py +0 -367
- clarifai_utils/client/auth/register.py +0 -23
- clarifai_utils/client/auth/stub.py +0 -127
- clarifai_utils/client/base.py +0 -131
- clarifai_utils/client/dataset.py +0 -442
- clarifai_utils/client/input.py +0 -892
- clarifai_utils/client/lister.py +0 -54
- clarifai_utils/client/model.py +0 -575
- clarifai_utils/client/module.py +0 -94
- clarifai_utils/client/runner.py +0 -161
- clarifai_utils/client/search.py +0 -254
- clarifai_utils/client/user.py +0 -253
- clarifai_utils/client/workflow.py +0 -223
- clarifai_utils/constants/model.py +0 -4
- clarifai_utils/constants/search.py +0 -2
- clarifai_utils/datasets/__init__.py +0 -0
- clarifai_utils/datasets/export/__init__.py +0 -0
- clarifai_utils/datasets/export/inputs_annotations.py +0 -222
- clarifai_utils/datasets/upload/__init__.py +0 -0
- clarifai_utils/datasets/upload/base.py +0 -66
- clarifai_utils/datasets/upload/examples/README.md +0 -31
- clarifai_utils/datasets/upload/examples/image_classification/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/cifar_small_test.csv +0 -10
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/cifar_small_train.csv +0 -10
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/dataset.py +0 -46
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +0 -42
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/test.csv +0 -201
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/train.csv +0 -201
- clarifai_utils/datasets/upload/features.py +0 -44
- clarifai_utils/datasets/upload/image.py +0 -165
- clarifai_utils/datasets/upload/loaders/README.md +0 -49
- clarifai_utils/datasets/upload/loaders/__init__.py +0 -0
- clarifai_utils/datasets/upload/loaders/coco_captions.py +0 -103
- clarifai_utils/datasets/upload/loaders/coco_detection.py +0 -134
- clarifai_utils/datasets/upload/loaders/coco_segmentation.py +0 -166
- clarifai_utils/datasets/upload/loaders/imagenet_classification.py +0 -59
- clarifai_utils/datasets/upload/loaders/xview_detection.py +0 -148
- clarifai_utils/datasets/upload/text.py +0 -53
- clarifai_utils/datasets/upload/utils.py +0 -63
- clarifai_utils/errors.py +0 -89
- clarifai_utils/models/__init__.py +0 -0
- clarifai_utils/models/api.py +0 -283
- clarifai_utils/models/model_serving/README.md +0 -155
- clarifai_utils/models/model_serving/__init__.py +0 -12
- clarifai_utils/models/model_serving/cli/__init__.py +0 -12
- clarifai_utils/models/model_serving/cli/deploy_cli.py +0 -123
- clarifai_utils/models/model_serving/cli/model_zip.py +0 -61
- clarifai_utils/models/model_serving/cli/repository.py +0 -87
- clarifai_utils/models/model_serving/constants.py +0 -1
- clarifai_utils/models/model_serving/docs/custom_config.md +0 -33
- clarifai_utils/models/model_serving/docs/dependencies.md +0 -11
- clarifai_utils/models/model_serving/docs/inference_parameters.md +0 -134
- clarifai_utils/models/model_serving/docs/model_types.md +0 -20
- clarifai_utils/models/model_serving/docs/output.md +0 -28
- clarifai_utils/models/model_serving/examples/README.md +0 -7
- clarifai_utils/models/model_serving/examples/image_classification/README.md +0 -9
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/inference.py +0 -56
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/README.md +0 -11
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/config.json +0 -42
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/preprocessor_config.json +0 -15
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/config.pbtxt +0 -23
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/labels.txt +0 -9
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/requirements.txt +0 -7
- clarifai_utils/models/model_serving/examples/text_classification/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/inference.py +0 -55
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/README.md +0 -12
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/config.json +0 -34
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/special_tokens_map.json +0 -1
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/config.pbtxt +0 -21
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/labels.txt +0 -3
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +0 -7
- clarifai_utils/models/model_serving/examples/text_embedding/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_to_image/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/inference.py +0 -52
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/config.pbtxt +0 -22
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +0 -6
- clarifai_utils/models/model_serving/examples/text_to_text/README.md +0 -10
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/inference.py +0 -47
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/config.pbtxt +0 -20
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +0 -4
- clarifai_utils/models/model_serving/examples/visual_detection/README.md +0 -11
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/1/inference.py +0 -72
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/config.pbtxt +0 -36
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/labels.txt +0 -80
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +0 -12
- clarifai_utils/models/model_serving/examples/visual_embedding/README.md +0 -9
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/inference.py +0 -51
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/config.pbtxt +0 -22
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +0 -5
- clarifai_utils/models/model_serving/examples/visual_segmentation/README.md +0 -9
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/inference.py +0 -55
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/config.pbtxt +0 -24
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/labels.txt +0 -18
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +0 -5
- clarifai_utils/models/model_serving/model_config/__init__.py +0 -14
- clarifai_utils/models/model_serving/model_config/config.py +0 -302
- clarifai_utils/models/model_serving/model_config/inference_parameter.py +0 -124
- clarifai_utils/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -24
- clarifai_utils/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -28
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/serializer.py +0 -134
- clarifai_utils/models/model_serving/models/__init__.py +0 -12
- clarifai_utils/models/model_serving/models/default_test.py +0 -275
- clarifai_utils/models/model_serving/models/inference.py +0 -42
- clarifai_utils/models/model_serving/models/model_types.py +0 -265
- clarifai_utils/models/model_serving/models/output.py +0 -124
- clarifai_utils/models/model_serving/models/pb_model.py +0 -74
- clarifai_utils/models/model_serving/models/test.py +0 -64
- clarifai_utils/models/model_serving/pb_model_repository.py +0 -101
- clarifai_utils/modules/README.md +0 -5
- clarifai_utils/modules/__init__.py +0 -0
- clarifai_utils/modules/css.py +0 -60
- clarifai_utils/modules/pages.py +0 -42
- clarifai_utils/modules/style.css +0 -217
- clarifai_utils/runners/__init__.py +0 -0
- clarifai_utils/runners/example.py +0 -33
- clarifai_utils/schema/search.py +0 -69
- clarifai_utils/urls/helper.py +0 -103
- clarifai_utils/utils/__init__.py +0 -0
- clarifai_utils/utils/logging.py +0 -90
- clarifai_utils/utils/misc.py +0 -33
- clarifai_utils/utils/model_train.py +0 -157
- clarifai_utils/versions.py +0 -6
- clarifai_utils/workflows/__init__.py +0 -0
- clarifai_utils/workflows/export.py +0 -68
- clarifai_utils/workflows/utils.py +0 -59
- clarifai_utils/workflows/validate.py +0 -67
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/LICENSE +0 -0
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/WHEEL +0 -0
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import urllib.request
|
|
3
|
-
from typing import Any, Dict
|
|
4
|
-
|
|
5
|
-
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
|
|
6
|
-
from clarifai_grpc.grpc.api import resources_pb2, service_pb2_grpc
|
|
7
|
-
|
|
8
|
-
DEFAULT_BASE = "https://api.clarifai.com"
|
|
9
|
-
DEFAULT_UI = "https://clarifai.com"
|
|
10
|
-
|
|
11
|
-
# Map from base domain to True / False for whether the base has https or http.
|
|
12
|
-
# This is filled in get_stub() if it's not in there already.
|
|
13
|
-
base_https_cache = {}
|
|
14
|
-
ui_https_cache = {}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def clear_cache() -> None:
|
|
18
|
-
"""Clears the cache."""
|
|
19
|
-
base_https_cache.clear()
|
|
20
|
-
ui_https_cache.clear()
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def https_cache(cache: dict, url: str) -> str:
|
|
24
|
-
"""This is a helper function to cache whether a url is http or https."""
|
|
25
|
-
HTTPS = True
|
|
26
|
-
HTTP = False
|
|
27
|
-
|
|
28
|
-
# If http or https is provided, we trust that it is correct.
|
|
29
|
-
# Note: this always stores the url without http:// or https://
|
|
30
|
-
if url.startswith("https://"):
|
|
31
|
-
url = url.replace("https://", "")
|
|
32
|
-
cache[url] = HTTPS
|
|
33
|
-
elif url.startswith("http://"):
|
|
34
|
-
url = url.replace("http://", "")
|
|
35
|
-
cache[url] = HTTP
|
|
36
|
-
elif url not in cache:
|
|
37
|
-
# We know our endpoints are https.
|
|
38
|
-
if ".clarifai.com" in url:
|
|
39
|
-
cache[url] = HTTPS
|
|
40
|
-
else: # need to test it.
|
|
41
|
-
try: # make request to https endpoint.
|
|
42
|
-
urllib.request.urlopen("https://%s/v2/auth/methods" % url, timeout=1)
|
|
43
|
-
cache[url] = HTTPS # cache it.
|
|
44
|
-
except Exception as e:
|
|
45
|
-
if "SSL" in str(e): # if ssl error then we know it's http.
|
|
46
|
-
cache[url] = HTTP
|
|
47
|
-
# For http urls we need host:port format.
|
|
48
|
-
if ":" not in url:
|
|
49
|
-
raise Exception("When providing an insecure url it must have both host:port format")
|
|
50
|
-
else:
|
|
51
|
-
raise Exception("Could not get a valid response from url: %s, is the API running there?"
|
|
52
|
-
% url) from e
|
|
53
|
-
return url
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class ClarifaiAuthHelper:
|
|
57
|
-
|
|
58
|
-
def __init__(
|
|
59
|
-
self,
|
|
60
|
-
user_id: str,
|
|
61
|
-
app_id: str,
|
|
62
|
-
pat: str,
|
|
63
|
-
token: str = "",
|
|
64
|
-
base: str = DEFAULT_BASE,
|
|
65
|
-
ui: str = DEFAULT_UI,
|
|
66
|
-
validate: bool = True,
|
|
67
|
-
):
|
|
68
|
-
"""
|
|
69
|
-
A helper to get the authorization information needed to make API calls with the grpc
|
|
70
|
-
client to a specific app using a personal access token.
|
|
71
|
-
|
|
72
|
-
There are classmethods to make this object easily from either query_params provided by streamlit or from env vars.
|
|
73
|
-
|
|
74
|
-
Note: only one of personal access token (pat) or a session token (token) can be provided.
|
|
75
|
-
Always use PATs in your code and never session tokens, those are only provided internal UI code.
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
user_id: a user id who owns the resource you want to make calls to.
|
|
79
|
-
app_id: an app id for the application that owns the resource you want to interact with
|
|
80
|
-
pat: a personal access token.
|
|
81
|
-
token: a session token (internal use only, always use a PAT).
|
|
82
|
-
base: a url to the API endpoint to hit. Examples include api.clarifai.com,
|
|
83
|
-
https://api.clarifai.com (default), https://host:port, http://host:port, host:port (will be treated as http, not https). It's highly recommended to include the http:// or https:// otherwise we need to check the endpoint to determine if it has SSL during this __init__
|
|
84
|
-
ui: a url to the UI. Examples include clarifai.com,
|
|
85
|
-
https://clarifai.com (default), https://host:port, http://host:port, host:port (will be treated as http, not https). It's highly recommended to include the http:// or https:// otherwise we need to check the endpoint to determine if it has SSL during this __init__
|
|
86
|
-
validate: whether to validate the inputs. This is useful for overriding vars then validating
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
self.user_id = user_id
|
|
90
|
-
self.app_id = app_id
|
|
91
|
-
self._pat = pat
|
|
92
|
-
self._token = token
|
|
93
|
-
|
|
94
|
-
self.set_base(base)
|
|
95
|
-
self.set_ui(ui)
|
|
96
|
-
if validate:
|
|
97
|
-
self.validate()
|
|
98
|
-
|
|
99
|
-
def validate(self):
|
|
100
|
-
if self.user_id == "":
|
|
101
|
-
raise Exception(
|
|
102
|
-
"Need 'user_id' to not be empty in the query params or user CLARIFAI_USER_ID env var")
|
|
103
|
-
if self.app_id == "":
|
|
104
|
-
raise Exception(
|
|
105
|
-
"Need 'app_id' to not be empty in the query params or user CLARIFAI_APP_ID env var")
|
|
106
|
-
if self._pat != "" and self._token != "":
|
|
107
|
-
raise Exception(
|
|
108
|
-
"A personal access token OR a session token need to be provided, but you cannot provide both."
|
|
109
|
-
)
|
|
110
|
-
elif self._pat == "" and self._token == "":
|
|
111
|
-
raise Exception(
|
|
112
|
-
"Need 'pat' or 'token' in the query params or use one of the CLARIFAI_PAT or CLARIFAI_SESSION_TOKEN env vars"
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
@classmethod
|
|
116
|
-
def from_streamlit(cls, st: Any) -> "ClarifaiAuthHelper":
|
|
117
|
-
""" This is a convenient method to check the environment variables first to see if there are
|
|
118
|
-
required variables for auth, then override them with any additional query parameters that may
|
|
119
|
-
have been passed in.
|
|
120
|
-
|
|
121
|
-
Note: if a .streamlit/secrets.toml is present then st.secrets will auto populate the
|
|
122
|
-
corresponding environment variables and we will pick them up from there, OVERWRITING whatever
|
|
123
|
-
matching env var that may already be present.
|
|
124
|
-
|
|
125
|
-
Args:
|
|
126
|
-
st: the streamlit package typically as: 'import streamlit as st'
|
|
127
|
-
Returns:
|
|
128
|
-
auth: this class instantiated
|
|
129
|
-
"""
|
|
130
|
-
# start with the env vars (potentially loaded from secrets.toml)
|
|
131
|
-
# Don't validate yet as we'll layer on the query params next.
|
|
132
|
-
auth = ClarifaiAuthHelper.from_env(validate=False)
|
|
133
|
-
|
|
134
|
-
# Then add in the query params.
|
|
135
|
-
try:
|
|
136
|
-
auth.add_streamlit_query_params(st.experimental_get_query_params())
|
|
137
|
-
except Exception as e:
|
|
138
|
-
st.error(e)
|
|
139
|
-
st.stop()
|
|
140
|
-
raise e
|
|
141
|
-
|
|
142
|
-
# Then validate.
|
|
143
|
-
try:
|
|
144
|
-
auth.validate()
|
|
145
|
-
except Exception as e:
|
|
146
|
-
st.error(e)
|
|
147
|
-
st.stop()
|
|
148
|
-
raise e
|
|
149
|
-
|
|
150
|
-
return auth
|
|
151
|
-
|
|
152
|
-
@classmethod
|
|
153
|
-
def from_streamlit_query_params(cls, query_params: Any = "") -> "ClarifaiAuthHelper":
|
|
154
|
-
"""Initialize from streamlit queryparams. The following things will be looked for:
|
|
155
|
-
user_id: as 'user_id' in query_params
|
|
156
|
-
app_id: as 'app_id' in query_params
|
|
157
|
-
one of:
|
|
158
|
-
token: as 'token' in query_params
|
|
159
|
-
pat: as 'pat' in query_params
|
|
160
|
-
optionally:
|
|
161
|
-
base: as 'base' in query_params.
|
|
162
|
-
ui: as 'ui' in query_params.
|
|
163
|
-
|
|
164
|
-
"""
|
|
165
|
-
|
|
166
|
-
# Setup an empty one (not from env).
|
|
167
|
-
auth = ClarifaiAuthHelper("", "", "", "", validate=False)
|
|
168
|
-
|
|
169
|
-
# Then add in the query params.
|
|
170
|
-
auth.add_streamlit_query_params(query_params)
|
|
171
|
-
|
|
172
|
-
# Then validate.
|
|
173
|
-
auth.validate()
|
|
174
|
-
|
|
175
|
-
return auth
|
|
176
|
-
|
|
177
|
-
def add_streamlit_query_params(self, query_params: Any = "") -> "ClarifaiAuthHelper":
|
|
178
|
-
"""Initialize from streamlit queryparams. The following things will be looked for:
|
|
179
|
-
user_id: as 'user_id' in query_params
|
|
180
|
-
app_id: as 'app_id' in query_params
|
|
181
|
-
one of:
|
|
182
|
-
token: as 'token' in query_params
|
|
183
|
-
pat: as 'pat' in query_params
|
|
184
|
-
optionally:
|
|
185
|
-
base: as 'base' in query_params.
|
|
186
|
-
|
|
187
|
-
Args:
|
|
188
|
-
query_params: the streamlit.experimental_get_query_params() response or an empty dict to fall
|
|
189
|
-
back to using env vars.
|
|
190
|
-
"""
|
|
191
|
-
error_description = """
|
|
192
|
-
Please check the following required query params are in the url:
|
|
193
|
-
- 'user_id': the user ID accessing the module.
|
|
194
|
-
- 'app_id': the app the module is being accessed from.
|
|
195
|
-
- 'token' or 'pat': to authenticate the calling user with a session token or personal access token.
|
|
196
|
-
|
|
197
|
-
Additionally, these optional params are supported:
|
|
198
|
-
- 'base': the base domain for the API such as https://api.clarifai.com
|
|
199
|
-
- 'ui': the overall UI domain for redirects such as https://clarifai.com
|
|
200
|
-
"""
|
|
201
|
-
|
|
202
|
-
if query_params == "": # empty response from streamlit
|
|
203
|
-
query_params = {}
|
|
204
|
-
for k in ["user_id", "app_id", "token", "pat"]:
|
|
205
|
-
if k in query_params and len(query_params[k]) != 1:
|
|
206
|
-
err_str = "There should only be 1 query param value for key '%s'" % k
|
|
207
|
-
raise Exception(err_str + error_description)
|
|
208
|
-
if "user_id" in query_params:
|
|
209
|
-
self.user_id = query_params["user_id"][0]
|
|
210
|
-
if "app_id" in query_params:
|
|
211
|
-
self.app_id = query_params["app_id"][0]
|
|
212
|
-
if "token" in query_params:
|
|
213
|
-
self._token = query_params["token"][0]
|
|
214
|
-
if "pat" in query_params:
|
|
215
|
-
self._pat = query_params["pat"][0]
|
|
216
|
-
if "base" in query_params:
|
|
217
|
-
self.set_base(query_params["base"][0])
|
|
218
|
-
if "ui" in query_params:
|
|
219
|
-
self.set_ui(query_params["ui"][0])
|
|
220
|
-
|
|
221
|
-
@classmethod
|
|
222
|
-
def from_env(cls, validate: bool = True) -> "ClarifaiAuthHelper":
|
|
223
|
-
"""Will look for the following env vars:
|
|
224
|
-
user_id: CLARIFAI_USER_ID env var.
|
|
225
|
-
app_id: CLARIFAI_APP_ID env var.
|
|
226
|
-
one of:
|
|
227
|
-
token: CLARIFAI_SESSION_TOKEN env var.
|
|
228
|
-
pat: CLARIFAI_PAT env var.
|
|
229
|
-
base: CLARIFAI_API_BASE env var.
|
|
230
|
-
"""
|
|
231
|
-
user_id = os.environ.get("CLARIFAI_USER_ID", "")
|
|
232
|
-
app_id = os.environ.get("CLARIFAI_APP_ID", "")
|
|
233
|
-
token = os.environ.get("CLARIFAI_SESSION_TOKEN", "")
|
|
234
|
-
pat = os.environ.get("CLARIFAI_PAT", "")
|
|
235
|
-
base = os.environ.get("CLARIFAI_API_BASE", DEFAULT_BASE)
|
|
236
|
-
ui = os.environ.get("CLARIFAI_UI", DEFAULT_UI)
|
|
237
|
-
return cls(user_id, app_id, pat, token, base, ui, validate)
|
|
238
|
-
|
|
239
|
-
def get_user_app_id_proto(
|
|
240
|
-
self,
|
|
241
|
-
user_id: str = None,
|
|
242
|
-
app_id: str = None,
|
|
243
|
-
) -> resources_pb2.UserAppIDSet:
|
|
244
|
-
"""Get the gRPC metadata that contains either the session token or the PAT to use.
|
|
245
|
-
|
|
246
|
-
Args:
|
|
247
|
-
user_id: optional user_id to override the default
|
|
248
|
-
app_id: optional app_id to override the default.
|
|
249
|
-
|
|
250
|
-
Returns:
|
|
251
|
-
metadata: the metadata need to send with all grpc API calls in the API client.
|
|
252
|
-
"""
|
|
253
|
-
user_id = self.user_id if user_id is None else user_id
|
|
254
|
-
app_id = self.app_id if app_id is None else app_id
|
|
255
|
-
return resources_pb2.UserAppIDSet(user_id=user_id, app_id=app_id)
|
|
256
|
-
|
|
257
|
-
@property
|
|
258
|
-
def metadata(self):
|
|
259
|
-
"""Get the gRPC metadata that contains either the session token or the PAT to use.
|
|
260
|
-
|
|
261
|
-
Returns:
|
|
262
|
-
metadata: the metadata need to send with all grpc API calls in the API client.
|
|
263
|
-
"""
|
|
264
|
-
if self._pat != "":
|
|
265
|
-
return (("authorization", "Key %s" % self._pat),)
|
|
266
|
-
elif self._token != "":
|
|
267
|
-
return (("x-clarifai-session-token", self._token),)
|
|
268
|
-
else:
|
|
269
|
-
raise Exception("'token' or 'pat' needed to be provided in the query params or env vars.")
|
|
270
|
-
|
|
271
|
-
def get_stub(self) -> service_pb2_grpc.V2Stub:
|
|
272
|
-
"""Get the API gRPC stub using the right channel based on the API endpoint base.
|
|
273
|
-
|
|
274
|
-
Returns:
|
|
275
|
-
stub: The service_pb2_grpc.V2Stub stub for the API.
|
|
276
|
-
"""
|
|
277
|
-
if self._base not in base_https_cache:
|
|
278
|
-
raise Exception("Cannot determine if base %s is https" % self._base)
|
|
279
|
-
|
|
280
|
-
https = base_https_cache[self._base]
|
|
281
|
-
if https:
|
|
282
|
-
channel = ClarifaiChannel.get_grpc_channel(base=self._base)
|
|
283
|
-
else:
|
|
284
|
-
if self._base.find(":") >= 0:
|
|
285
|
-
host, port = self._base.split(":")
|
|
286
|
-
else:
|
|
287
|
-
host = self._base
|
|
288
|
-
port = 80
|
|
289
|
-
channel = ClarifaiChannel.get_insecure_grpc_channel(base=host, port=port)
|
|
290
|
-
stub = service_pb2_grpc.V2Stub(channel)
|
|
291
|
-
return stub
|
|
292
|
-
|
|
293
|
-
@property
|
|
294
|
-
def ui(self) -> str:
|
|
295
|
-
""" Return the domain for the UI. """
|
|
296
|
-
if self._ui not in ui_https_cache:
|
|
297
|
-
raise Exception("Cannot determine if ui %s is https" % self._ui)
|
|
298
|
-
https = ui_https_cache[self._ui]
|
|
299
|
-
if https:
|
|
300
|
-
if not self._ui.startswith("https://"):
|
|
301
|
-
return "https://" + self._ui
|
|
302
|
-
return self._ui
|
|
303
|
-
if not self._ui.startswith("http://"):
|
|
304
|
-
return "http://" + self._ui
|
|
305
|
-
return self._ui
|
|
306
|
-
|
|
307
|
-
def set_base(self, base: str):
|
|
308
|
-
""" Set the base domain for the API. """
|
|
309
|
-
self._base = https_cache(base_https_cache, base)
|
|
310
|
-
|
|
311
|
-
def set_ui(self, ui: str):
|
|
312
|
-
""" Set the domain for the UI. """
|
|
313
|
-
self._ui = https_cache(ui_https_cache, ui)
|
|
314
|
-
|
|
315
|
-
@property
|
|
316
|
-
def base(self) -> str:
|
|
317
|
-
""" Return the base domain for the API. """
|
|
318
|
-
if self._base not in base_https_cache:
|
|
319
|
-
raise Exception("Cannot determine if base %s is https" % self._base)
|
|
320
|
-
https = base_https_cache[self._base]
|
|
321
|
-
if https:
|
|
322
|
-
if not self._base.startswith("https://"):
|
|
323
|
-
return "https://" + self._base
|
|
324
|
-
return self._base
|
|
325
|
-
if not self._base.startswith("http://"):
|
|
326
|
-
return "http://" + self._base
|
|
327
|
-
return self._base
|
|
328
|
-
|
|
329
|
-
@property
|
|
330
|
-
def pat(self) -> str:
|
|
331
|
-
""" Return the personal access token. """
|
|
332
|
-
return self._pat
|
|
333
|
-
|
|
334
|
-
def __str__(self):
|
|
335
|
-
return "ClarifaiAuthHelper:\n- base: %s\n- user_id: %s\n- app_id: %s\n" % (
|
|
336
|
-
self._base,
|
|
337
|
-
self.user_id,
|
|
338
|
-
self.app_id,
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
@classmethod
|
|
342
|
-
def required_env_vars(cls):
|
|
343
|
-
""" Return the list of the required environment variables. """
|
|
344
|
-
return ["CLARIFAI_USER_ID", "CLARIFAI_APP_ID", "CLARIFAI_PAT"]
|
|
345
|
-
|
|
346
|
-
@classmethod
|
|
347
|
-
def validate_secrets_dict(cls, toml_dict: Dict[str, Any]):
|
|
348
|
-
""" Validate the secrets.toml file has been filled with non-empty values for all the auth
|
|
349
|
-
parameters that are present.
|
|
350
|
-
|
|
351
|
-
We don't load the file here so that we don't need the tomli package dependency. You can simply
|
|
352
|
-
do:
|
|
353
|
-
import tomli
|
|
354
|
-
|
|
355
|
-
d = tomli.load(open("secrets.toml"))
|
|
356
|
-
ClarifaiAuthHelper.validate_secrets_dict(d)
|
|
357
|
-
|
|
358
|
-
"""
|
|
359
|
-
# We don't validate the bases because they have sensible defaults
|
|
360
|
-
auth_keys = cls.required_env_vars()
|
|
361
|
-
|
|
362
|
-
for k, v in toml_dict.items():
|
|
363
|
-
if k in auth_keys:
|
|
364
|
-
if v == "":
|
|
365
|
-
raise Exception("'%s' in secrets.toml cannot be empty" % k)
|
|
366
|
-
# for all the keys that are not present, they have a non empty value.
|
|
367
|
-
return True
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import grpc
|
|
3
|
-
|
|
4
|
-
from clarifai_grpc.grpc.api import service_pb2_grpc
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class V2Stub(abc.ABC):
|
|
8
|
-
"""Abstract base class of clarifai api rpc client stubs"""
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class RpcCallable(abc.ABC):
|
|
12
|
-
"""Abstract base class of clarifai api rpc callables"""
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# add grpc classes as subclasses of the abcs, so they also succeed in isinstance calls
|
|
16
|
-
def _register_classes():
|
|
17
|
-
V2Stub.register(service_pb2_grpc.V2Stub)
|
|
18
|
-
for name in dir(grpc):
|
|
19
|
-
if name.endswith('Callable'):
|
|
20
|
-
RpcCallable.register(getattr(grpc, name))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_register_classes()
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import time
|
|
3
|
-
from concurrent.futures import ThreadPoolExecutor
|
|
4
|
-
|
|
5
|
-
import grpc
|
|
6
|
-
from clarifai_grpc.grpc.api.status import status_code_pb2
|
|
7
|
-
|
|
8
|
-
from clarifai.client.auth.helper import ClarifaiAuthHelper
|
|
9
|
-
from clarifai.client.auth.register import RpcCallable, V2Stub
|
|
10
|
-
|
|
11
|
-
throttle_status_codes = {
|
|
12
|
-
status_code_pb2.CONN_THROTTLED,
|
|
13
|
-
status_code_pb2.CONN_EXCEED_HOURLY_LIMIT,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
retry_codes_grpc = {
|
|
17
|
-
grpc.StatusCode.UNAVAILABLE,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_threadpool = ThreadPoolExecutor(100)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def create_stub(auth_helper: ClarifaiAuthHelper = None, max_retry_attempts: int = 10) -> V2Stub:
|
|
24
|
-
"""
|
|
25
|
-
Create client stub that handles authorization and basic retries for
|
|
26
|
-
unavailable or throttled connections.
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
auth_helper: ClarifaiAuthHelper to use for auth metadata (default: from env)
|
|
30
|
-
max_retry_attempts: max attempts to retry rpcs with retryable failures
|
|
31
|
-
"""
|
|
32
|
-
stub = AuthorizedStub(auth_helper)
|
|
33
|
-
if max_retry_attempts > 0:
|
|
34
|
-
return RetryStub(stub, max_retry_attempts)
|
|
35
|
-
return stub
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class AuthorizedStub(V2Stub):
|
|
39
|
-
"""V2Stub proxy that inserts metadata authorization in rpc calls."""
|
|
40
|
-
|
|
41
|
-
def __init__(self, auth_helper: ClarifaiAuthHelper = None):
|
|
42
|
-
if auth_helper is None:
|
|
43
|
-
auth_helper = ClarifaiAuthHelper.from_env()
|
|
44
|
-
self.stub = auth_helper.get_stub()
|
|
45
|
-
self.metadata = auth_helper.metadata
|
|
46
|
-
|
|
47
|
-
def __getattr__(self, name):
|
|
48
|
-
value = getattr(self.stub, name)
|
|
49
|
-
if isinstance(value, RpcCallable):
|
|
50
|
-
value = _AuthorizedRpcCallable(value, self.metadata)
|
|
51
|
-
return value
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class _AuthorizedRpcCallable(RpcCallable):
|
|
55
|
-
"""Adds metadata(authorization header) to rpc calls"""
|
|
56
|
-
|
|
57
|
-
def __init__(self, func, metadata):
|
|
58
|
-
self.f = func
|
|
59
|
-
self.metadata = metadata
|
|
60
|
-
|
|
61
|
-
def __repr__(self):
|
|
62
|
-
return repr(self.f)
|
|
63
|
-
|
|
64
|
-
def __call__(self, *args, **kwargs):
|
|
65
|
-
metadata = kwargs.pop('metadata', self.metadata)
|
|
66
|
-
return self.f(*args, **kwargs, metadata=metadata)
|
|
67
|
-
|
|
68
|
-
def future(self, *args, **kwargs):
|
|
69
|
-
metadata = kwargs.pop('metadata', self.metadata)
|
|
70
|
-
return self.f.future(*args, **kwargs, metadata=metadata)
|
|
71
|
-
|
|
72
|
-
def __getattr__(self, name):
|
|
73
|
-
return getattr(self.f, name)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
class RetryStub(V2Stub):
|
|
77
|
-
"""
|
|
78
|
-
V2Stub proxy that retries requests (currently on unavailable server or throttle codes)
|
|
79
|
-
"""
|
|
80
|
-
|
|
81
|
-
def __init__(self, stub, max_attempts=10, backoff_time=5):
|
|
82
|
-
self.stub = stub
|
|
83
|
-
self.max_attempts = max_attempts
|
|
84
|
-
self.backoff_time = backoff_time
|
|
85
|
-
|
|
86
|
-
def __getattr__(self, name):
|
|
87
|
-
value = getattr(self.stub, name)
|
|
88
|
-
if isinstance(value, RpcCallable):
|
|
89
|
-
value = _RetryRpcCallable(value, self.max_attempts, self.backoff_time)
|
|
90
|
-
return value
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
class _RetryRpcCallable(RpcCallable):
|
|
94
|
-
"""Retries rpc calls on unavailable server or throttle codes"""
|
|
95
|
-
|
|
96
|
-
def __init__(self, func, max_attempts, backoff_time):
|
|
97
|
-
self.f = func
|
|
98
|
-
self.max_attempts = max_attempts
|
|
99
|
-
self.backoff_time = backoff_time
|
|
100
|
-
|
|
101
|
-
def __repr__(self):
|
|
102
|
-
return repr(self.f)
|
|
103
|
-
|
|
104
|
-
def __call__(self, *args, **kwargs):
|
|
105
|
-
attempt = 0
|
|
106
|
-
while attempt < self.max_attempts:
|
|
107
|
-
attempt += 1
|
|
108
|
-
if attempt != 1:
|
|
109
|
-
time.sleep(self.backoff_time) # TODO better backoff between attempts
|
|
110
|
-
try:
|
|
111
|
-
response = self.f(*args, **kwargs)
|
|
112
|
-
if (response.status.code in throttle_status_codes) and attempt < self.max_attempts:
|
|
113
|
-
logging.debug('Retrying with status %s' % str(response.status))
|
|
114
|
-
else:
|
|
115
|
-
return response
|
|
116
|
-
except grpc.RpcError as e:
|
|
117
|
-
if (e.code() in retry_codes_grpc) and attempt < self.max_attempts:
|
|
118
|
-
logging.debug('Retrying with status %s' % e.code())
|
|
119
|
-
else:
|
|
120
|
-
raise
|
|
121
|
-
|
|
122
|
-
def future(self, *args, **kwargs):
|
|
123
|
-
# TODO use single result event loop thread with asyncio
|
|
124
|
-
return _threadpool.submit(self, *args, **kwargs)
|
|
125
|
-
|
|
126
|
-
def __getattr__(self, name):
|
|
127
|
-
return getattr(self.f, name)
|
clarifai_utils/client/base.py
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from typing import Any, Callable
|
|
4
|
-
|
|
5
|
-
from google.protobuf import struct_pb2
|
|
6
|
-
from google.protobuf.timestamp_pb2 import Timestamp
|
|
7
|
-
from google.protobuf.wrappers_pb2 import BoolValue
|
|
8
|
-
|
|
9
|
-
from clarifai.client.auth import create_stub
|
|
10
|
-
from clarifai.client.auth.helper import ClarifaiAuthHelper
|
|
11
|
-
from clarifai.errors import ApiError, UserError
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class BaseClient:
|
|
15
|
-
"""BaseClient is the base class for all the classes interacting with Clarifai endpoints.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
**kwargs: Additional keyword arguments to be passed to the ClarifaiAuthHelper.
|
|
19
|
-
- user_id (str): A user ID for authentication.
|
|
20
|
-
- app_id (str): An app ID for the application to interact with.
|
|
21
|
-
- pat (str): A personal access token for authentication.
|
|
22
|
-
- base (str): The base URL for the API endpoint. Defaults to 'https://api.clarifai.com'.
|
|
23
|
-
- ui (str): The URL for the UI. Defaults to 'https://clarifai.com'.
|
|
24
|
-
|
|
25
|
-
Attributes:
|
|
26
|
-
auth_helper (ClarifaiAuthHelper): An instance of ClarifaiAuthHelper for authentication.
|
|
27
|
-
STUB (Stub): The gRPC Stub object for API interaction.
|
|
28
|
-
metadata (tuple): The gRPC metadata containing the personal access token.
|
|
29
|
-
userDataObject (UserAppIDSet): The protobuf object representing user and app IDs.
|
|
30
|
-
base (str): The base URL for the API endpoint.
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
def __init__(self, **kwargs):
|
|
34
|
-
pat = os.environ.get('CLARIFAI_PAT', "")
|
|
35
|
-
if pat == "":
|
|
36
|
-
raise UserError("CLARIFAI_PAT must be set as env vars")
|
|
37
|
-
self.auth_helper = ClarifaiAuthHelper(**kwargs, pat=pat, validate=False)
|
|
38
|
-
self.STUB = create_stub(self.auth_helper)
|
|
39
|
-
self.metadata = self.auth_helper.metadata
|
|
40
|
-
self.user_app_id = self.auth_helper.get_user_app_id_proto()
|
|
41
|
-
self.base = self.auth_helper.base
|
|
42
|
-
|
|
43
|
-
def _grpc_request(self, method: Callable, argument: Any):
|
|
44
|
-
"""Makes a gRPC request to the API.
|
|
45
|
-
|
|
46
|
-
Args:
|
|
47
|
-
method (Callable): The gRPC method to call.
|
|
48
|
-
argument (Any): The argument to pass to the gRPC method.
|
|
49
|
-
|
|
50
|
-
Returns:
|
|
51
|
-
res (Any): The result of the gRPC method call.
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
|
-
try:
|
|
55
|
-
res = method(argument)
|
|
56
|
-
# MessageToDict(res) TODO global debug logger
|
|
57
|
-
return res
|
|
58
|
-
except ApiError:
|
|
59
|
-
raise Exception("ApiError")
|
|
60
|
-
|
|
61
|
-
def convert_string_to_timestamp(self, date_str) -> Timestamp:
|
|
62
|
-
"""Converts a string to a Timestamp object.
|
|
63
|
-
|
|
64
|
-
Args:
|
|
65
|
-
date_str (str): The string to convert.
|
|
66
|
-
|
|
67
|
-
Returns:
|
|
68
|
-
Timestamp: The converted Timestamp object.
|
|
69
|
-
"""
|
|
70
|
-
# Parse the string into a Python datetime object
|
|
71
|
-
try:
|
|
72
|
-
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
|
|
73
|
-
except ValueError:
|
|
74
|
-
try:
|
|
75
|
-
datetime_obj = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
|
|
76
|
-
except ValueError:
|
|
77
|
-
return Timestamp()
|
|
78
|
-
|
|
79
|
-
# Convert the datetime object to a Timestamp object
|
|
80
|
-
timestamp_obj = Timestamp()
|
|
81
|
-
timestamp_obj.FromDatetime(datetime_obj)
|
|
82
|
-
|
|
83
|
-
return timestamp_obj
|
|
84
|
-
|
|
85
|
-
def process_response_keys(self, old_dict, listing_resource=None):
|
|
86
|
-
"""Converts keys in a response dictionary to resource proto format.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
old_dict (dict): The dictionary to convert.
|
|
90
|
-
|
|
91
|
-
Returns:
|
|
92
|
-
new_dict (dict): The dictionary with processed keys.
|
|
93
|
-
"""
|
|
94
|
-
if listing_resource:
|
|
95
|
-
old_dict[f'{listing_resource}_id'] = old_dict['id']
|
|
96
|
-
old_dict.pop('id')
|
|
97
|
-
|
|
98
|
-
def convert_recursive(item):
|
|
99
|
-
if isinstance(item, dict):
|
|
100
|
-
new_item = {}
|
|
101
|
-
for key, value in item.items():
|
|
102
|
-
if key == 'default_value':
|
|
103
|
-
# Map infer param value to proto value
|
|
104
|
-
value_map = dict(number_value=None, string_value=None, bool_value=None)
|
|
105
|
-
|
|
106
|
-
def map_fn(v):
|
|
107
|
-
return 'number_value' if isinstance(v, float) or isinstance(v, int) else \
|
|
108
|
-
'string_value' if isinstance(v, str) else \
|
|
109
|
-
'bool_value' if isinstance(v, bool) else None
|
|
110
|
-
|
|
111
|
-
value_map[map_fn(value)] = value
|
|
112
|
-
value = struct_pb2.Value(**value_map)
|
|
113
|
-
if key in ['created_at', 'modified_at', 'completed_at']:
|
|
114
|
-
value = self.convert_string_to_timestamp(value)
|
|
115
|
-
elif key in ['workflow_recommended']:
|
|
116
|
-
value = BoolValue(value=True)
|
|
117
|
-
elif key in ['fields_map', 'params']:
|
|
118
|
-
value_s = struct_pb2.Struct()
|
|
119
|
-
value_s.update(value)
|
|
120
|
-
value = value_s
|
|
121
|
-
elif key in ['metadata']:
|
|
122
|
-
continue # TODO Fix "app_duplication"
|
|
123
|
-
new_item[key] = convert_recursive(value)
|
|
124
|
-
return new_item
|
|
125
|
-
elif isinstance(item, list):
|
|
126
|
-
return [convert_recursive(element) for element in item]
|
|
127
|
-
else:
|
|
128
|
-
return item
|
|
129
|
-
|
|
130
|
-
new_dict = convert_recursive(old_dict)
|
|
131
|
-
return new_dict
|