clarifai 11.2.4rc3__py3-none-any.whl → 11.3.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/client/deployment.py +3 -1
- clarifai/client/model.py +7 -3
- clarifai/runners/models/model_class.py +4 -2
- clarifai/runners/utils/data_types.py +3 -3
- clarifai/runners/utils/data_utils.py +3 -2
- clarifai/runners/utils/method_signatures.py +0 -8
- clarifai/utils/protobuf.py +143 -0
- {clarifai-11.2.4rc3.dist-info → clarifai-11.3.0.dist-info}/METADATA +15 -3
- clarifai-11.3.0.dist-info/RECORD +107 -0
- {clarifai-11.2.4rc3.dist-info → clarifai-11.3.0.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.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__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.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__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.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__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.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-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.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_runner.cpython-310.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-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__/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-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-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__/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-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_handler.py +0 -292
- clarifai/runners/utils/data_handler_refract.py +0 -213
- 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/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.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-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai-11.2.4rc3.dist-info/RECORD +0 -241
- {clarifai-11.2.4rc3.dist-info → clarifai-11.3.0.dist-info}/entry_points.txt +0 -0
- {clarifai-11.2.4rc3.dist-info → clarifai-11.3.0.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.2.4rc3.dist-info → clarifai-11.3.0.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.
|
1
|
+
__version__ = "11.3.0"
|
clarifai/client/deployment.py
CHANGED
@@ -3,6 +3,7 @@ from clarifai_grpc.grpc.api import resources_pb2
|
|
3
3
|
from clarifai.client.base import BaseClient
|
4
4
|
from clarifai.client.lister import Lister
|
5
5
|
from clarifai.utils.logging import logger
|
6
|
+
from clarifai.utils.protobuf import dict_to_protobuf
|
6
7
|
|
7
8
|
|
8
9
|
class Deployment(Lister, BaseClient):
|
@@ -28,7 +29,8 @@ class Deployment(Lister, BaseClient):
|
|
28
29
|
**kwargs: Additional keyword arguments to be passed to the deployment.
|
29
30
|
"""
|
30
31
|
self.kwargs = {**kwargs, 'id': deployment_id, 'user_id': user_id}
|
31
|
-
self.deployment_info = resources_pb2.Deployment(
|
32
|
+
self.deployment_info = resources_pb2.Deployment()
|
33
|
+
dict_to_protobuf(self.deployment_info, self.kwargs)
|
32
34
|
self.logger = logger
|
33
35
|
BaseClient.__init__(
|
34
36
|
self,
|
clarifai/client/model.py
CHANGED
@@ -32,7 +32,7 @@ from clarifai.utils.misc import BackoffIterator
|
|
32
32
|
from clarifai.utils.model_train import (find_and_replace_key, params_parser,
|
33
33
|
response_to_model_params, response_to_param_info,
|
34
34
|
response_to_templates)
|
35
|
-
|
35
|
+
from clarifai.utils.protobuf import dict_to_protobuf
|
36
36
|
MAX_SIZE_PER_STREAM = int(89_128_960) # 85GiB
|
37
37
|
MIN_CHUNK_FOR_UPLOAD_FILE = int(5_242_880) # 5MiB
|
38
38
|
MAX_CHUNK_FOR_UPLOAD_FILE = int(5_242_880_000) # 5GiB
|
@@ -73,8 +73,11 @@ class Model(Lister, BaseClient):
|
|
73
73
|
user_id, app_id, _, model_id, model_version_id = ClarifaiUrlHelper.split_clarifai_url(url)
|
74
74
|
model_version = {'id': model_version_id}
|
75
75
|
kwargs = {'user_id': user_id, 'app_id': app_id}
|
76
|
+
|
76
77
|
self.kwargs = {**kwargs, 'id': model_id, 'model_version': model_version, }
|
77
|
-
self.model_info = resources_pb2.Model(
|
78
|
+
self.model_info = resources_pb2.Model()
|
79
|
+
dict_to_protobuf(self.model_info, self.kwargs)
|
80
|
+
|
78
81
|
self.logger = logger
|
79
82
|
self.training_params = {}
|
80
83
|
self.input_types = None
|
@@ -983,7 +986,8 @@ class Model(Lister, BaseClient):
|
|
983
986
|
|
984
987
|
dict_response = MessageToDict(response, preserving_proto_field_name=True)
|
985
988
|
self.kwargs = self.process_response_keys(dict_response['model'])
|
986
|
-
self.model_info = resources_pb2.Model(
|
989
|
+
self.model_info = resources_pb2.Model()
|
990
|
+
dict_to_protobuf(self.model_info, self.kwargs)
|
987
991
|
|
988
992
|
def __str__(self):
|
989
993
|
if len(self.kwargs) < 10:
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import collections.abc as abc
|
1
2
|
import inspect
|
2
3
|
import itertools
|
3
4
|
import logging
|
@@ -271,8 +272,9 @@ class ModelClass(ABC):
|
|
271
272
|
if k not in python_param_types:
|
272
273
|
continue
|
273
274
|
|
274
|
-
if hasattr(python_param_types[k],
|
275
|
-
|
275
|
+
if hasattr(python_param_types[k],
|
276
|
+
"__args__") and (getattr(python_param_types[k], "__origin__",
|
277
|
+
None) in [abc.Iterator, abc.Generator, abc.Iterable]):
|
276
278
|
# get the type of the items in the stream
|
277
279
|
stream_type = python_param_types[k].__args__[0]
|
278
280
|
|
@@ -160,8 +160,8 @@ class Text(MessageData):
|
|
160
160
|
|
161
161
|
class Concept(MessageData):
|
162
162
|
|
163
|
-
def __init__(self,
|
164
|
-
self.id =
|
163
|
+
def __init__(self, name: str, value: float = 1):
|
164
|
+
self.id = name
|
165
165
|
self.name = name
|
166
166
|
self.value = value
|
167
167
|
|
@@ -173,7 +173,7 @@ class Concept(MessageData):
|
|
173
173
|
|
174
174
|
@classmethod
|
175
175
|
def from_proto(cls, proto: ConceptProto) -> "Concept":
|
176
|
-
return cls(proto.
|
176
|
+
return cls(proto.name, proto.value)
|
177
177
|
|
178
178
|
|
179
179
|
class Region(MessageData):
|
@@ -171,12 +171,13 @@ class InputField(MessageData):
|
|
171
171
|
if default is not None:
|
172
172
|
proto.default = json.dumps(default)
|
173
173
|
return proto
|
174
|
-
except
|
174
|
+
except Exception:
|
175
175
|
if default is not None:
|
176
176
|
proto.default = str(default)
|
177
177
|
return proto
|
178
178
|
except Exception as e:
|
179
|
-
raise ValueError(
|
179
|
+
raise ValueError(
|
180
|
+
f"Error setting default value of type, {type(default)} and value: {default}: {e}")
|
180
181
|
|
181
182
|
@classmethod
|
182
183
|
def get_default(cls, proto):
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import collections.abc as abc
|
2
2
|
import inspect
|
3
3
|
import json
|
4
|
-
import logging
|
5
4
|
from collections import namedtuple
|
6
5
|
from typing import Dict, List, Tuple, get_args, get_origin
|
7
6
|
|
@@ -313,13 +312,6 @@ def deserialize(proto, signatures, inference_params={}, is_output=False):
|
|
313
312
|
kwargs[sig.name] = serializer.deserialize(part.data)
|
314
313
|
elif inference_params_value is not None:
|
315
314
|
kwargs[sig.name] = inference_params_value
|
316
|
-
elif sig.default and (sig.required is False) and (not is_output):
|
317
|
-
try:
|
318
|
-
kwargs[sig.name] = data_utils.InputField.get_default(sig)
|
319
|
-
except Exception as e:
|
320
|
-
# default is not set, so ignore
|
321
|
-
logging.exception('Default value not set for %s: %s', sig.name, e)
|
322
|
-
pass
|
323
315
|
else:
|
324
316
|
if sig_i == 0:
|
325
317
|
# possible inlined first value
|
@@ -0,0 +1,143 @@
|
|
1
|
+
from google.protobuf import struct_pb2, symbol_database, wrappers_pb2
|
2
|
+
from google.protobuf.descriptor import FieldDescriptor
|
3
|
+
from google.protobuf.message import Message
|
4
|
+
from google.protobuf.timestamp_pb2 import Timestamp
|
5
|
+
|
6
|
+
from clarifai.utils.logging import logger
|
7
|
+
|
8
|
+
# Initialize the Protobuf symbol database for dynamic message type resolution
|
9
|
+
db = symbol_database.Default()
|
10
|
+
|
11
|
+
# Define standard wrapper types for Protobuf well-known types
|
12
|
+
WRAPPER_TYPES = {
|
13
|
+
wrappers_pb2.Int32Value,
|
14
|
+
wrappers_pb2.Int64Value,
|
15
|
+
wrappers_pb2.StringValue,
|
16
|
+
wrappers_pb2.UInt32Value,
|
17
|
+
wrappers_pb2.UInt64Value,
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
def dict_to_protobuf(pb_obj: Message, data: dict) -> None:
|
22
|
+
"""Recursively convert a nested dictionary to a Protobuf message object.
|
23
|
+
|
24
|
+
Args:
|
25
|
+
pb_obj: The target Protobuf message instance to populate.
|
26
|
+
data: Source dictionary containing the data to convert.
|
27
|
+
"""
|
28
|
+
for field, value in data.items():
|
29
|
+
if field not in pb_obj.DESCRIPTOR.fields_by_name:
|
30
|
+
logger.warning(f"Ignoring unknown field '{field}' in message '{pb_obj.DESCRIPTOR.name}'")
|
31
|
+
continue
|
32
|
+
|
33
|
+
field_descriptor = pb_obj.DESCRIPTOR.fields_by_name[field]
|
34
|
+
|
35
|
+
try:
|
36
|
+
# Handle repeated fields (lists)
|
37
|
+
if field_descriptor.label == FieldDescriptor.LABEL_REPEATED:
|
38
|
+
_handle_repeated_field(pb_obj, field_descriptor, field, value)
|
39
|
+
|
40
|
+
# Handle message fields (nested messages)
|
41
|
+
elif field_descriptor.type == FieldDescriptor.TYPE_MESSAGE:
|
42
|
+
_handle_message_field(pb_obj, field_descriptor, field, value)
|
43
|
+
|
44
|
+
# Handle scalar fields
|
45
|
+
else:
|
46
|
+
if value:
|
47
|
+
setattr(pb_obj, field, value)
|
48
|
+
|
49
|
+
except Exception as e:
|
50
|
+
logger.error(f"Error processing field '{field}': {str(e)}")
|
51
|
+
raise
|
52
|
+
|
53
|
+
|
54
|
+
def _handle_repeated_field(pb_obj: Message, field_descriptor: FieldDescriptor, field: str,
|
55
|
+
value: list) -> None:
|
56
|
+
"""Process repeated fields (both scalar and message types)."""
|
57
|
+
if not isinstance(value, list):
|
58
|
+
logger.warning(f"Expected list for repeated field '{field}', got {type(value).__name__}")
|
59
|
+
return
|
60
|
+
|
61
|
+
repeated_field = getattr(pb_obj, field)
|
62
|
+
|
63
|
+
# Handle repeated message fields
|
64
|
+
if field_descriptor.type == FieldDescriptor.TYPE_MESSAGE:
|
65
|
+
for item in value:
|
66
|
+
if isinstance(item, dict):
|
67
|
+
item_msg = repeated_field.add()
|
68
|
+
dict_to_protobuf(item_msg, item)
|
69
|
+
elif isinstance(item, Message):
|
70
|
+
repeated_field.add().CopyFrom(item)
|
71
|
+
else:
|
72
|
+
logger.warning(f"Invalid type {type(item).__name__} in repeated message field '{field}'")
|
73
|
+
else:
|
74
|
+
# Handle repeated scalar fields
|
75
|
+
try:
|
76
|
+
repeated_field.extend(value)
|
77
|
+
except TypeError as e:
|
78
|
+
logger.error(f"Type mismatch in repeated scalar field '{field}': {str(e)}")
|
79
|
+
raise
|
80
|
+
|
81
|
+
|
82
|
+
def _handle_message_field(pb_obj: Message, field_descriptor: FieldDescriptor, field: str,
|
83
|
+
value: object) -> None:
|
84
|
+
"""Process message-type fields including special types."""
|
85
|
+
msg_class = db.GetSymbol(field_descriptor.message_type.full_name)
|
86
|
+
target_field = getattr(pb_obj, field)
|
87
|
+
|
88
|
+
# Handle special message types
|
89
|
+
if msg_class is Timestamp:
|
90
|
+
_set_timestamp_value(target_field, value)
|
91
|
+
elif msg_class is struct_pb2.Struct:
|
92
|
+
_set_struct_value(target_field, value)
|
93
|
+
elif msg_class in WRAPPER_TYPES:
|
94
|
+
_set_wrapper_value(target_field, msg_class, value)
|
95
|
+
else:
|
96
|
+
# Handle nested messages
|
97
|
+
if isinstance(value, dict):
|
98
|
+
nested_pb = msg_class()
|
99
|
+
dict_to_protobuf(nested_pb, value)
|
100
|
+
target_field.CopyFrom(nested_pb)
|
101
|
+
elif isinstance(value, Message):
|
102
|
+
target_field.CopyFrom(value)
|
103
|
+
else:
|
104
|
+
logger.warning(f"Invalid type {type(value).__name__} for message field '{field}'")
|
105
|
+
|
106
|
+
|
107
|
+
def _set_timestamp_value(target_field: Message, value: object) -> None:
|
108
|
+
"""Set timestamp value from dict or numeric timestamp."""
|
109
|
+
ts = Timestamp()
|
110
|
+
if isinstance(value, dict):
|
111
|
+
ts.seconds = value.get('seconds', 0)
|
112
|
+
ts.nanos = value.get('nanos', 0)
|
113
|
+
elif isinstance(value, (int, float)):
|
114
|
+
ts.seconds = int(value)
|
115
|
+
ts.nanos = int((value - ts.seconds) * 1e9)
|
116
|
+
else:
|
117
|
+
logger.warning(f"Unsupported timestamp format: {type(value).__name__}")
|
118
|
+
target_field.CopyFrom(ts)
|
119
|
+
|
120
|
+
|
121
|
+
def _set_struct_value(target_field: Message, value: object) -> None:
|
122
|
+
"""Convert dictionary to Protobuf Struct."""
|
123
|
+
if not isinstance(value, dict):
|
124
|
+
logger.warning(f"Expected dict for Struct field, got {type(value).__name__}")
|
125
|
+
return
|
126
|
+
|
127
|
+
struct = struct_pb2.Struct()
|
128
|
+
try:
|
129
|
+
struct.update(value)
|
130
|
+
except ValueError as e:
|
131
|
+
logger.error(f"Invalid value in Struct: {str(e)}")
|
132
|
+
raise
|
133
|
+
target_field.CopyFrom(struct)
|
134
|
+
|
135
|
+
|
136
|
+
def _set_wrapper_value(target_field: Message, wrapper_type: type, value: object) -> None:
|
137
|
+
"""Set value for wrapper types (e.g., Int32Value)."""
|
138
|
+
try:
|
139
|
+
wrapper = wrapper_type(value=value)
|
140
|
+
except TypeError as e:
|
141
|
+
logger.error(f"Invalid value for {wrapper_type.__name__}: {str(e)}")
|
142
|
+
raise
|
143
|
+
target_field.CopyFrom(wrapper)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: clarifai
|
3
|
-
Version: 11.
|
3
|
+
Version: 11.3.0
|
4
4
|
Summary: Clarifai Python SDK
|
5
5
|
Home-page: https://github.com/Clarifai/clarifai-python
|
6
6
|
Author: Clarifai
|
@@ -20,7 +20,7 @@ Classifier: Operating System :: OS Independent
|
|
20
20
|
Requires-Python: >=3.8
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
License-File: LICENSE
|
23
|
-
Requires-Dist: clarifai-grpc>=11.2
|
23
|
+
Requires-Dist: clarifai-grpc>=11.3.2
|
24
24
|
Requires-Dist: clarifai-protocol>=0.0.22
|
25
25
|
Requires-Dist: numpy>=1.22.0
|
26
26
|
Requires-Dist: tqdm>=4.65.0
|
@@ -35,6 +35,18 @@ Requires-Dist: requests>=2.32.3
|
|
35
35
|
Requires-Dist: aiohttp>=3.10.0
|
36
36
|
Provides-Extra: all
|
37
37
|
Requires-Dist: pycocotools==2.0.6; extra == "all"
|
38
|
+
Dynamic: author
|
39
|
+
Dynamic: author-email
|
40
|
+
Dynamic: classifier
|
41
|
+
Dynamic: description
|
42
|
+
Dynamic: description-content-type
|
43
|
+
Dynamic: home-page
|
44
|
+
Dynamic: license
|
45
|
+
Dynamic: license-file
|
46
|
+
Dynamic: provides-extra
|
47
|
+
Dynamic: requires-dist
|
48
|
+
Dynamic: requires-python
|
49
|
+
Dynamic: summary
|
38
50
|
|
39
51
|
<h1 align="center">
|
40
52
|
<a href="https://www.clarifai.com/"><img alt="Clarifai" title="Clarifai" src="https://github.com/user-attachments/assets/623b883b-7fe5-4b95-bbfa-8691f5779af4"></a>
|
@@ -0,0 +1,107 @@
|
|
1
|
+
clarifai/__init__.py,sha256=AKQVpPKUjXA31bxC6zOaWuLMOUf9UCfopNi6s5UU5_g,23
|
2
|
+
clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
clarifai/errors.py,sha256=RwzTajwds51wLD0MVlMC5kcpBnzRpreDLlazPSBZxrg,2605
|
4
|
+
clarifai/versions.py,sha256=jctnczzfGk_S3EnVqb2FjRKfSREkNmvNEwAAa_VoKiQ,222
|
5
|
+
clarifai/cli/README.md,sha256=YGApHfeUyu5P0Pdth-mqQCQftWHDxz6bugDlvDXDhOE,1942
|
6
|
+
clarifai/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
clarifai/cli/__main__.py,sha256=utJ2F40cl0jPHcYdTlGZRqpPfZ0CtVYB-8Ft0b2fWD4,72
|
8
|
+
clarifai/cli/base.py,sha256=ZG1Ial89wGVqt4bSFYmIoRH_OZtw2yxlq3Ihp9e025U,7592
|
9
|
+
clarifai/cli/compute_cluster.py,sha256=dma_dgzSg5pYQcxlWhoKYdMFPO2KS7HzsN81ploNB-E,2083
|
10
|
+
clarifai/cli/deployment.py,sha256=wBWkYfLr6W73LScF6NlQM-reXWUP38VfAudltjpnFpk,3822
|
11
|
+
clarifai/cli/model.py,sha256=M1dEbR7t0Ay9cgUe73knIvZ5y1UJedM8FoNrmuYxWOA,12789
|
12
|
+
clarifai/cli/nodepool.py,sha256=7nTNd9T-UEPFE36vbxwdUHu2B3NECbN-lSTb_DQYw18,3874
|
13
|
+
clarifai/client/__init__.py,sha256=xI1U0l5AZdRThvQAXCLsd9axxyFzXXJ22m8LHqVjQRU,662
|
14
|
+
clarifai/client/app.py,sha256=FnKvKksYZwdry0e4Obh-trdSO1mv6QcVAa3kzKiQMpU,38340
|
15
|
+
clarifai/client/base.py,sha256=hSHOqkXbSKyaRDeylMMnkhUHCAHhEqno4KI0CXGziBA,7536
|
16
|
+
clarifai/client/compute_cluster.py,sha256=EvW9TJjPvInUlggfg1A98sxoWH8_PY5rCVXZhsj6ac0,8705
|
17
|
+
clarifai/client/dataset.py,sha256=6DqfXQtiHoOJq0vPw2fz5ATo5zxQMmlhKG9IBwhnXeU,32078
|
18
|
+
clarifai/client/deployment.py,sha256=I3UJLu2NB1GlKZaIFTI_q-3P5ZTtIoNEuKxB-oHMvD4,2682
|
19
|
+
clarifai/client/input.py,sha256=obMAHMDU1OwfXZ8KraOnGFlWzlW-3F7Ob_2lcOQMlhY,46339
|
20
|
+
clarifai/client/lister.py,sha256=03KGMvs5RVyYqxLsSrWhNc34I8kiF1Ph0NeyEwu7nMU,2082
|
21
|
+
clarifai/client/model.py,sha256=Zm_GoTNy-HL6zmld_PeKGqnQgaLhLPqlNb4BcFBX8bY,77125
|
22
|
+
clarifai/client/model_client.py,sha256=X0RndVfTdfa4PZaOtSick0VKC3AkQakT-qrkPqaFKuI,19971
|
23
|
+
clarifai/client/module.py,sha256=FTkm8s9m-EaTKN7g9MnLhGJ9eETUfKG7aWZ3o1RshYs,4204
|
24
|
+
clarifai/client/nodepool.py,sha256=la3vTFrO4LX8zm2eQ5jqf2L0-kQ63Dano8FibadoZbk,10152
|
25
|
+
clarifai/client/search.py,sha256=GaPWN6JmTQGZaCHr6U1yv0zqR6wKFl7i9IVLg2ul1CI,14254
|
26
|
+
clarifai/client/user.py,sha256=WOv66ww2wx9isIge3V-xTHCkqC6akl2jEGAxzT_Ugfs,17642
|
27
|
+
clarifai/client/workflow.py,sha256=5VjZ2D8cudLznR8yhrwNawOmjxUhkJllZMKM6pn-4gs,12170
|
28
|
+
clarifai/client/auth/__init__.py,sha256=7EwR0NrozkAUwpUnCsqXvE_p0wqx_SelXlSpKShKJK0,136
|
29
|
+
clarifai/client/auth/helper.py,sha256=Ngw5IDkOWvnOz5YwViVk55z3mC52MyezLc0G3WxLqok,14643
|
30
|
+
clarifai/client/auth/register.py,sha256=2CMdBsoVLoTfjyksE6j7BM2tiEc73WKYvxnwDDgNn1k,536
|
31
|
+
clarifai/client/auth/stub.py,sha256=FrA5QpEFY4sK6fvPVhTg19ROLHkYSRo343nNqiVE7xw,4963
|
32
|
+
clarifai/constants/base.py,sha256=ogmFSZYoF0YhGjHg5aiOc3MLqPr_poKAls6xaD0_C3U,89
|
33
|
+
clarifai/constants/dataset.py,sha256=vjK3IlgXu31HycuvjRSzEQSqhU6xfj5TIgo6IpyUWoc,609
|
34
|
+
clarifai/constants/input.py,sha256=WcHwToUVIK9ItAhDefaSohQHCLNeR55PSjZ0BFnoZ3U,28
|
35
|
+
clarifai/constants/model.py,sha256=Um1hLfMFlh5R_vtP3Z6P-o6zon-tdbLcKVIl4PucrV4,438
|
36
|
+
clarifai/constants/rag.py,sha256=WcHwToUVIK9ItAhDefaSohQHCLNeR55PSjZ0BFnoZ3U,28
|
37
|
+
clarifai/constants/search.py,sha256=yYEqTaFg-KdnpJE_Ytp-EPVHIIC395iNtZrpVlLIf4o,101
|
38
|
+
clarifai/constants/workflow.py,sha256=cECq1xdvf44MCdtK2AbkiuuwhyL-6OWZdQfYbsLKy_o,33
|
39
|
+
clarifai/datasets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
|
+
clarifai/datasets/export/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
41
|
+
clarifai/datasets/export/inputs_annotations.py,sha256=3AtUBrMIjw8H3ehDsJFYcBFoAZ1QKQo1hXTMsHh8f20,10159
|
42
|
+
clarifai/datasets/upload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
43
|
+
clarifai/datasets/upload/base.py,sha256=UIc0ufyIBCrb83_sFpv21L8FshsX4nwsLYQkdlJfzD4,2357
|
44
|
+
clarifai/datasets/upload/features.py,sha256=GK69WvUYnks5G26Z5L5XSisBIZILLv7lYhS2y8BJCt0,2031
|
45
|
+
clarifai/datasets/upload/image.py,sha256=HlCsfEMu_C4GVecGSv52RUJ6laLW8H64Pfj_FQyX6qg,8580
|
46
|
+
clarifai/datasets/upload/multimodal.py,sha256=_NpNQak9KMn0NOiOr48MYnXL0GQZ1LXKhwdYF1HhrHs,2377
|
47
|
+
clarifai/datasets/upload/text.py,sha256=dpRMNz49EyKau0kwksEaNV6TLBUf5lSr7t5g3pG2byM,2298
|
48
|
+
clarifai/datasets/upload/utils.py,sha256=BerWhq40ZUN30z6VImlc93eZtT-1vI18AMgSOuNzJEM,9647
|
49
|
+
clarifai/datasets/upload/loaders/README.md,sha256=aNRutSCTzLp2ruIZx74ZkN5AxpzwKOxMa7OzabnKpwg,2980
|
50
|
+
clarifai/datasets/upload/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
51
|
+
clarifai/datasets/upload/loaders/coco_captions.py,sha256=YfuNXplbdoH8N9ph7RyN9MfJTtOcJBG4ie1ow6-mELA,1516
|
52
|
+
clarifai/datasets/upload/loaders/coco_detection.py,sha256=_I_yThw435KS9SH7zheBbJDK3zFgjTImBsES__ijjMk,2831
|
53
|
+
clarifai/datasets/upload/loaders/imagenet_classification.py,sha256=i7W5F6FTB3LwLmhPgjZHmbCbS3l4LmjsuBFKtjxl1pU,1962
|
54
|
+
clarifai/datasets/upload/loaders/xview_detection.py,sha256=hk8cZdYZimm4KOaZvBjYcC6ikURZMn51xmn7pXZT3HE,6052
|
55
|
+
clarifai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
56
|
+
clarifai/models/api.py,sha256=d3FQQlG0mNDLrfEvchqaVcq4Tgb_TqryNnJtwp3c7sE,10961
|
57
|
+
clarifai/modules/README.md,sha256=mx8pVx6cPp-pP4LcFPT_nX3ngGmhygVK0WiXeD3cbIo,367
|
58
|
+
clarifai/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
59
|
+
clarifai/modules/css.py,sha256=kadCEunmyh5h2yf0-4aysE3ZcZ6qaQcxuAgDXS96yF8,2020
|
60
|
+
clarifai/modules/pages.py,sha256=iOoM3RNRMgXlV0qBqcdQofxoXo2RuRQh0h9c9BIS0-I,1383
|
61
|
+
clarifai/modules/style.css,sha256=j7FNPZVhLPj35vvBksAJ90RuX5sLuqzDR5iM2WIEhiA,6073
|
62
|
+
clarifai/rag/__init__.py,sha256=wu3PzAzo7uqgrEzuaC9lY_3gj1HFiR3GU3elZIKTT5g,40
|
63
|
+
clarifai/rag/rag.py,sha256=bqUWnfdf91OYMucEK0_rJXDwg0oKjz5c7eda-9CPXu8,12680
|
64
|
+
clarifai/rag/utils.py,sha256=yr1jAcbpws4vFGBqlAwPPE7v1DRba48g8gixLFw8OhQ,4070
|
65
|
+
clarifai/runners/__init__.py,sha256=cDJ31l41dDsqW4Xn6sFMkKxxdIMTnGH9IW6sVkq0TNw,207
|
66
|
+
clarifai/runners/server.py,sha256=xHDLdhQApCgYG19QOKXqJNCGNyw1Vsvobq3UdryDrVc,4132
|
67
|
+
clarifai/runners/dockerfile_template/Dockerfile.template,sha256=5cjv7U8PmWa3DB_5B1CqSYh_6GE0E0np52TIAa7EIDE,2312
|
68
|
+
clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
69
|
+
clarifai/runners/models/model_builder.py,sha256=vIUZII9n5wL0SGV4xR6wfsdRvrMv4pSHr6P-KdYpikI,36343
|
70
|
+
clarifai/runners/models/model_class.py,sha256=J33aq5OqKu_1iVnaSAbEQCaE_ina8X46PlQ5AiK80_o,14806
|
71
|
+
clarifai/runners/models/model_run_locally.py,sha256=H7FKUBzZ_EPPj1b6P59qbOYr3mUJjJTlD5gavH5e80o,17746
|
72
|
+
clarifai/runners/models/model_runner.py,sha256=T4Qn_x0vky7XdeS54bvipzEmKZMra1tQdAu_u01yyjc,6503
|
73
|
+
clarifai/runners/models/model_servicer.py,sha256=A--b1P71PBCAMJCpy_-fpNDkfCVdvdMh1LleW15dSas,3037
|
74
|
+
clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
75
|
+
clarifai/runners/utils/code_script.py,sha256=NutTcbJWChjSb_WLNwkesavzcpP_-wh_R4ySWt0VPcI,8971
|
76
|
+
clarifai/runners/utils/const.py,sha256=9qnOC1Bt6SGLQ9XCQEQ6519XhW4gzcztsV1Rgej67Vw,1055
|
77
|
+
clarifai/runners/utils/data_types.py,sha256=l_yd09GIlAZ_0bJdY558BuNSKTM48rx7fYA7-HNxETY,12415
|
78
|
+
clarifai/runners/utils/data_utils.py,sha256=dVGl7ZW6t0BztzfIOKV-WMeAEyEjwxzU3ud5fgL5Jmo,12843
|
79
|
+
clarifai/runners/utils/loader.py,sha256=Sl0m29RDtMPx2cIiSbbDFtKHQj2ktXQ5CnkvaHi-zDc,8804
|
80
|
+
clarifai/runners/utils/method_signatures.py,sha256=2SSStcBuBUbIgvFgAJFt4By0ZHos2c7bDWJOiUxQxZQ,18190
|
81
|
+
clarifai/runners/utils/openai_convertor.py,sha256=qRhq_nGacaLFD_-8oAbPaDhGZJVMtKbgb2A4X7FlhD0,4564
|
82
|
+
clarifai/runners/utils/serializers.py,sha256=S4sRsOVvH191vAGTRTAAdwLlQwlK4T5QVRDGPptg9nQ,7191
|
83
|
+
clarifai/runners/utils/url_fetcher.py,sha256=v_8JOWmkyFAzsBulsieKX7Nfjy1Yg7wGSZeqfEvw2cg,1640
|
84
|
+
clarifai/schema/search.py,sha256=JjTi8ammJgZZ2OGl4K6tIA4zEJ1Fr2ASZARXavI1j5c,2448
|
85
|
+
clarifai/urls/helper.py,sha256=tjoMGGHuWX68DUB0pk4MEjrmFsClUAQj2jmVEM_Sy78,4751
|
86
|
+
clarifai/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
87
|
+
clarifai/utils/cli.py,sha256=FUFJJb8Jzohpt132JE43xHNzWtX0N8fbWROxJISfCM0,5072
|
88
|
+
clarifai/utils/config.py,sha256=MxuQ1U4EOT4yVOEcRyv3OUPnoY_A_J5cZKHJGiuuo30,2883
|
89
|
+
clarifai/utils/constants.py,sha256=fdCmw8fjgo8eoWu85t95ZoRTrgXC5_XVXFyB8_VQTtw,219
|
90
|
+
clarifai/utils/logging.py,sha256=I2Sj1X-phYcINXe4-pW22Tq6Sz5PlwcxYQh7zORBbeM,13634
|
91
|
+
clarifai/utils/misc.py,sha256=gensDjU5pV44iFzUzmM_Lf6PZX63GFxRXJX91esEjAg,2999
|
92
|
+
clarifai/utils/model_train.py,sha256=Mndqy5GNu7kjQHjDyNVyamL0hQFLGSHcWhOuPyOvr1w,8005
|
93
|
+
clarifai/utils/protobuf.py,sha256=P2deeGfs3VajkfQgPn7ROkqZ-4kXnWRxHCsy_XS7yKI,4954
|
94
|
+
clarifai/utils/evaluation/__init__.py,sha256=PYkurUrXrGevByj7RFb6CoU1iC7fllyQSfnnlo9WnY8,69
|
95
|
+
clarifai/utils/evaluation/helpers.py,sha256=aZeHLI7oSmU5YDWQp5GdkYW5qbHx37nV9xwunKTAwWM,18549
|
96
|
+
clarifai/utils/evaluation/main.py,sha256=sQAuMk0lPclXCYvy_rS7rYteo2xh9Ju13VNvbyGt_VM,15779
|
97
|
+
clarifai/utils/evaluation/testset_annotation_parser.py,sha256=iZfLw6oR1qgJ3MHMbOZXcGBLu7btSDn0VqdiAzpIm4g,5002
|
98
|
+
clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
99
|
+
clarifai/workflows/export.py,sha256=vICRhIreqDSShxLKjHNM2JwzKsf1B4fdXB0ciMcA70k,1945
|
100
|
+
clarifai/workflows/utils.py,sha256=nGeB_yjVgUO9kOeKTg4OBBaBz-AwXI3m-huSVj-9W18,1924
|
101
|
+
clarifai/workflows/validate.py,sha256=yJq03MaJqi5AK3alKGJJBR89xmmjAQ31sVufJUiOqY8,2556
|
102
|
+
clarifai-11.3.0.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
|
103
|
+
clarifai-11.3.0.dist-info/METADATA,sha256=_Y8jWVUURPYvFkK2Ky0MSr0dZSjY9S_LkLMBtBZh4Bo,22472
|
104
|
+
clarifai-11.3.0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
105
|
+
clarifai-11.3.0.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
|
106
|
+
clarifai-11.3.0.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
|
107
|
+
clarifai-11.3.0.dist-info/RECORD,,
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/client/cli/__init__.py
DELETED
File without changes
|
Binary file
|
Binary file
|
Binary file
|
clarifai/client/cli/base_cli.py
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
import click
|
2
|
-
import os
|
3
|
-
import yaml
|
4
|
-
|
5
|
-
@click.group()
|
6
|
-
@click.pass_context
|
7
|
-
def cli(ctx):
|
8
|
-
"""Clarifai CLI"""
|
9
|
-
ctx.ensure_object(dict)
|
10
|
-
config_path = 'config.yaml'
|
11
|
-
if os.path.exists(config_path):
|
12
|
-
ctx.obj = _from_yaml(config_path)
|
13
|
-
print("Loaded config from file.")
|
14
|
-
print(f"Config: {ctx.obj}")
|
15
|
-
else:
|
16
|
-
ctx.obj = {}
|
17
|
-
|
18
|
-
def _from_yaml(filename: str):
|
19
|
-
try:
|
20
|
-
with open(filename, 'r') as f:
|
21
|
-
return yaml.safe_load(f)
|
22
|
-
except yaml.YAMLError as e:
|
23
|
-
click.echo(f"Error reading YAML file: {e}", err=True)
|
24
|
-
return {}
|
25
|
-
|
26
|
-
def _dump_yaml(data, filename: str):
|
27
|
-
try:
|
28
|
-
with open(filename, 'w') as f:
|
29
|
-
yaml.dump(data, f)
|
30
|
-
except Exception as e:
|
31
|
-
click.echo(f"Error writing YAML file: {e}", err=True)
|
32
|
-
|
33
|
-
def _set_base_url(env):
|
34
|
-
environments = {'prod': 'https://api.clarifai.com', 'staging': 'https://api-staging.clarifai.com', 'dev': 'https://api-dev.clarifai.com'}
|
35
|
-
return environments.get(env, 'https://api.clarifai.com')
|
36
|
-
|
37
|
-
|
38
|
-
@cli.command()
|
39
|
-
@click.option('--config', type=click.Path(), required=False, help='Path to the config file')
|
40
|
-
@click.option('-e', '--env', required=False, help='Environment', type=click.Choice(['prod', 'staging', 'dev']))
|
41
|
-
@click.option('--user_id', required=False, help='User ID')
|
42
|
-
@click.pass_context
|
43
|
-
def login(ctx, config, env, user_id):
|
44
|
-
"""Login command to set PAT and other configurations."""
|
45
|
-
|
46
|
-
if config and os.path.exists(config):
|
47
|
-
ctx.obj = _from_yaml(config)
|
48
|
-
|
49
|
-
if 'pat' in ctx.obj:
|
50
|
-
os.environ["CLARIFAI_PAT"] = ctx.obj['pat']
|
51
|
-
click.echo("Loaded PAT from config file.")
|
52
|
-
elif 'CLARIFAI_PAT' in os.environ:
|
53
|
-
ctx.obj['pat'] = os.environ["CLARIFAI_PAT"]
|
54
|
-
click.echo("Loaded PAT from environment variable.")
|
55
|
-
else:
|
56
|
-
_pat = click.prompt("Get your PAT from https://clarifai.com/settings/security and pass it here", type=str)
|
57
|
-
os.environ["CLARIFAI_PAT"] = _pat
|
58
|
-
ctx.obj['pat'] = _pat
|
59
|
-
click.echo("PAT saved successfully.")
|
60
|
-
|
61
|
-
if user_id:
|
62
|
-
ctx.obj['user_id'] = user_id
|
63
|
-
os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
|
64
|
-
elif 'user_id' in ctx.obj or 'CLARIFAI_USER_ID' in os.environ:
|
65
|
-
ctx.obj['user_id'] = ctx.obj.get('user_id', os.environ["CLARIFAI_USER_ID"])
|
66
|
-
os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
|
67
|
-
|
68
|
-
if env:
|
69
|
-
ctx.obj['env'] = env
|
70
|
-
ctx.obj['base_url'] = _set_base_url(env)
|
71
|
-
os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
|
72
|
-
elif 'env' in ctx.obj:
|
73
|
-
ctx.obj['env'] = ctx.obj.get('env', "prod")
|
74
|
-
ctx.obj['base_url'] = _set_base_url(ctx.obj['env'])
|
75
|
-
os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
|
76
|
-
elif 'CLARIFAI_API_BASE' in os.environ:
|
77
|
-
ctx.obj['base_url'] = os.environ["CLARIFAI_API_BASE"]
|
78
|
-
|
79
|
-
_dump_yaml(ctx.obj, 'config.yaml')
|
80
|
-
|
81
|
-
click.echo("Login successful.")
|
82
|
-
|
83
|
-
# Import the model CLI commands to register them
|
84
|
-
from clarifai.client.cli.model_cli import model # Ensure this is the correct import path
|
85
|
-
|
86
|
-
|
87
|
-
if __name__ == '__main__':
|
88
|
-
cli()
|
clarifai/client/cli/model_cli.py
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
import click
|
2
|
-
from clarifai.client.cli.base_cli import cli
|
3
|
-
|
4
|
-
@cli.group()
|
5
|
-
def model():
|
6
|
-
"""Manage models: upload, test locally"""
|
7
|
-
pass
|
8
|
-
|
9
|
-
@model.command()
|
10
|
-
@click.argument('model_path', type=click.Path(exists=True))
|
11
|
-
@click.option('--download_checkpoints', is_flag=True, help='Flag to download checkpoints before uploading and including them in the tar file that is uploaded. Defaults to False, which will attempt to download them at docker build time.', )
|
12
|
-
@click.option('--skip_dockerfile', is_flag =True, help='Flag to skip generating a dockerfile so that you can manually edit an already created dockerfile.', )
|
13
|
-
def upload(model_path, download_checkpoints, skip_dockerfile):
|
14
|
-
"""Upload a model to Clarifai."""
|
15
|
-
from clarifai.runners.models import model_upload
|
16
|
-
|
17
|
-
model_upload.main(model_path, download_checkpoints, skip_dockerfile)
|
18
|
-
|
19
|
-
@model.command()
|
20
|
-
@click.argument('model_path', type=click.Path(exists=True))
|
21
|
-
def test_locally(model_path):
|
22
|
-
"""Test model locally."""
|
23
|
-
try:
|
24
|
-
from clarifai.runners.models import run_test_locally
|
25
|
-
run_test_locally.main(model_path)
|
26
|
-
click.echo(f"Model tested locally from {model_path}.")
|
27
|
-
except Exception as e:
|
28
|
-
click.echo(f"Failed to test model locally: {e}", err=True)
|
29
|
-
|
Binary file
|
Binary file
|
Binary file
|