clarifai 11.3.0rc2__py3-none-any.whl → 11.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/cli/__main__.py +1 -1
  3. clarifai/cli/base.py +144 -136
  4. clarifai/cli/compute_cluster.py +45 -31
  5. clarifai/cli/deployment.py +93 -76
  6. clarifai/cli/model.py +578 -180
  7. clarifai/cli/nodepool.py +100 -82
  8. clarifai/client/__init__.py +12 -2
  9. clarifai/client/app.py +973 -911
  10. clarifai/client/auth/helper.py +345 -342
  11. clarifai/client/auth/register.py +7 -7
  12. clarifai/client/auth/stub.py +107 -106
  13. clarifai/client/base.py +185 -178
  14. clarifai/client/compute_cluster.py +214 -180
  15. clarifai/client/dataset.py +793 -698
  16. clarifai/client/deployment.py +55 -50
  17. clarifai/client/input.py +1223 -1088
  18. clarifai/client/lister.py +47 -45
  19. clarifai/client/model.py +1939 -1717
  20. clarifai/client/model_client.py +525 -502
  21. clarifai/client/module.py +82 -73
  22. clarifai/client/nodepool.py +358 -213
  23. clarifai/client/runner.py +58 -0
  24. clarifai/client/search.py +342 -309
  25. clarifai/client/user.py +419 -414
  26. clarifai/client/workflow.py +294 -274
  27. clarifai/constants/dataset.py +11 -17
  28. clarifai/constants/model.py +8 -2
  29. clarifai/datasets/export/inputs_annotations.py +233 -217
  30. clarifai/datasets/upload/base.py +63 -51
  31. clarifai/datasets/upload/features.py +43 -38
  32. clarifai/datasets/upload/image.py +237 -207
  33. clarifai/datasets/upload/loaders/coco_captions.py +34 -32
  34. clarifai/datasets/upload/loaders/coco_detection.py +72 -65
  35. clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
  36. clarifai/datasets/upload/loaders/xview_detection.py +274 -132
  37. clarifai/datasets/upload/multimodal.py +55 -46
  38. clarifai/datasets/upload/text.py +55 -47
  39. clarifai/datasets/upload/utils.py +250 -234
  40. clarifai/errors.py +51 -50
  41. clarifai/models/api.py +260 -238
  42. clarifai/modules/css.py +50 -50
  43. clarifai/modules/pages.py +33 -33
  44. clarifai/rag/rag.py +312 -288
  45. clarifai/rag/utils.py +91 -84
  46. clarifai/runners/models/model_builder.py +906 -802
  47. clarifai/runners/models/model_class.py +370 -331
  48. clarifai/runners/models/model_run_locally.py +459 -419
  49. clarifai/runners/models/model_runner.py +170 -162
  50. clarifai/runners/models/model_servicer.py +78 -70
  51. clarifai/runners/server.py +111 -101
  52. clarifai/runners/utils/code_script.py +225 -187
  53. clarifai/runners/utils/const.py +4 -1
  54. clarifai/runners/utils/data_types/__init__.py +12 -0
  55. clarifai/runners/utils/data_types/data_types.py +598 -0
  56. clarifai/runners/utils/data_utils.py +387 -440
  57. clarifai/runners/utils/loader.py +247 -227
  58. clarifai/runners/utils/method_signatures.py +411 -386
  59. clarifai/runners/utils/openai_convertor.py +108 -109
  60. clarifai/runners/utils/serializers.py +175 -179
  61. clarifai/runners/utils/url_fetcher.py +35 -35
  62. clarifai/schema/search.py +56 -63
  63. clarifai/urls/helper.py +125 -102
  64. clarifai/utils/cli.py +129 -123
  65. clarifai/utils/config.py +127 -87
  66. clarifai/utils/constants.py +49 -0
  67. clarifai/utils/evaluation/helpers.py +503 -466
  68. clarifai/utils/evaluation/main.py +431 -393
  69. clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
  70. clarifai/utils/logging.py +324 -306
  71. clarifai/utils/misc.py +60 -56
  72. clarifai/utils/model_train.py +165 -146
  73. clarifai/utils/protobuf.py +126 -103
  74. clarifai/versions.py +3 -1
  75. clarifai/workflows/export.py +48 -50
  76. clarifai/workflows/utils.py +39 -36
  77. clarifai/workflows/validate.py +55 -43
  78. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
  79. clarifai-11.4.0.dist-info/RECORD +109 -0
  80. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
  81. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  82. clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
  83. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  84. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  85. clarifai/__pycache__/errors.cpython-311.pyc +0 -0
  86. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  87. clarifai/__pycache__/versions.cpython-311.pyc +0 -0
  88. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  89. clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
  90. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  91. clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
  92. clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  93. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  94. clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  95. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  96. clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
  97. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  98. clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
  99. clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  100. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  101. clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
  102. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  103. clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
  104. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  105. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  106. clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
  107. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  108. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  109. clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
  110. clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  111. clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  112. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  113. clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
  114. clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
  115. clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
  116. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  117. clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
  118. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  119. clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
  120. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  121. clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
  122. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  123. clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
  124. clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
  125. clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
  126. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  127. clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
  128. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  129. clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
  130. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  131. clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
  132. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  133. clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
  134. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  135. clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
  136. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  137. clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
  138. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  139. clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
  140. clarifai/client/cli/__init__.py +0 -0
  141. clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  142. clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  143. clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  144. clarifai/client/cli/base_cli.py +0 -88
  145. clarifai/client/cli/model_cli.py +0 -29
  146. clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
  147. clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
  148. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  149. clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
  150. clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
  151. clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
  152. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  153. clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
  154. clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
  155. clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
  156. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  157. clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
  158. clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
  159. clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
  160. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  161. clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
  162. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  163. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  164. clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
  165. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  166. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  167. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
  168. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  169. clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
  170. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  171. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  172. clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
  173. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  174. clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
  175. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  176. clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
  177. clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
  178. clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
  179. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  180. clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
  181. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  182. clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
  183. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
  184. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  185. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
  186. clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
  187. clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
  188. clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
  189. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  190. clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
  191. clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
  192. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  193. clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
  194. clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
  195. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  196. clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
  197. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  198. clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
  199. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  200. clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
  201. clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
  202. clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
  203. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  204. clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
  205. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  206. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  207. clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
  208. clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
  209. clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
  210. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  211. clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
  212. clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
  213. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  214. clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
  215. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  216. clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
  217. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  218. clarifai/runners/models/base_typed_model.py +0 -238
  219. clarifai/runners/models/model_class_refract.py +0 -80
  220. clarifai/runners/models/model_upload.py +0 -607
  221. clarifai/runners/models/temp.py +0 -25
  222. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  223. clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  224. clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  225. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  226. clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
  227. clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
  228. clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
  229. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  230. clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
  231. clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
  232. clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
  233. clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
  234. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  235. clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
  236. clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
  237. clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
  238. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  239. clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
  240. clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
  241. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  242. clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
  243. clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
  244. clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
  245. clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
  246. clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
  247. clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
  248. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  249. clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
  250. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  251. clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
  252. clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
  253. clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
  254. clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
  255. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  256. clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
  257. clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
  258. clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
  259. clarifai/runners/utils/data_handler.py +0 -231
  260. clarifai/runners/utils/data_handler_refract.py +0 -213
  261. clarifai/runners/utils/data_types.py +0 -469
  262. clarifai/runners/utils/logger.py +0 -0
  263. clarifai/runners/utils/openai_format.py +0 -87
  264. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  265. clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
  266. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  267. clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
  268. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  269. clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  270. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  271. clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
  272. clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
  273. clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
  274. clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
  275. clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
  276. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  277. clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
  278. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  279. clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
  280. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  281. clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
  282. clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
  283. clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
  284. clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
  285. clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
  286. clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
  287. clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
  288. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  289. clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
  290. clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
  291. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  292. clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
  293. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  294. clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
  295. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  296. clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
  297. clarifai-11.3.0rc2.dist-info/RECORD +0 -322
  298. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
  299. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
  300. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
@@ -1,217 +1,255 @@
1
1
  import json
2
2
  from typing import List
3
+
3
4
  from clarifai_grpc.grpc.api import resources_pb2
5
+
4
6
  from clarifai.runners.utils import data_types
5
7
 
6
8
 
7
- def generate_client_script(method_signatures: List[resources_pb2.MethodSignature], user_id, app_id,
8
- model_id) -> str:
9
- _CLIENT_TEMPLATE = """\
10
- from clarifai.runners.utils import data_types
9
+ def generate_client_script(
10
+ method_signatures: List[resources_pb2.MethodSignature],
11
+ user_id,
12
+ app_id,
13
+ model_id,
14
+ base_url: str = None,
15
+ deployment_id: str = None,
16
+ use_ctx: bool = False,
17
+ ) -> str:
18
+ _CLIENT_TEMPLATE = """\
11
19
  import os
12
- from clarifai.client import Model
13
20
 
14
- model = Model("www.clarifai.com/{user_id}/{app_id}/{model_id}",
15
- deployment_id = os.environ['CLARIFAI_DEPLOYMENT_ID'], # Only needed for dedicated deployed models
16
- )
21
+ from clarifai.client import Model
22
+ from clarifai.runners.utils import data_types
23
+ {model_section}
17
24
  """
18
- # Generate client template
19
- client_template = _CLIENT_TEMPLATE.format(user_id=user_id, app_id=app_id, model_id=model_id)
20
-
21
- # Generate method signatures
22
- method_signatures_str = []
23
- for method_signature in method_signatures:
24
- method_name = method_signature.name
25
- if method_signature.method_type in [
26
- resources_pb2.RunnerMethodType.UNARY_UNARY,
27
- resources_pb2.RunnerMethodType.UNARY_STREAMING,
28
- ]:
29
-
30
- client_script_str = f'response = model.{method_name}('
31
- annotations = _get_annotations_source(method_signature)
32
- for param_name, (param_type, default_value) in annotations.items():
33
- if param_name == "return":
34
- continue
35
- if default_value is None:
36
- default_value = _set_default_value(param_type)
37
- if param_type == "str":
38
- default_value = repr(default_value)
39
-
40
- client_script_str += f"{param_name}={default_value}, "
41
- client_script_str = client_script_str.rstrip(", ") + ")"
42
- if method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_UNARY:
43
- client_script_str += "\nprint(response)"
44
- elif method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_STREAMING:
45
- client_script_str += "\nfor res in response:\n print(res)"
46
- client_script_str += "\n"
47
- method_signatures_str.append(client_script_str)
48
-
49
- method_signatures_str = "\n".join(method_signatures_str)
50
- # Combine all parts
51
- script_lines = []
52
- script_lines.append("\n# Clarifai Model Client Script")
53
- script_lines.append(
54
- "# Set the environment variables `CLARIFAI_DEPLOYMENT_ID` and `CLARIFAI_PAT` to run this script."
55
- )
56
- script_lines.append("# Example usage:")
57
- script_lines.append(client_template)
58
- script_lines.append("# Example model prediction from different model methods: \n")
59
- script_lines.append(method_signatures_str)
60
- script_lines.append("")
61
- script = "\n".join(script_lines)
62
- return script
25
+
26
+ deployment_id = (
27
+ "os.environ['CLARIFAI_DEPLOYMENT_ID']" if deployment_id is None else deployment_id
28
+ )
29
+
30
+ base_url_str = ""
31
+ if base_url is not None:
32
+ base_url_str = f"base_url={base_url},"
33
+
34
+ if use_ctx:
35
+ model_section = """
36
+ model = Model.from_current_context()"""
37
+ else:
38
+ model_section = """
39
+ model = Model("https://clarifai.com/{user_id}/{app_id}/{model_id}",
40
+ deployment_id = {deployment_id}, # Only needed for dedicated deployed models
41
+ {base_url_str}
42
+ )
43
+ """
44
+ model_section = _CLIENT_TEMPLATE.format(
45
+ user_id=user_id,
46
+ app_id=app_id,
47
+ model_id=model_id,
48
+ deployment_id=deployment_id,
49
+ base_url_str=base_url_str,
50
+ )
51
+
52
+ # Generate client template
53
+ client_template = _CLIENT_TEMPLATE.format(
54
+ model_section=model_section,
55
+ )
56
+
57
+ # Generate method signatures
58
+ method_signatures_str = []
59
+ for method_signature in method_signatures:
60
+ method_name = method_signature.name
61
+ if method_signature.method_type in [
62
+ resources_pb2.RunnerMethodType.UNARY_UNARY,
63
+ resources_pb2.RunnerMethodType.UNARY_STREAMING,
64
+ ]:
65
+ client_script_str = f'response = model.{method_name}('
66
+ annotations = _get_annotations_source(method_signature)
67
+ for param_name, (param_type, default_value) in annotations.items():
68
+ if param_name == "return":
69
+ continue
70
+ if default_value is None:
71
+ default_value = _set_default_value(param_type)
72
+ if param_type == "str":
73
+ default_value = repr(default_value)
74
+
75
+ client_script_str += f"{param_name}={default_value}, "
76
+ client_script_str = client_script_str.rstrip(", ") + ")"
77
+ if method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_UNARY:
78
+ client_script_str += "\nprint(response)"
79
+ elif method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_STREAMING:
80
+ client_script_str += "\nfor res in response:\n print(res)"
81
+ client_script_str += "\n"
82
+ method_signatures_str.append(client_script_str)
83
+
84
+ method_signatures_str = "\n".join(method_signatures_str)
85
+ # Combine all parts
86
+ script_lines = []
87
+ script_lines.append("\n# Clarifai Model Client Script")
88
+ if not use_ctx:
89
+ script_lines.append(
90
+ "# Set the environment variables `CLARIFAI_DEPLOYMENT_ID` and `CLARIFAI_PAT` to run this script."
91
+ )
92
+ script_lines.append("# Example usage:")
93
+ script_lines.append(client_template)
94
+ script_lines.append("# Example model prediction from different model methods: \n")
95
+ script_lines.append(method_signatures_str)
96
+ script_lines.append("")
97
+ script = "\n".join(script_lines)
98
+ return script
63
99
 
64
100
 
65
101
  # get annotations source with default values
66
102
  def _get_annotations_source(method_signature: resources_pb2.MethodSignature) -> dict:
67
- annotations = {}
68
- for input_field in method_signature.input_fields:
69
- param_name = input_field.name
70
- param_type = _get_base_type(input_field)
71
- if input_field.iterator:
72
- param_type = f"Iterator[{param_type}]"
73
- default_value = None
74
- if input_field.default:
75
- default_value = _parse_default_value(input_field)
76
-
77
- annotations[param_name] = (param_type, default_value)
78
- if not method_signature.output_fields:
79
- raise ValueError("MethodSignature must have at least one output field")
80
- for output_field in method_signature.output_fields:
81
- param_name = output_field.name
82
- param_type = _get_base_type(output_field)
83
- if output_field.iterator:
84
- param_type = f"Iterator[{param_type}]"
85
- annotations[param_name] = (param_type, None)
86
- return annotations
103
+ annotations = {}
104
+ for input_field in method_signature.input_fields:
105
+ param_name = input_field.name
106
+ param_type = _get_base_type(input_field)
107
+ if input_field.iterator:
108
+ param_type = f"Iterator[{param_type}]"
109
+ default_value = None
110
+ if input_field.default:
111
+ default_value = _parse_default_value(input_field)
112
+
113
+ annotations[param_name] = (param_type, default_value)
114
+ if not method_signature.output_fields:
115
+ raise ValueError("MethodSignature must have at least one output field")
116
+ for output_field in method_signature.output_fields:
117
+ param_name = output_field.name
118
+ param_type = _get_base_type(output_field)
119
+ if output_field.iterator:
120
+ param_type = f"Iterator[{param_type}]"
121
+ annotations[param_name] = (param_type, None)
122
+ return annotations
87
123
 
88
124
 
89
125
  def _get_base_type(field: resources_pb2.ModelTypeField) -> str:
90
- data_type = field.type
91
- if data_type == resources_pb2.ModelTypeField.DataType.NAMED_FIELDS:
92
- annotations = {}
93
- for type_arg in field.type_args:
94
- field_name = type_arg.name
95
- field_type = _get_base_type(type_arg)
96
- annotations[field_name] = field_type
97
- class_name = f"NamedFields[{', '.join(f'{k}: {v}' for k, v in annotations.items())}]"
98
- return class_name
99
- elif data_type == resources_pb2.ModelTypeField.DataType.TUPLE:
100
- type_args_str = [_get_base_type(ta) for ta in field.type_args]
101
- return f"Tuple[{', '.join(type_args_str)}]"
102
- elif data_type == resources_pb2.ModelTypeField.DataType.LIST:
103
- if len(field.type_args) != 1:
104
- raise ValueError("List type must have exactly one type argument")
105
- element_type = _get_base_type(field.type_args[0])
106
- return f"List[{element_type}]"
107
- else:
108
- type_map = {
109
- resources_pb2.ModelTypeField.DataType.STR: "str",
110
- resources_pb2.ModelTypeField.DataType.BYTES: "bytes",
111
- resources_pb2.ModelTypeField.DataType.INT: "int",
112
- resources_pb2.ModelTypeField.DataType.FLOAT: "float",
113
- resources_pb2.ModelTypeField.DataType.BOOL: "bool",
114
- resources_pb2.ModelTypeField.DataType.NDARRAY: "np.ndarray",
115
- resources_pb2.ModelTypeField.DataType.JSON_DATA: "data_types.JSON",
116
- resources_pb2.ModelTypeField.DataType.TEXT: "data_types.Text",
117
- resources_pb2.ModelTypeField.DataType.IMAGE: "data_types.Image",
118
- resources_pb2.ModelTypeField.DataType.CONCEPT: "data_types.Concept",
119
- resources_pb2.ModelTypeField.DataType.REGION: "data_types.Region",
120
- resources_pb2.ModelTypeField.DataType.FRAME: "data_types.Frame",
121
- resources_pb2.ModelTypeField.DataType.AUDIO: "data_types.Audio",
122
- resources_pb2.ModelTypeField.DataType.VIDEO: "data_types.Video",
123
- }
124
- return type_map.get(data_type, "Any")
126
+ data_type = field.type
127
+ if data_type == resources_pb2.ModelTypeField.DataType.NAMED_FIELDS:
128
+ annotations = {}
129
+ for type_arg in field.type_args:
130
+ field_name = type_arg.name
131
+ field_type = _get_base_type(type_arg)
132
+ annotations[field_name] = field_type
133
+ class_name = f"NamedFields[{', '.join(f'{k}: {v}' for k, v in annotations.items())}]"
134
+ return class_name
135
+ elif data_type == resources_pb2.ModelTypeField.DataType.TUPLE:
136
+ type_args_str = [_get_base_type(ta) for ta in field.type_args]
137
+ return f"Tuple[{', '.join(type_args_str)}]"
138
+ elif data_type == resources_pb2.ModelTypeField.DataType.LIST:
139
+ if len(field.type_args) != 1:
140
+ raise ValueError("List type must have exactly one type argument")
141
+ element_type = _get_base_type(field.type_args[0])
142
+ return f"List[{element_type}]"
143
+ else:
144
+ type_map = {
145
+ resources_pb2.ModelTypeField.DataType.STR: "str",
146
+ resources_pb2.ModelTypeField.DataType.BYTES: "bytes",
147
+ resources_pb2.ModelTypeField.DataType.INT: "int",
148
+ resources_pb2.ModelTypeField.DataType.FLOAT: "float",
149
+ resources_pb2.ModelTypeField.DataType.BOOL: "bool",
150
+ resources_pb2.ModelTypeField.DataType.NDARRAY: "np.ndarray",
151
+ resources_pb2.ModelTypeField.DataType.JSON_DATA: "data_types.JSON",
152
+ resources_pb2.ModelTypeField.DataType.TEXT: "data_types.Text",
153
+ resources_pb2.ModelTypeField.DataType.IMAGE: "data_types.Image",
154
+ resources_pb2.ModelTypeField.DataType.CONCEPT: "data_types.Concept",
155
+ resources_pb2.ModelTypeField.DataType.REGION: "data_types.Region",
156
+ resources_pb2.ModelTypeField.DataType.FRAME: "data_types.Frame",
157
+ resources_pb2.ModelTypeField.DataType.AUDIO: "data_types.Audio",
158
+ resources_pb2.ModelTypeField.DataType.VIDEO: "data_types.Video",
159
+ }
160
+ return type_map.get(data_type, "Any")
125
161
 
126
162
 
127
163
  def _map_default_value(field_type):
128
- """
164
+ """
129
165
  Map the default value of a field type to a string representation.
130
166
  """
131
- default_value = None
132
-
133
- if field_type == "str":
134
- default_value = 'What is the future of AI?'
135
- elif field_type == "bytes":
136
- default_value = b""
137
- elif field_type == "int":
138
- default_value = 0
139
- elif field_type == "float":
140
- default_value = 0.0
141
- elif field_type == "bool":
142
- default_value = False
143
- elif field_type == "data_types.Image":
144
- default_value = data_types.Image.from_url("https://samples.clarifai.com/metro-north.jpg")
145
- elif field_type == "data_types.Text":
146
- default_value = data_types.Text("What's the future of AI?")
147
- elif field_type == "data_types.Audio":
148
- default_value = data_types.Audio.from_url("https://samples.clarifai.com/audio.mp3")
149
- elif field_type == "data_types.Video":
150
- default_value = data_types.Video.from_url("https://samples.clarifai.com/video.mp4")
151
- elif field_type == "data_types.Concept":
152
- default_value = data_types.Concept(id="concept_id", name="dog", value=0.95)
153
- elif field_type == "data_types.Region":
154
- default_value = data_types.Region(box=[0.1, 0.1, 0.5, 0.5],)
155
- elif field_type == "data_types.Frame":
156
- default_value = data_types.Frame.from_url("https://samples.clarifai.com/video.mp4", 0)
157
- elif field_type == "data_types.NDArray":
158
- default_value = data_types.NDArray([1, 2, 3])
159
- else:
160
167
  default_value = None
161
- return default_value
168
+
169
+ if field_type == "str":
170
+ default_value = 'What is the future of AI?'
171
+ elif field_type == "bytes":
172
+ default_value = b""
173
+ elif field_type == "int":
174
+ default_value = 0
175
+ elif field_type == "float":
176
+ default_value = 0.0
177
+ elif field_type == "bool":
178
+ default_value = False
179
+ elif field_type == "data_types.Image":
180
+ default_value = data_types.Image.from_url("https://samples.clarifai.com/metro-north.jpg")
181
+ elif field_type == "data_types.Text":
182
+ default_value = data_types.Text("What's the future of AI?")
183
+ elif field_type == "data_types.Audio":
184
+ default_value = data_types.Audio.from_url("https://samples.clarifai.com/audio.mp3")
185
+ elif field_type == "data_types.Video":
186
+ default_value = data_types.Video.from_url("https://samples.clarifai.com/video.mp4")
187
+ elif field_type == "data_types.Concept":
188
+ default_value = data_types.Concept(id="concept_id", name="dog", value=0.95)
189
+ elif field_type == "data_types.Region":
190
+ default_value = data_types.Region(
191
+ box=[0.1, 0.1, 0.5, 0.5],
192
+ )
193
+ elif field_type == "data_types.Frame":
194
+ default_value = data_types.Frame.from_url("https://samples.clarifai.com/video.mp4", 0)
195
+ elif field_type == "data_types.NDArray":
196
+ default_value = data_types.NDArray([1, 2, 3])
197
+ else:
198
+ default_value = None
199
+ return default_value
162
200
 
163
201
 
164
202
  def _set_default_value(field_type):
165
- """
203
+ """
166
204
  Set the default value of a field if it is not set.
167
205
  """
168
- default_value = None
169
- default_value = _map_default_value(field_type)
170
- if field_type.startswith("List["):
171
- element_type = field_type[5:-1]
172
- element_type_default_value = _map_default_value(element_type)
173
- if element_type_default_value is not None:
174
- default_value = f"[{element_type_default_value}]"
175
- elif field_type.startswith("Tuple["):
176
- element_types = field_type[6:-1].split(", ")
177
- element_type_defaults = [_map_default_value(et) for et in element_types]
178
- default_value = f"({', '.join([str(et) for et in element_type_defaults])})"
179
- elif field_type.startswith("NamedFields["):
180
- element_types = field_type[12:-1].split(", ")
181
- element_type_defaults = [_map_default_value(et) for et in element_types]
182
- default_value = f"{{{', '.join([str(et) for et in element_type_defaults])}}}"
183
-
184
- return default_value
206
+ default_value = None
207
+ default_value = _map_default_value(field_type)
208
+ if field_type.startswith("List["):
209
+ element_type = field_type[5:-1]
210
+ element_type_default_value = _map_default_value(element_type)
211
+ if element_type_default_value is not None:
212
+ default_value = f"[{element_type_default_value}]"
213
+ elif field_type.startswith("Tuple["):
214
+ element_types = field_type[6:-1].split(", ")
215
+ element_type_defaults = [_map_default_value(et) for et in element_types]
216
+ default_value = f"({', '.join([str(et) for et in element_type_defaults])})"
217
+ elif field_type.startswith("NamedFields["):
218
+ element_types = field_type[12:-1].split(", ")
219
+ element_type_defaults = [_map_default_value(et) for et in element_types]
220
+ default_value = f"{{{', '.join([str(et) for et in element_type_defaults])}}}"
221
+
222
+ return default_value
185
223
 
186
224
 
187
225
  def _parse_default_value(field: resources_pb2.ModelTypeField):
188
- if not field.default:
189
- return None
190
- default_str = field.default
191
- data_type = field.type
192
-
193
- try:
194
- if data_type == resources_pb2.ModelTypeField.DataType.INT:
195
- return str(int(default_str))
196
- elif data_type == resources_pb2.ModelTypeField.DataType.FLOAT:
197
- return str(float(default_str))
198
- elif data_type == resources_pb2.ModelTypeField.DataType.BOOL:
199
- return 'True' if default_str.lower() == 'true' else 'False'
200
- elif data_type == resources_pb2.ModelTypeField.DataType.STR:
201
- return repr(default_str)
202
- elif data_type == resources_pb2.ModelTypeField.DataType.BYTES:
203
- return f"b{repr(default_str.encode('utf-8'))}"
204
- elif data_type == resources_pb2.ModelTypeField.DataType.JSON_DATA:
205
- parsed = json.loads(default_str)
206
- return repr(parsed)
207
- elif data_type in (
208
- resources_pb2.ModelTypeField.DataType.LIST,
209
- resources_pb2.ModelTypeField.DataType.TUPLE,
210
- resources_pb2.ModelTypeField.DataType.NAMED_FIELDS,
211
- ):
212
- parsed = json.loads(default_str)
213
- return repr(parsed)
214
- else:
215
- return repr(default_str)
216
- except (ValueError, json.JSONDecodeError):
217
- return repr(default_str)
226
+ if not field.default:
227
+ return None
228
+ default_str = field.default
229
+ data_type = field.type
230
+
231
+ try:
232
+ if data_type == resources_pb2.ModelTypeField.DataType.INT:
233
+ return str(int(default_str))
234
+ elif data_type == resources_pb2.ModelTypeField.DataType.FLOAT:
235
+ return str(float(default_str))
236
+ elif data_type == resources_pb2.ModelTypeField.DataType.BOOL:
237
+ return 'True' if default_str.lower() == 'true' else 'False'
238
+ elif data_type == resources_pb2.ModelTypeField.DataType.STR:
239
+ return repr(default_str)
240
+ elif data_type == resources_pb2.ModelTypeField.DataType.BYTES:
241
+ return f"b{repr(default_str.encode('utf-8'))}"
242
+ elif data_type == resources_pb2.ModelTypeField.DataType.JSON_DATA:
243
+ parsed = json.loads(default_str)
244
+ return repr(parsed)
245
+ elif data_type in (
246
+ resources_pb2.ModelTypeField.DataType.LIST,
247
+ resources_pb2.ModelTypeField.DataType.TUPLE,
248
+ resources_pb2.ModelTypeField.DataType.NAMED_FIELDS,
249
+ ):
250
+ parsed = json.loads(default_str)
251
+ return repr(parsed)
252
+ else:
253
+ return repr(default_str)
254
+ except (ValueError, json.JSONDecodeError):
255
+ return repr(default_str)
@@ -30,5 +30,8 @@ AVAILABLE_TORCH_IMAGES = [
30
30
  '2.7.0-py3.12-rocm6.3',
31
31
  ]
32
32
  CONCEPTS_REQUIRED_MODEL_TYPE = [
33
- 'visual-classifier', 'visual-detector', 'visual-segmenter', 'text-classifier'
33
+ 'visual-classifier',
34
+ 'visual-detector',
35
+ 'visual-segmenter',
36
+ 'text-classifier',
34
37
  ]
@@ -0,0 +1,12 @@
1
+ from .data_types import JSON # noqa
2
+ from .data_types import Audio # noqa
3
+ from .data_types import Concept # noqa
4
+ from .data_types import Frame # noqa
5
+ from .data_types import Image # noqa
6
+ from .data_types import MessageData # noqa
7
+ from .data_types import NamedFields # noqa
8
+ from .data_types import NamedFieldsMeta # noqa
9
+ from .data_types import Region # noqa
10
+ from .data_types import Text # noqa
11
+ from .data_types import Video # noqa
12
+ from .data_types import cast # noqa