clarifai 11.2.2__py3-none-any.whl → 11.2.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/utils/logging.py CHANGED
@@ -10,15 +10,6 @@ import traceback
10
10
  from collections import defaultdict
11
11
  from typing import Any, Dict, List, Optional, Union
12
12
 
13
- from rich import print as rprint
14
- from rich.console import Console
15
- from rich.logging import RichHandler
16
- from rich.table import Table
17
- from rich.traceback import install
18
- from rich.tree import Tree
19
-
20
- install()
21
-
22
13
  # The default logger to use throughout the SDK is defined at bottom of this file.
23
14
 
24
15
  # For the json logger.
@@ -29,6 +20,20 @@ FIELD_BLACKLIST = [
29
20
  'msg', 'message', 'account', 'levelno', 'created', 'threadName', 'name', 'processName',
30
21
  'module', 'funcName', 'msecs', 'relativeCreated', 'pathname', 'args', 'thread', 'process'
31
22
  ]
23
+ COLORS = {
24
+ 'ARGUMENTS': '\033[90m', # Gray
25
+ 'DEBUG': '\033[90m', # Gray
26
+ 'INFO': '\033[32m', # Green
27
+ 'WARNING': '\033[33m', # Yellow
28
+ 'ERROR': '\033[31m', # Red
29
+ 'CRITICAL': '\033[31m', # Red
30
+ 'TIME': '\033[34m',
31
+ 'RESET': '\033[0m'
32
+ }
33
+ LOG_FORMAT = f"[%(levelname)s] {COLORS.get('TIME')}%(asctime)s{COLORS.get('RESET')} %(message)s |" \
34
+ f"{COLORS.get('ARGUMENTS')} " \
35
+ f"%(optional_args)s " \
36
+ f"thread=%(thread)d {COLORS.get('RESET')}"
32
37
 
33
38
  # Create thread local storage that the format() call below uses.
34
39
  # This is only used by the json_logger in the appropriate CLARIFAI_DEPLOY levels.
@@ -59,6 +64,9 @@ def get_req_id_from_context():
59
64
 
60
65
  def display_workflow_tree(nodes_data: List[Dict]) -> None:
61
66
  """Displays a tree of the workflow nodes."""
67
+ from rich import print as rprint
68
+ from rich.tree import Tree
69
+
62
70
  # Create a mapping of node_id to the list of node_ids that are connected to it.
63
71
  node_adj_mapping = defaultdict(list)
64
72
  # Create a mapping of node_id to the node data info.
@@ -104,8 +112,10 @@ def display_workflow_tree(nodes_data: List[Dict]) -> None:
104
112
  rprint(tree)
105
113
 
106
114
 
107
- def table_from_dict(data: List[Dict], column_names: List[str], title: str = "") -> Table:
115
+ def table_from_dict(data: List[Dict], column_names: List[str],
116
+ title: str = "") -> 'rich.Table': #noqa F821
108
117
  """Use this function for printing tables from a list of dicts."""
118
+ from rich.table import Table
109
119
  table = Table(title=title, show_lines=False, show_header=True, header_style="blue")
110
120
  for column_name in column_names:
111
121
  table.add_column(column_name)
@@ -134,23 +144,18 @@ def _configure_logger(name: str, logger_level: Union[int, str] = logging.NOTSET)
134
144
  # If ENABLE_JSON_LOGGER is not set, then use json logger if in k8s.
135
145
  enabled_json = os.getenv('ENABLE_JSON_LOGGER', None)
136
146
  in_k8s = 'KUBERNETES_SERVICE_HOST' in os.environ
147
+ handler = logging.StreamHandler()
148
+ handler.setLevel(logger_level)
137
149
  if enabled_json == 'true' or (in_k8s and enabled_json != 'false'):
138
150
  # Add the json handler and formatter
139
- handler = logging.StreamHandler()
140
151
  formatter = JsonFormatter()
141
152
  handler.setFormatter(formatter)
142
- logger.addHandler(handler)
143
153
  else:
144
- # Add the new rich handler and formatter
145
- try:
146
- width, _ = os.get_terminal_size()
147
- except OSError:
148
- width = 255
149
- handler = RichHandler(
150
- rich_tracebacks=True, log_time_format="%Y-%m-%d %H:%M:%S.%f", console=Console(width=width))
151
- formatter = logging.Formatter('%(message)s')
154
+ # create formatter and add it to the handlers
155
+ formatter = TerminalFormatter(LOG_FORMAT)
152
156
  handler.setFormatter(formatter)
153
- logger.addHandler(handler)
157
+ # add the handlers to the logger
158
+ logger.addHandler(handler)
154
159
 
155
160
 
156
161
  def get_logger(logger_level: Union[int, str] = logging.NOTSET,
@@ -207,6 +212,8 @@ def display_concept_relations_tree(relations_dict: Dict[str, Any]) -> None:
207
212
  Args:
208
213
  relations_dict (dict): A dict of concept relations info.
209
214
  """
215
+ from rich import print as rprint
216
+ from rich.tree import Tree
210
217
  for parent, children in relations_dict.items():
211
218
  tree = Tree(parent)
212
219
  for child in children:
@@ -372,5 +379,41 @@ class JsonFormatter(logging.Formatter):
372
379
  )
373
380
 
374
381
 
382
+ class TerminalFormatter(logging.Formatter):
383
+ """ If you have fields in your Formatter (see setup_logger where we setup the format strings) then
384
+ you can set them on the record using a filter. We do that for req_id here which is a request
385
+ specific field. This allows us to find requests easily between services.
386
+ """
387
+
388
+ def format(self, record):
389
+ record.optional_args = []
390
+
391
+ user_id = getattr(thread_log_info, 'user_id', None)
392
+ if user_id is not None:
393
+ record.optional_args.append("user_id=" + user_id)
394
+
395
+ app_id = getattr(thread_log_info, 'app_id', None)
396
+ if app_id is not None:
397
+ record.optional_args.append("app_id=" + app_id)
398
+
399
+ req_id = getattr(thread_log_info, 'req_id', None)
400
+ if req_id is not None:
401
+ record.optional_args.append("req_id=" + req_id)
402
+
403
+ record.optional_args = " ".join(record.optional_args)
404
+
405
+ color_code = COLORS.get(record.levelname, '')
406
+
407
+ record.levelname = f"{color_code}{record.levelname}{COLORS.get('RESET')}"
408
+ record.msg = f"{color_code}{str(record.msg)}{COLORS.get('RESET')}"
409
+
410
+ return super(TerminalFormatter, self).format(record)
411
+
412
+ def formatTime(self, record, datefmt=None):
413
+ # Note we didn't go with UTC here as it's easier to understand time in your time zone.
414
+ # The json logger leverages UTC though.
415
+ return datetime.datetime.fromtimestamp(record.created).strftime('%H:%M:%S.%f')
416
+
417
+
375
418
  # the default logger for the SDK.
376
419
  logger = get_logger(logger_level=os.environ.get("LOG_LEVEL", "INFO"), name="clarifai")
clarifai/utils/misc.py CHANGED
@@ -12,6 +12,8 @@ RETRYABLE_CODES = [
12
12
  status_code_pb2.MODEL_BUSY_PLEASE_RETRY
13
13
  ]
14
14
 
15
+ DEFAULT_CONFIG = f'{os.environ["HOME"]}/.config/clarifai/config'
16
+
15
17
 
16
18
  def status_is_retryable(status_code: int) -> bool:
17
19
  """Check if a status code is retryable."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarifai
3
- Version: 11.2.2
3
+ Version: 11.2.3
4
4
  Summary: Clarifai Python SDK
5
5
  Home-page: https://github.com/Clarifai/clarifai-python
6
6
  Author: Clarifai
@@ -21,7 +21,7 @@ Requires-Python: >=3.8
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
23
  Requires-Dist: clarifai-grpc>=11.2.6
24
- Requires-Dist: clarifai-protocol>=0.0.20
24
+ Requires-Dist: clarifai-protocol>=0.0.21
25
25
  Requires-Dist: numpy>=1.22.0
26
26
  Requires-Dist: tqdm>=4.65.0
27
27
  Requires-Dist: rich>=13.4.2
@@ -1,20 +1,20 @@
1
- clarifai/__init__.py,sha256=_cDM_DxpY5KiS6333RgrXKdnvdwjkQID_vppBsYvGPM,23
1
+ clarifai/__init__.py,sha256=cMulojaj2PqKzdUooqsKg8CUvyqheI7pr_8Y-DBZwsQ,23
2
2
  clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  clarifai/errors.py,sha256=RwzTajwds51wLD0MVlMC5kcpBnzRpreDLlazPSBZxrg,2605
4
4
  clarifai/versions.py,sha256=jctnczzfGk_S3EnVqb2FjRKfSREkNmvNEwAAa_VoKiQ,222
5
5
  clarifai/cli/README.md,sha256=YGApHfeUyu5P0Pdth-mqQCQftWHDxz6bugDlvDXDhOE,1942
6
6
  clarifai/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  clarifai/cli/__main__.py,sha256=utJ2F40cl0jPHcYdTlGZRqpPfZ0CtVYB-8Ft0b2fWD4,72
8
- clarifai/cli/base.py,sha256=SOAic4T6Hg7VJJ-UDdjTuTNI1Hu_YANmzW_giUjK24o,3853
9
- clarifai/cli/compute_cluster.py,sha256=v77YUbZjmXbTq0wCmcUJ8TzYSfFEtB1na87-iZuG21Q,1921
10
- clarifai/cli/deployment.py,sha256=Vv92Qo7Q3UmMiCdrGQ4qNVNVzfcDyl-GB6B7kx8gyFw,2597
11
- clarifai/cli/model.py,sha256=PR-A7V3D78iAjNx2hNeputiWuIyINrx2SJmjKtfMoQ4,12079
12
- clarifai/cli/nodepool.py,sha256=eYo3l9NMSwjeFzsuwKSYVkR1FdZ7_NcCdNvzGsBBMzY,3139
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=4n9CmpKOHXY1KxEzhmUy6l5hhU5u_mKhatLXY0L3LVo,12064
12
+ clarifai/cli/nodepool.py,sha256=7nTNd9T-UEPFE36vbxwdUHu2B3NECbN-lSTb_DQYw18,3874
13
13
  clarifai/client/__init__.py,sha256=xI1U0l5AZdRThvQAXCLsd9axxyFzXXJ22m8LHqVjQRU,662
14
14
  clarifai/client/app.py,sha256=FnKvKksYZwdry0e4Obh-trdSO1mv6QcVAa3kzKiQMpU,38340
15
15
  clarifai/client/base.py,sha256=hSHOqkXbSKyaRDeylMMnkhUHCAHhEqno4KI0CXGziBA,7536
16
16
  clarifai/client/compute_cluster.py,sha256=EvW9TJjPvInUlggfg1A98sxoWH8_PY5rCVXZhsj6ac0,8705
17
- clarifai/client/dataset.py,sha256=y3zKT_VhP1gyN3OO-b3cPeW21ZXyKbQ7ZJkEG06bsTU,32096
17
+ clarifai/client/dataset.py,sha256=6DqfXQtiHoOJq0vPw2fz5ATo5zxQMmlhKG9IBwhnXeU,32078
18
18
  clarifai/client/deployment.py,sha256=w7Y6pA1rYG4KRK1SwusRZc2sQRXlG8wezuVdzSWpCo0,2586
19
19
  clarifai/client/input.py,sha256=obMAHMDU1OwfXZ8KraOnGFlWzlW-3F7Ob_2lcOQMlhY,46339
20
20
  clarifai/client/lister.py,sha256=03KGMvs5RVyYqxLsSrWhNc34I8kiF1Ph0NeyEwu7nMU,2082
@@ -27,7 +27,7 @@ clarifai/client/workflow.py,sha256=5VjZ2D8cudLznR8yhrwNawOmjxUhkJllZMKM6pn-4gs,1
27
27
  clarifai/client/auth/__init__.py,sha256=7EwR0NrozkAUwpUnCsqXvE_p0wqx_SelXlSpKShKJK0,136
28
28
  clarifai/client/auth/helper.py,sha256=Ngw5IDkOWvnOz5YwViVk55z3mC52MyezLc0G3WxLqok,14643
29
29
  clarifai/client/auth/register.py,sha256=2CMdBsoVLoTfjyksE6j7BM2tiEc73WKYvxnwDDgNn1k,536
30
- clarifai/client/auth/stub.py,sha256=xy4-fV0W8keCgXld4eOVzFQEIKxOktNwtL5bLztReug,4940
30
+ clarifai/client/auth/stub.py,sha256=FrA5QpEFY4sK6fvPVhTg19ROLHkYSRo343nNqiVE7xw,4963
31
31
  clarifai/constants/base.py,sha256=ogmFSZYoF0YhGjHg5aiOc3MLqPr_poKAls6xaD0_C3U,89
32
32
  clarifai/constants/dataset.py,sha256=vjK3IlgXu31HycuvjRSzEQSqhU6xfj5TIgo6IpyUWoc,609
33
33
  clarifai/constants/input.py,sha256=WcHwToUVIK9ItAhDefaSohQHCLNeR55PSjZ0BFnoZ3U,28
@@ -66,13 +66,13 @@ clarifai/runners/server.py,sha256=xHDLdhQApCgYG19QOKXqJNCGNyw1Vsvobq3UdryDrVc,41
66
66
  clarifai/runners/dockerfile_template/Dockerfile.template,sha256=5cjv7U8PmWa3DB_5B1CqSYh_6GE0E0np52TIAa7EIDE,2312
67
67
  clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
68
68
  clarifai/runners/models/base_typed_model.py,sha256=0QCWxch8CcyJSKvE1D4PILd2RSnQZHTmx4DXlQQ6dpo,7856
69
- clarifai/runners/models/model_builder.py,sha256=NAZiOm2ok-ThQ-jcAyBTRRCFufmyxGY76vlkLMpYHq4,33320
69
+ clarifai/runners/models/model_builder.py,sha256=eL7gLgdJjsHrJy2Omu0XiGoACBl3CwCZan4SSEiUmG8,33984
70
70
  clarifai/runners/models/model_class.py,sha256=9JSPAr4U4K7xI0kSl-q0mHB06zknm2OR-8XIgBCto94,1611
71
- clarifai/runners/models/model_run_locally.py,sha256=jz4ZvRj0eMCEziV3X37wH2AEe3Gl9Icx7Quy1ymaDe0,20556
71
+ clarifai/runners/models/model_run_locally.py,sha256=qwWJ4UvvMx3ktbwIwjoucJ725TxRbK9CDa5ZMiy6vJM,20592
72
72
  clarifai/runners/models/model_runner.py,sha256=PyxwK-33hLlhkD07tTXkjWZ_iNlZHl9_8AZ2W7WfExI,6097
73
73
  clarifai/runners/models/model_servicer.py,sha256=jtQmtGeQlvQ5ttMvVw7CMnNzq-rLkTaxR2IWF9SnHwk,2808
74
74
  clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
75
- clarifai/runners/utils/const.py,sha256=bwj-Pcw558-pasdIFbNhnkn-9oiCdojYH1fNTTUG2gU,1048
75
+ clarifai/runners/utils/const.py,sha256=9qnOC1Bt6SGLQ9XCQEQ6519XhW4gzcztsV1Rgej67Vw,1055
76
76
  clarifai/runners/utils/data_handler.py,sha256=sxy9zlAgI6ETuxCQhUgEXAn2GCsaW1GxpK6GTaMne0g,6966
77
77
  clarifai/runners/utils/data_utils.py,sha256=R1iQ82TuQ9JwxCJk8yEB1Lyb0BYVhVbWJI9YDi1zGOs,318
78
78
  clarifai/runners/utils/loader.py,sha256=Sl0m29RDtMPx2cIiSbbDFtKHQj2ktXQ5CnkvaHi-zDc,8804
@@ -80,10 +80,11 @@ clarifai/runners/utils/url_fetcher.py,sha256=v_8JOWmkyFAzsBulsieKX7Nfjy1Yg7wGSZe
80
80
  clarifai/schema/search.py,sha256=JjTi8ammJgZZ2OGl4K6tIA4zEJ1Fr2ASZARXavI1j5c,2448
81
81
  clarifai/urls/helper.py,sha256=tjoMGGHuWX68DUB0pk4MEjrmFsClUAQj2jmVEM_Sy78,4751
82
82
  clarifai/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
- clarifai/utils/cli.py,sha256=P29JalmKQLQBWqbW2_bumCLNSUUo8APtLXD8zS0dcIk,2160
84
- clarifai/utils/constants.py,sha256=MG_iHnSwNEyUZOpvsrTicNwaT4CIjmlK_Ixk_qqEX8g,142
85
- clarifai/utils/logging.py,sha256=CVy8OsLrlbg-b8qe88kb1yO_9wi9wRYfF-QkIaN9xE8,11936
86
- clarifai/utils/misc.py,sha256=4aNOHPTNdX-WGxuNab8qKePoCMUnscd-aN_dQEIVSWk,2933
83
+ clarifai/utils/cli.py,sha256=FUFJJb8Jzohpt132JE43xHNzWtX0N8fbWROxJISfCM0,5072
84
+ clarifai/utils/config.py,sha256=MxuQ1U4EOT4yVOEcRyv3OUPnoY_A_J5cZKHJGiuuo30,2883
85
+ clarifai/utils/constants.py,sha256=fdCmw8fjgo8eoWu85t95ZoRTrgXC5_XVXFyB8_VQTtw,219
86
+ clarifai/utils/logging.py,sha256=I2Sj1X-phYcINXe4-pW22Tq6Sz5PlwcxYQh7zORBbeM,13634
87
+ clarifai/utils/misc.py,sha256=gensDjU5pV44iFzUzmM_Lf6PZX63GFxRXJX91esEjAg,2999
87
88
  clarifai/utils/model_train.py,sha256=Mndqy5GNu7kjQHjDyNVyamL0hQFLGSHcWhOuPyOvr1w,8005
88
89
  clarifai/utils/evaluation/__init__.py,sha256=PYkurUrXrGevByj7RFb6CoU1iC7fllyQSfnnlo9WnY8,69
89
90
  clarifai/utils/evaluation/helpers.py,sha256=aZeHLI7oSmU5YDWQp5GdkYW5qbHx37nV9xwunKTAwWM,18549
@@ -93,9 +94,9 @@ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
93
94
  clarifai/workflows/export.py,sha256=vICRhIreqDSShxLKjHNM2JwzKsf1B4fdXB0ciMcA70k,1945
94
95
  clarifai/workflows/utils.py,sha256=nGeB_yjVgUO9kOeKTg4OBBaBz-AwXI3m-huSVj-9W18,1924
95
96
  clarifai/workflows/validate.py,sha256=yJq03MaJqi5AK3alKGJJBR89xmmjAQ31sVufJUiOqY8,2556
96
- clarifai-11.2.2.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
97
- clarifai-11.2.2.dist-info/METADATA,sha256=mWqPwNuC1LdGkPWUu5ugnqADyHzcwR18PA66roRCPj4,22472
98
- clarifai-11.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
99
- clarifai-11.2.2.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
100
- clarifai-11.2.2.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
101
- clarifai-11.2.2.dist-info/RECORD,,
97
+ clarifai-11.2.3.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
98
+ clarifai-11.2.3.dist-info/METADATA,sha256=7YnU6nLN-FgtfIPvDfv-qMUvS8B93f86eYrZFC4S-V0,22472
99
+ clarifai-11.2.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
100
+ clarifai-11.2.3.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
101
+ clarifai-11.2.3.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
102
+ clarifai-11.2.3.dist-info/RECORD,,