clarifai 10.9.5__tar.gz → 10.10.1__tar.gz

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.
Files changed (120) hide show
  1. {clarifai-10.9.5/clarifai.egg-info → clarifai-10.10.1}/PKG-INFO +1 -1
  2. clarifai-10.10.1/clarifai/__init__.py +1 -0
  3. clarifai-10.10.1/clarifai/cli/README.md +87 -0
  4. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/cli/base.py +41 -3
  5. clarifai-10.10.1/clarifai/cli/compute_cluster.py +51 -0
  6. clarifai-10.10.1/clarifai/cli/deployment.py +84 -0
  7. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/cli/model.py +1 -1
  8. clarifai-10.10.1/clarifai/cli/nodepool.py +91 -0
  9. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/auth/helper.py +1 -0
  10. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/compute_cluster.py +5 -4
  11. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/dataset.py +21 -0
  12. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/deployment.py +2 -1
  13. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/input.py +27 -0
  14. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/nodepool.py +5 -4
  15. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/user.py +6 -5
  16. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/multimodal.py +0 -2
  17. clarifai-10.9.5/clarifai/runners/dockerfile_template/Dockerfile.cpu.template → clarifai-10.10.1/clarifai/runners/dockerfile_template/Dockerfile.template +21 -11
  18. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/model_upload.py +100 -12
  19. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/cli.py +25 -0
  20. {clarifai-10.9.5 → clarifai-10.10.1/clarifai.egg-info}/PKG-INFO +1 -1
  21. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai.egg-info/SOURCES.txt +5 -2
  22. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_app.py +1 -1
  23. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_data_upload.py +3 -0
  24. clarifai-10.9.5/clarifai/__init__.py +0 -1
  25. clarifai-10.9.5/clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -83
  26. {clarifai-10.9.5 → clarifai-10.10.1}/LICENSE +0 -0
  27. {clarifai-10.9.5 → clarifai-10.10.1}/MANIFEST.in +0 -0
  28. {clarifai-10.9.5 → clarifai-10.10.1}/README.md +0 -0
  29. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/cli/__init__.py +0 -0
  30. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/cli.py +0 -0
  31. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/__init__.py +0 -0
  32. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/app.py +0 -0
  33. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/auth/__init__.py +0 -0
  34. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/auth/register.py +0 -0
  35. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/auth/stub.py +0 -0
  36. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/base.py +0 -0
  37. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/lister.py +0 -0
  38. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/model.py +0 -0
  39. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/module.py +0 -0
  40. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/search.py +0 -0
  41. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/client/workflow.py +0 -0
  42. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/base.py +0 -0
  43. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/dataset.py +0 -0
  44. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/input.py +0 -0
  45. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/model.py +0 -0
  46. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/rag.py +0 -0
  47. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/search.py +0 -0
  48. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/constants/workflow.py +0 -0
  49. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/__init__.py +0 -0
  50. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/export/__init__.py +0 -0
  51. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/export/inputs_annotations.py +0 -0
  52. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/__init__.py +0 -0
  53. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/base.py +0 -0
  54. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/features.py +0 -0
  55. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/image.py +0 -0
  56. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/README.md +0 -0
  57. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/__init__.py +0 -0
  58. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/coco_captions.py +0 -0
  59. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/coco_detection.py +0 -0
  60. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/imagenet_classification.py +0 -0
  61. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/loaders/xview_detection.py +0 -0
  62. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/text.py +0 -0
  63. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/datasets/upload/utils.py +0 -0
  64. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/errors.py +0 -0
  65. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/models/__init__.py +0 -0
  66. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/models/api.py +0 -0
  67. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/modules/README.md +0 -0
  68. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/modules/__init__.py +0 -0
  69. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/modules/css.py +0 -0
  70. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/modules/pages.py +0 -0
  71. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/modules/style.css +0 -0
  72. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/rag/__init__.py +0 -0
  73. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/rag/rag.py +0 -0
  74. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/rag/utils.py +0 -0
  75. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/__init__.py +0 -0
  76. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/__init__.py +0 -0
  77. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/base_typed_model.py +0 -0
  78. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/model_class.py +0 -0
  79. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/model_run_locally.py +0 -0
  80. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/model_runner.py +0 -0
  81. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/models/model_servicer.py +0 -0
  82. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/server.py +0 -0
  83. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/utils/__init__.py +0 -0
  84. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/utils/data_handler.py +0 -0
  85. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/utils/data_utils.py +0 -0
  86. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/utils/loader.py +0 -0
  87. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/runners/utils/url_fetcher.py +0 -0
  88. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/schema/search.py +0 -0
  89. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/urls/helper.py +0 -0
  90. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/__init__.py +0 -0
  91. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/constants.py +0 -0
  92. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/evaluation/__init__.py +0 -0
  93. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/evaluation/helpers.py +0 -0
  94. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/evaluation/main.py +0 -0
  95. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/evaluation/testset_annotation_parser.py +0 -0
  96. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/logging.py +0 -0
  97. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/misc.py +0 -0
  98. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/utils/model_train.py +0 -0
  99. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/versions.py +0 -0
  100. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/workflows/__init__.py +0 -0
  101. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/workflows/export.py +0 -0
  102. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/workflows/utils.py +0 -0
  103. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai/workflows/validate.py +0 -0
  104. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai.egg-info/dependency_links.txt +0 -0
  105. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai.egg-info/entry_points.txt +0 -0
  106. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai.egg-info/requires.txt +0 -0
  107. {clarifai-10.9.5 → clarifai-10.10.1}/clarifai.egg-info/top_level.txt +0 -0
  108. {clarifai-10.9.5 → clarifai-10.10.1}/pyproject.toml +0 -0
  109. {clarifai-10.9.5 → clarifai-10.10.1}/requirements.txt +0 -0
  110. {clarifai-10.9.5 → clarifai-10.10.1}/setup.cfg +0 -0
  111. {clarifai-10.9.5 → clarifai-10.10.1}/setup.py +0 -0
  112. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_auth.py +0 -0
  113. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_eval.py +0 -0
  114. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_misc.py +0 -0
  115. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_model_predict.py +0 -0
  116. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_model_train.py +0 -0
  117. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_modules.py +0 -0
  118. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_rag.py +0 -0
  119. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_search.py +0 -0
  120. {clarifai-10.9.5 → clarifai-10.10.1}/tests/test_stub.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clarifai
3
- Version: 10.9.5
3
+ Version: 10.10.1
4
4
  Summary: Clarifai Python SDK
5
5
  Home-page: https://github.com/Clarifai/clarifai-python
6
6
  Author: Clarifai
@@ -0,0 +1 @@
1
+ __version__ = "10.10.1"
@@ -0,0 +1,87 @@
1
+ # Clarifai CLI
2
+
3
+ ## Overview
4
+
5
+ Clarifai offers a user-friendly interface for deploying your local model into production with Clarifai, featuring:
6
+
7
+ * A convenient command-line interface (CLI)
8
+ * Easy implementation and testing in Python
9
+ * No need for MLops expertise.
10
+
11
+ ## Compute Orchestration
12
+
13
+ Quick example for deploying a `visual-classifier` model
14
+
15
+ ### Login
16
+
17
+ First, login to cli using clarifai account details in a config file as shown below:
18
+
19
+ ```bash
20
+ $ clarifai login --config <config-filepath>
21
+ ```
22
+
23
+ ### Setup
24
+
25
+ To prepare for deployment step, we have to setup a Compute Cluster with Nodepool of required server config to deploy the model.
26
+
27
+ So, First, create a new Compute Cluster
28
+ ```bash
29
+ $ clarifai computecluster create --config <compute-cluster-config-filepath>
30
+ ```
31
+
32
+ Then, create a new Nodepool in the created Compute Cluster
33
+ ```bash
34
+ $ clarifai nodepool create --config <nodepool-config-filepath>
35
+ ```
36
+
37
+ ### Deployment
38
+
39
+ After setup, we can deploy the `visual-classifier` model using a deployment config file as shown below:
40
+
41
+ ```bash
42
+ $ clarifai deployment create --config <deployment-config-filepath>
43
+ ```
44
+
45
+ ### List Resources
46
+
47
+ List out existing Compute Clusters:
48
+
49
+ ```bash
50
+ $ clarifai computecluster list
51
+ ```
52
+
53
+ List out existing Nodepools:
54
+
55
+ ```bash
56
+ $ clarifai nodepool list --compute_cluster_id <compute-cluster-id>
57
+ ```
58
+
59
+ List out existing Deployments:
60
+
61
+ ```bash
62
+ $ clarifai deployment list --nodepool_id <nodepool-id>
63
+ ```
64
+
65
+ ### Delete Resources
66
+
67
+ Delete existing Deployment:
68
+
69
+ ```bash
70
+ $ clarifai deployment delete --nodepool_id <nodepool-id> --deployment_id <deployment-id>
71
+ ```
72
+
73
+ Delete existing Nodepool:
74
+
75
+ ```bash
76
+ $ clarifai nodepool delete --compute_cluster_id <compute-cluster-id> --nodepool_id <nodepool-id>
77
+ ```
78
+
79
+ Delete existing Compute Clusters:
80
+
81
+ ```bash
82
+ $ clarifai computecluster delete --compute_cluster_id <compute-cluster-id>
83
+ ```
84
+
85
+ ## Learn More
86
+
87
+ * [Example Configs](https://github.com/Clarifai/examples/tree/main/ComputeOrchestration/configs)
@@ -5,7 +5,38 @@ import click
5
5
  from ..utils.cli import dump_yaml, from_yaml, load_command_modules, set_base_url
6
6
 
7
7
 
8
- @click.group()
8
+ class CustomMultiGroup(click.Group):
9
+
10
+ def group(self, *args, **kwargs):
11
+ """Behaves the same as `click.Group.group()` except if passed
12
+ a list of names, all after the first will be aliases for the first.
13
+ """
14
+
15
+ def decorator(f):
16
+ aliased_group = []
17
+ if isinstance(args[0], list):
18
+ # we have a list so create group aliases
19
+ _args = [args[0][0]] + list(args[1:])
20
+ for alias in args[0][1:]:
21
+ grp = super(CustomMultiGroup, self).group(alias, *args[1:], **kwargs)(f)
22
+ grp.short_help = "Alias for '{}'".format(_args[0])
23
+ aliased_group.append(grp)
24
+ else:
25
+ _args = args
26
+
27
+ # create the main group
28
+ grp = super(CustomMultiGroup, self).group(*_args, **kwargs)(f)
29
+
30
+ # for all of the aliased groups, share the main group commands
31
+ for aliased in aliased_group:
32
+ aliased.commands = grp.commands
33
+
34
+ return grp
35
+
36
+ return decorator
37
+
38
+
39
+ @click.group(cls=CustomMultiGroup)
9
40
  @click.pass_context
10
41
  def cli(ctx):
11
42
  """Clarifai CLI"""
@@ -49,9 +80,16 @@ def login(ctx, config, env, user_id):
49
80
  if user_id:
50
81
  ctx.obj['user_id'] = user_id
51
82
  os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
52
- elif 'user_id' in ctx.obj or 'CLARIFAI_USER_ID' in os.environ:
53
- ctx.obj['user_id'] = ctx.obj.get('user_id', os.environ["CLARIFAI_USER_ID"])
83
+ elif 'user_id' in ctx.obj:
84
+ ctx.obj['user_id'] = ctx.obj.get('user_id', "")
54
85
  os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
86
+ elif 'CLARIFAI_USER_ID' in os.environ:
87
+ ctx.obj['user_id'] = os.environ["CLARIFAI_USER_ID"]
88
+ else:
89
+ user_id = click.prompt("Pass the User ID here", type=str)
90
+ os.environ["CLARIFAI_USER_ID"] = user_id
91
+ ctx.obj['user_id'] = user_id
92
+ click.echo("User ID saved successfully.")
55
93
 
56
94
  if env:
57
95
  ctx.obj['env'] = env
@@ -0,0 +1,51 @@
1
+ import click
2
+ from clarifai.cli.base import cli
3
+ from clarifai.client.user import User
4
+ from clarifai.utils.cli import display_co_resources
5
+
6
+
7
+ @cli.group(['computecluster', 'cc'])
8
+ def computecluster():
9
+ """Manage Compute Clusters: create, delete, list"""
10
+ pass
11
+
12
+
13
+ @computecluster.command()
14
+ @click.option(
15
+ '--config',
16
+ type=click.Path(exists=True),
17
+ required=True,
18
+ help='Path to the compute cluster config file.')
19
+ @click.option(
20
+ '-cc_id',
21
+ '--compute_cluster_id',
22
+ required=False,
23
+ help='New Compute Cluster ID for the compute cluster to create.')
24
+ @click.pass_context
25
+ def create(ctx, config, compute_cluster_id):
26
+ """Create a new Compute Cluster with the given config file."""
27
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
28
+ if compute_cluster_id:
29
+ user.create_compute_cluster(config, compute_cluster_id=compute_cluster_id)
30
+ else:
31
+ user.create_compute_cluster(config)
32
+
33
+
34
+ @computecluster.command()
35
+ @click.option('--page_no', required=False, help='Page number to list.', default=1)
36
+ @click.option('--per_page', required=False, help='Number of items per page.', default=16)
37
+ @click.pass_context
38
+ def list(ctx, page_no, per_page):
39
+ """List all compute clusters for the user."""
40
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
41
+ response = user.list_compute_clusters(page_no, per_page)
42
+ display_co_resources(response, "Compute Cluster")
43
+
44
+
45
+ @computecluster.command()
46
+ @click.option('-cc_id', '--compute_cluster_id', help='Compute Cluster ID of the user to delete.')
47
+ @click.pass_context
48
+ def delete(ctx, compute_cluster_id):
49
+ """Deletes a compute cluster for the user."""
50
+ user = User(user_id=ctx.obj['user_id'], pat=ctx.obj['pat'], base_url=ctx.obj['base_url'])
51
+ user.delete_compute_clusters([compute_cluster_id])
@@ -0,0 +1,84 @@
1
+ import click
2
+ from clarifai.cli.base import cli
3
+ from clarifai.client.nodepool import Nodepool
4
+ from clarifai.utils.cli import display_co_resources, from_yaml
5
+
6
+
7
+ @cli.group(['deployment', 'dpl'])
8
+ def deployment():
9
+ """Manage Deployments: create, delete, list"""
10
+ pass
11
+
12
+
13
+ @deployment.command()
14
+ @click.option(
15
+ '-np_id',
16
+ '--nodepool_id',
17
+ required=False,
18
+ help='Nodepool ID for the Nodepool to interact with.')
19
+ @click.option(
20
+ '--config',
21
+ type=click.Path(exists=True),
22
+ required=True,
23
+ help='Path to the deployment config file.')
24
+ @click.option(
25
+ '-dpl_id',
26
+ '--deployment_id',
27
+ required=False,
28
+ help='New deployment ID for the deployment to create.')
29
+ @click.pass_context
30
+ def create(ctx, nodepool_id, config, deployment_id):
31
+ """Create a new Deployment with the given config file."""
32
+ if not nodepool_id:
33
+ deployment_config = from_yaml(config)
34
+ nodepool_id = deployment_config['deployment']['nodepools'][0]['id']
35
+
36
+ nodepool = Nodepool(
37
+ nodepool_id=nodepool_id,
38
+ user_id=ctx.obj['user_id'],
39
+ pat=ctx.obj['pat'],
40
+ base_url=ctx.obj['base_url'])
41
+ if deployment_id:
42
+ nodepool.create_deployment(config, deployment_id=deployment_id)
43
+ else:
44
+ nodepool.create_deployment(config)
45
+
46
+
47
+ @deployment.command()
48
+ @click.option(
49
+ '-np_id',
50
+ '--nodepool_id',
51
+ required=True,
52
+ help='Nodepool ID for the Nodepool to interact with.')
53
+ @click.option('--page_no', required=False, help='Page number to list.', default=1)
54
+ @click.option('--per_page', required=False, help='Number of items per page.', default=16)
55
+ @click.pass_context
56
+ def list(ctx, nodepool_id, page_no, per_page):
57
+ """List all deployments for the nodepool."""
58
+
59
+ nodepool = Nodepool(
60
+ nodepool_id=nodepool_id,
61
+ user_id=ctx.obj['user_id'],
62
+ pat=ctx.obj['pat'],
63
+ base_url=ctx.obj['base_url'])
64
+ response = nodepool.list_deployments(page_no=page_no, per_page=per_page)
65
+ display_co_resources(response, "Deployment")
66
+
67
+
68
+ @deployment.command()
69
+ @click.option(
70
+ '-np_id',
71
+ '--nodepool_id',
72
+ required=True,
73
+ help='Nodepool ID for the Nodepool to interact with.')
74
+ @click.option('-dpl_id', '--deployment_id', help='Deployment ID of the nodepool to delete.')
75
+ @click.pass_context
76
+ def delete(ctx, nodepool_id, deployment_id):
77
+ """Deletes a deployment for the nodepool."""
78
+
79
+ nodepool = Nodepool(
80
+ nodepool_id=nodepool_id,
81
+ user_id=ctx.obj['user_id'],
82
+ pat=ctx.obj['pat'],
83
+ base_url=ctx.obj['base_url'])
84
+ nodepool.delete_deployments([deployment_id])
@@ -2,7 +2,7 @@ import click
2
2
  from clarifai.cli.base import cli
3
3
 
4
4
 
5
- @cli.group()
5
+ @cli.group(['model'])
6
6
  def model():
7
7
  """Manage models: upload, test locally"""
8
8
  pass
@@ -0,0 +1,91 @@
1
+ import click
2
+ from clarifai.cli.base import cli
3
+ from clarifai.client.compute_cluster import ComputeCluster
4
+ from clarifai.utils.cli import display_co_resources, dump_yaml, from_yaml
5
+
6
+
7
+ @cli.group(['nodepool', 'np'])
8
+ def nodepool():
9
+ """Manage Nodepools: create, delete, list"""
10
+ pass
11
+
12
+
13
+ @nodepool.command()
14
+ @click.option(
15
+ '-cc_id',
16
+ '--compute_cluster_id',
17
+ required=False,
18
+ help='Compute Cluster ID for the compute cluster to interact with.')
19
+ @click.option(
20
+ '--config',
21
+ type=click.Path(exists=True),
22
+ required=True,
23
+ help='Path to the nodepool config file.')
24
+ @click.option(
25
+ '-np_id', '--nodepool_id', required=False, help='New Nodepool ID for the nodepool to create.')
26
+ @click.pass_context
27
+ def create(ctx, compute_cluster_id, config, nodepool_id):
28
+ """Create a new Nodepool with the given config file."""
29
+
30
+ nodepool_config = from_yaml(config)
31
+ if not compute_cluster_id:
32
+ if 'compute_cluster' not in nodepool_config['nodepool']:
33
+ click.echo(
34
+ "Please provide a compute cluster ID either in the config file or using --compute_cluster_id flag",
35
+ err=True)
36
+ return
37
+ compute_cluster_id = nodepool_config['nodepool']['compute_cluster']['id']
38
+ else:
39
+ if 'compute_cluster' not in nodepool_config['nodepool']:
40
+ nodepool_config['nodepool']['compute_cluster']['id'] = compute_cluster_id
41
+ dump_yaml(config, nodepool_config)
42
+
43
+ compute_cluster = ComputeCluster(
44
+ compute_cluster_id=compute_cluster_id,
45
+ user_id=ctx.obj['user_id'],
46
+ pat=ctx.obj['pat'],
47
+ base_url=ctx.obj['base_url'])
48
+ if nodepool_id:
49
+ compute_cluster.create_nodepool(config, nodepool_id=nodepool_id)
50
+ else:
51
+ compute_cluster.create_nodepool(config)
52
+
53
+
54
+ @nodepool.command()
55
+ @click.option(
56
+ '-cc_id',
57
+ '--compute_cluster_id',
58
+ required=True,
59
+ help='Compute Cluster ID for the compute cluster to interact with.')
60
+ @click.option('--page_no', required=False, help='Page number to list.', default=1)
61
+ @click.option('--per_page', required=False, help='Number of items per page.', default=16)
62
+ @click.pass_context
63
+ def list(ctx, compute_cluster_id, page_no, per_page):
64
+ """List all nodepools for the user."""
65
+
66
+ compute_cluster = ComputeCluster(
67
+ compute_cluster_id=compute_cluster_id,
68
+ user_id=ctx.obj['user_id'],
69
+ pat=ctx.obj['pat'],
70
+ base_url=ctx.obj['base_url'])
71
+ response = compute_cluster.list_nodepools(page_no, per_page)
72
+ display_co_resources(response, "Nodepool")
73
+
74
+
75
+ @nodepool.command()
76
+ @click.option(
77
+ '-cc_id',
78
+ '--compute_cluster_id',
79
+ required=True,
80
+ help='Compute Cluster ID for the compute cluster to interact with.')
81
+ @click.option('-np_id', '--nodepool_id', help='Nodepool ID of the user to delete.')
82
+ @click.pass_context
83
+ def delete(ctx, compute_cluster_id, nodepool_id):
84
+ """Deletes a nodepool for the user."""
85
+
86
+ compute_cluster = ComputeCluster(
87
+ compute_cluster_id=compute_cluster_id,
88
+ user_id=ctx.obj['user_id'],
89
+ pat=ctx.obj['pat'],
90
+ base_url=ctx.obj['base_url'])
91
+ compute_cluster.delete_nodepools([nodepool_id])
@@ -321,6 +321,7 @@ Additionally, these optional params are supported:
321
321
 
322
322
  def set_base(self, base: str):
323
323
  """ Set the base domain for the API. """
324
+ base = DEFAULT_BASE if base is None else base
324
325
  self._base = https_cache(base_https_cache, base)
325
326
 
326
327
  def set_ui(self, ui: str):
@@ -102,12 +102,12 @@ class ComputeCluster(Lister, BaseClient):
102
102
  nodepool["visibility"] = resources_pb2.Visibility(**nodepool["visibility"])
103
103
  return nodepool
104
104
 
105
- def create_nodepool(self, nodepool_id: str, config_filepath: str) -> Nodepool:
105
+ def create_nodepool(self, config_filepath: str, nodepool_id: str = None) -> Nodepool:
106
106
  """Creates a nodepool for the compute cluster.
107
107
 
108
108
  Args:
109
- nodepool_id (str): The nodepool ID for the nodepool to create.
110
109
  config_filepath (str): The path to the nodepool config file.
110
+ nodepool_id (str): New nodepool ID for the nodepool to create.
111
111
 
112
112
  Returns:
113
113
  Nodepool: A Nodepool object for the specified nodepool ID.
@@ -115,7 +115,7 @@ class ComputeCluster(Lister, BaseClient):
115
115
  Example:
116
116
  >>> from clarifai.client.compute_cluster import ComputeCluster
117
117
  >>> compute_cluster = ComputeCluster(compute_cluster_id="compute_cluster_id", user_id="user_id")
118
- >>> nodepool = compute_cluster.create_nodepool(nodepool_id="nodepool_id", config_filepath="config.yml")
118
+ >>> nodepool = compute_cluster.create_nodepool(config_filepath="config.yml")
119
119
  """
120
120
  if not os.path.exists(config_filepath):
121
121
  raise UserError(f"Nodepool config file not found at {config_filepath}")
@@ -123,7 +123,8 @@ class ComputeCluster(Lister, BaseClient):
123
123
  nodepool_config = self._process_nodepool_config(config_filepath)
124
124
 
125
125
  if 'id' in nodepool_config:
126
- nodepool_id = nodepool_config['id']
126
+ if nodepool_id is None:
127
+ nodepool_id = nodepool_config['id']
127
128
  nodepool_config.pop('id')
128
129
 
129
130
  request = service_pb2.PostNodepoolsRequest(
@@ -9,6 +9,7 @@ from typing import Dict, Generator, List, Optional, Tuple, Type, TypeVar, Union
9
9
 
10
10
  import requests
11
11
  from clarifai_grpc.grpc.api import resources_pb2, service_pb2
12
+ from clarifai_grpc.grpc.api.resources_pb2 import Input
12
13
  from clarifai_grpc.grpc.api.service_pb2 import MultiInputResponse
13
14
  from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
14
15
  from google.protobuf.json_format import MessageToDict
@@ -190,6 +191,26 @@ class Dataset(Lister, BaseClient):
190
191
  }
191
192
  yield Dataset.from_auth_helper(self.auth_helper, **kwargs)
192
193
 
194
+ def list_inputs(self, page_no: int = None, per_page: int = None,
195
+ input_type: str = None) -> Generator[Input, None, None]:
196
+ """Lists all the inputs for the dataset.
197
+
198
+ Args:
199
+ page_no (int): The page number to list.
200
+ per_page (int): The number of items per page.
201
+ input_type (str): The type of input to list. Options: 'image', 'video', 'audio', 'text'.
202
+
203
+ Yields:
204
+ Input: Input objects in the dataset.
205
+
206
+ Example:
207
+ >>> from clarifai.client.dataset import Dataset
208
+ >>> dataset = Dataset(dataset_id='dataset_id', user_id='user_id', app_id='app_id')
209
+ >>> all_dataset_inputs = list(dataset.list_inputs())
210
+ """
211
+ return self.input_object.list_inputs(
212
+ dataset_id=self.id, page_no=page_no, per_page=per_page, input_type=input_type)
213
+
193
214
  def __iter__(self):
194
215
  return iter(DatasetExportReader(archive_url=self.archive_zip()))
195
216
 
@@ -49,7 +49,8 @@ class Deployment(Lister, BaseClient):
49
49
  Returns:
50
50
  resources_pb2.RunnerSelector: A RunnerSelector object for the given deployment_id.
51
51
  """
52
- return resources_pb2.RunnerSelector(deployment_id=deployment_id, user_id=user_id)
52
+ return resources_pb2.RunnerSelector(
53
+ deployment=resources_pb2.Deployment(id=deployment_id, user_id=user_id))
53
54
 
54
55
  def __getattr__(self, name):
55
56
  return getattr(self.deployment_info, name)
@@ -867,6 +867,33 @@ class Inputs(Lister, BaseClient):
867
867
  raise Exception(response.status)
868
868
  self.logger.info("\nInputs Deleted\n%s", response.status)
869
869
 
870
+ def delete_annotations(self, input_ids: List[str], annotation_ids: List[str] = []) -> None:
871
+ """Delete list of annotations of input objects from the app.
872
+
873
+ Args:
874
+ input_ids (Input): List of input objects for which annotations to delete.
875
+ annotation_ids (List[str]): List of annotation ids to delete.
876
+
877
+ Example:
878
+ >>> from clarifai.client.user import User
879
+ >>> input_obj = User(user_id="user_id").app(app_id="app_id").inputs()
880
+ >>> input_obj.delete_annotations(input_ids=['input_id_1', 'input_id_2'])
881
+
882
+ Note:
883
+ 'annotation_ids' are optional but if the are provided, the number and order in
884
+ 'annotation_ids' and 'input_ids' should match
885
+ """
886
+ if not isinstance(input_ids, list):
887
+ raise UserError("input_ids must be a list of input ids")
888
+ if annotation_ids and len(input_ids) != len(annotation_ids):
889
+ raise UserError("Number of provided annotation_ids and input_ids should match.")
890
+ request = service_pb2.DeleteAnnotationsRequest(
891
+ user_app_id=self.user_app_id, ids=annotation_ids, input_ids=input_ids)
892
+ response = self._grpc_request(self.STUB.DeleteAnnotations, request)
893
+ if response.status.code != status_code_pb2.SUCCESS:
894
+ raise Exception(response.status)
895
+ self.logger.info("\nAnnotations Deleted\n%s", response.status)
896
+
870
897
  def download_inputs(self, inputs: List[Input]) -> List[bytes]:
871
898
  """Download list of input objects from the app.
872
899
 
@@ -136,12 +136,12 @@ class Nodepool(Lister, BaseClient):
136
136
  nodepool = resources_pb2.Nodepool(id=nodepool_id, compute_cluster=compute_cluster)
137
137
  return resources_pb2.RunnerSelector(nodepool=nodepool)
138
138
 
139
- def create_deployment(self, deployment_id: str, config_filepath: str) -> Deployment:
139
+ def create_deployment(self, config_filepath: str, deployment_id: str = None) -> Deployment:
140
140
  """Creates a deployment for the nodepool.
141
141
 
142
142
  Args:
143
- deployment_id (str): The deployment ID for the deployment to create.
144
143
  config_filepath (str): The path to the deployment config file.
144
+ deployment_id (str): New deployment ID for the deployment to create.
145
145
 
146
146
  Returns:
147
147
  Deployment: A Deployment object for the specified deployment ID.
@@ -149,7 +149,7 @@ class Nodepool(Lister, BaseClient):
149
149
  Example:
150
150
  >>> from clarifai.client.nodepool import Nodepool
151
151
  >>> nodepool = Nodepool(nodepool_id="nodepool_id", user_id="user_id")
152
- >>> deployment = nodepool.create_deployment(deployment_id="deployment_id", config_filepath="config.yml")
152
+ >>> deployment = nodepool.create_deployment(config_filepath="config.yml")
153
153
  """
154
154
  if not os.path.exists(config_filepath):
155
155
  raise UserError(f"Deployment config file not found at {config_filepath}")
@@ -157,7 +157,8 @@ class Nodepool(Lister, BaseClient):
157
157
  deployment_config = self._process_deployment_config(config_filepath)
158
158
 
159
159
  if 'id' in deployment_config:
160
- deployment_id = deployment_config['id']
160
+ if deployment_id is None:
161
+ deployment_id = deployment_config['id']
161
162
  deployment_config.pop('id')
162
163
 
163
164
  request = service_pb2.PostDeploymentsRequest(
@@ -222,13 +222,13 @@ class User(Lister, BaseClient):
222
222
  compute_cluster["visibility"] = resources_pb2.Visibility(**compute_cluster["visibility"])
223
223
  return compute_cluster
224
224
 
225
- def create_compute_cluster(self, compute_cluster_id: str,
226
- config_filepath: str) -> ComputeCluster:
225
+ def create_compute_cluster(self, config_filepath: str,
226
+ compute_cluster_id: str = None) -> ComputeCluster:
227
227
  """Creates a compute cluster for the user.
228
228
 
229
229
  Args:
230
- compute_cluster_id (str): The compute cluster ID for the compute cluster to create.
231
230
  config_filepath (str): The path to the compute cluster config file.
231
+ compute_cluster_id (str): New compute cluster ID for the compute cluster to create.
232
232
 
233
233
  Returns:
234
234
  ComputeCluster: A Compute Cluster object for the specified compute cluster ID.
@@ -236,7 +236,7 @@ class User(Lister, BaseClient):
236
236
  Example:
237
237
  >>> from clarifai.client.user import User
238
238
  >>> client = User(user_id="user_id")
239
- >>> compute_cluster = client.create_compute_cluster(compute_cluster_id="compute_cluster_id", config_filepath="config.yml")
239
+ >>> compute_cluster = client.create_compute_cluster(config_filepath="config.yml")
240
240
  """
241
241
  if not os.path.exists(config_filepath):
242
242
  raise UserError(f"Compute Cluster config file not found at {config_filepath}")
@@ -244,7 +244,8 @@ class User(Lister, BaseClient):
244
244
  compute_cluster_config = self._process_compute_cluster_config(config_filepath)
245
245
 
246
246
  if 'id' in compute_cluster_config:
247
- compute_cluster_id = compute_cluster_config['id']
247
+ if compute_cluster_id is None:
248
+ compute_cluster_id = compute_cluster_config['id']
248
249
  compute_cluster_config.pop('id')
249
250
 
250
251
  request = service_pb2.PostComputeClustersRequest(
@@ -6,7 +6,6 @@ from google.protobuf.struct_pb2 import Struct
6
6
 
7
7
  from clarifai.client.input import Inputs
8
8
  from clarifai.datasets.upload.base import ClarifaiDataLoader, ClarifaiDataset
9
- from clarifai.utils.misc import get_uuid
10
9
 
11
10
 
12
11
  class MultiModalDataset(ClarifaiDataset):
@@ -36,7 +35,6 @@ class MultiModalDataset(ClarifaiDataset):
36
35
  image_bytes = data_item.image_bytes
37
36
  text = data_item.text
38
37
  labels = data_item.labels if isinstance(data_item.labels, list) else [data_item.labels]
39
- id = get_uuid(8)
40
38
  input_id = f"{self.dataset_id}-{id}" if data_item.id is None else f"{self.dataset_id}-{str(data_item.id)}"
41
39
  if data_item.metadata is not None:
42
40
  metadata.update(data_item.metadata)
@@ -1,16 +1,16 @@
1
- ARG PYTHON_VERSION=${PYTHON_VERSION}
2
- FROM public.ecr.aws/docker/library/python:${PYTHON_VERSION}-slim-bookworm as build
1
+ FROM --platform=$TARGETPLATFORM ${BASE_IMAGE} as build
3
2
 
4
- # Set the working directory to /app
5
- WORKDIR /app
3
+ ENV DEBIAN_FRONTEND=noninteractive
6
4
 
5
+ #############################
6
+ # User specific requirements
7
+ #############################
7
8
  COPY requirements.txt .
8
- # Install requirements and cleanup before leaving this line.
9
- # Note(zeiler): this could be in a future template as {{model_python_deps}}
10
- RUN python -m pip install -r requirements.txt && rm -rf /root/.cache
11
9
 
12
- # Install Clarifai SDK
13
- RUN python -m pip install clarifai
10
+ # Install requirements and clarifai package and cleanup before leaving this line.
11
+ # Note(zeiler): this could be in a future template as {{model_python_deps}}
12
+ RUN pip install --no-cache-dir -r requirements.txt && \
13
+ pip install --no-cache-dir clarifai
14
14
 
15
15
  # These will be set by the templaing system.
16
16
  ENV CLARIFAI_PAT=${CLARIFAI_PAT}
@@ -20,12 +20,22 @@ ENV CLARIFAI_NODEPOOL_ID=${CLARIFAI_NODEPOOL_ID}
20
20
  ENV CLARIFAI_COMPUTE_CLUSTER_ID=${CLARIFAI_COMPUTE_CLUSTER_ID}
21
21
  ENV CLARIFAI_API_BASE=${CLARIFAI_API_BASE}
22
22
 
23
+ # Set the NUMBA cache dir to /tmp
24
+ ENV NUMBA_CACHE_DIR=/tmp/numba_cache
25
+ ENV HOME=/tmp
26
+
27
+ # Set the working directory to /app
28
+ WORKDIR /app
29
+
23
30
  # Copy the current folder into /app/model_dir that the SDK will expect.
31
+ # Note(zeiler): would be nice to exclude checkpoints in case they were pre-downloaded.
24
32
  COPY . /app/model_dir/${name}
25
33
 
26
34
  # Add the model directory to the python path.
27
- ENV PYTHONPATH "${PYTHONPATH}:/app/model_dir/${name}"
35
+ ENV PYTHONPATH=${PYTHONPATH}:/app/model_dir/${name}
36
+
37
+ ENTRYPOINT ["python", "-m", "clarifai.runners.server"]
28
38
 
29
39
  # Finally run the clarifai entrypoint to start the runner loop and local dev server.
30
40
  # Note(zeiler): we may want to make this a clarifai CLI call.
31
- CMD ["python", "-m", "clarifai.runners.server", "--model_path", "/app/model_dir/${name}"]
41
+ CMD ["--model_path", "/app/model_dir/main"]