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
@@ -6,44 +6,44 @@ from clarifai.utils.logging import logger
6
6
 
7
7
 
8
8
  def download_input(input):
9
- _download_input_data(input.data)
10
- if input.data.parts:
11
- for i in range(len(input.data.parts)):
12
- _download_input_data(input.data.parts[i].data)
9
+ _download_input_data(input.data)
10
+ if input.data.parts:
11
+ for i in range(len(input.data.parts)):
12
+ _download_input_data(input.data.parts[i].data)
13
13
 
14
14
 
15
15
  def _download_input_data(input_data):
16
- """
17
- This function will download any urls that are not already bytes.
18
- """
19
- if input_data.image.url and not input_data.image.base64:
20
- # Download the image
21
- with fsspec.open(input_data.image.url, 'rb') as f:
22
- input_data.image.base64 = f.read()
23
- if input_data.video.url and not input_data.video.base64:
24
- # Download the video
25
- with fsspec.open(input_data.video.url, 'rb') as f:
26
- input_data.video.base64 = f.read()
27
- if input_data.audio.url and not input_data.audio.base64:
28
- # Download the audio
29
- with fsspec.open(input_data.audio.url, 'rb') as f:
30
- input_data.audio.base64 = f.read()
31
- if input_data.text.url and not input_data.text.raw:
32
- # Download the text
33
- with fsspec.open(input_data.text.url, 'r') as f:
34
- input_data.text.raw = f.read()
16
+ """
17
+ This function will download any urls that are not already bytes.
18
+ """
19
+ if input_data.image.url and not input_data.image.base64:
20
+ # Download the image
21
+ with fsspec.open(input_data.image.url, 'rb') as f:
22
+ input_data.image.base64 = f.read()
23
+ if input_data.video.url and not input_data.video.base64:
24
+ # Download the video
25
+ with fsspec.open(input_data.video.url, 'rb') as f:
26
+ input_data.video.base64 = f.read()
27
+ if input_data.audio.url and not input_data.audio.base64:
28
+ # Download the audio
29
+ with fsspec.open(input_data.audio.url, 'rb') as f:
30
+ input_data.audio.base64 = f.read()
31
+ if input_data.text.url and not input_data.text.raw:
32
+ # Download the text
33
+ with fsspec.open(input_data.text.url, 'r') as f:
34
+ input_data.text.raw = f.read()
35
35
 
36
36
 
37
37
  def ensure_urls_downloaded(request, max_threads=128):
38
- """
39
- This function will download any urls that are not already bytes and parallelize with a thread pool.
40
- """
41
- with concurrent.futures.ThreadPoolExecutor(max_workers=max_threads) as executor:
42
- futures = []
43
- for input in request.inputs:
44
- futures.append(executor.submit(download_input, input))
45
- for future in concurrent.futures.as_completed(futures):
46
- try:
47
- future.result()
48
- except Exception as e:
49
- logger.exception(f"Error downloading input: {e}")
38
+ """
39
+ This function will download any urls that are not already bytes and parallelize with a thread pool.
40
+ """
41
+ with concurrent.futures.ThreadPoolExecutor(max_workers=max_threads) as executor:
42
+ futures = []
43
+ for input in request.inputs:
44
+ futures.append(executor.submit(download_input, input))
45
+ for future in concurrent.futures.as_completed(futures):
46
+ try:
47
+ future.result()
48
+ except Exception as e:
49
+ logger.exception(f"Error downloading input: {e}")
clarifai/schema/search.py CHANGED
@@ -2,71 +2,64 @@ from schema import And, Optional, Regex, Schema
2
2
 
3
3
 
4
4
  def get_schema() -> Schema:
5
- """Initialize the schema for rank and filter.
5
+ """Initialize the schema for rank and filter.
6
6
 
7
- This schema validates:
7
+ This schema validates:
8
8
 
9
- - Rank and filter must be a list
10
- - Each item in the list must be a dict
11
- - The dict can contain these optional keys:
12
- - 'image_url': Valid URL string
13
- - 'text_raw': Non-empty string
14
- - 'metadata': Dict
15
- - 'image_bytes': Bytes
16
- - 'geo_point': Dict with 'longitude', 'latitude' and 'geo_limit' as float, float and int respectively
17
- - 'concepts': List where each item is a concept dict
18
- - Concept dict requires at least one of:
19
- - 'name': Non-empty string with dashes/underscores
20
- - 'id': Non-empty string
21
- - 'language': Non-empty string
22
- - 'value': 0 or 1 integer
23
- - 'input_types': List of 'image', 'video', 'text' or 'audio'
24
- - 'input_dataset_ids': List of strings
25
- - 'input_status_code': Integer
9
+ - Rank and filter must be a list
10
+ - Each item in the list must be a dict
11
+ - The dict can contain these optional keys:
12
+ - 'image_url': Valid URL string
13
+ - 'text_raw': Non-empty string
14
+ - 'metadata': Dict
15
+ - 'image_bytes': Bytes
16
+ - 'geo_point': Dict with 'longitude', 'latitude' and 'geo_limit' as float, float and int respectively
17
+ - 'concepts': List where each item is a concept dict
18
+ - Concept dict requires at least one of:
19
+ - 'name': Non-empty string with dashes/underscores
20
+ - 'id': Non-empty string
21
+ - 'language': Non-empty string
22
+ - 'value': 0 or 1 integer
23
+ - 'input_types': List of 'image', 'video', 'text' or 'audio'
24
+ - 'input_dataset_ids': List of strings
25
+ - 'input_status_code': Integer
26
26
 
27
- Returns:
28
- Schema: The schema for rank and filter.
29
- """
30
- # Schema for a single concept
31
- concept_schema = Schema({
32
- Optional('value'):
33
- And(int, lambda x: x in [0, 1]),
34
- Optional('id'):
35
- And(str, len),
36
- Optional('language'):
37
- And(str, len),
38
- # Non-empty strings with internal dashes and underscores.
39
- Optional('name'):
40
- And(str, len, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$'))
41
- })
27
+ Returns:
28
+ Schema: The schema for rank and filter.
29
+ """
30
+ # Schema for a single concept
31
+ concept_schema = Schema(
32
+ {
33
+ Optional('value'): And(int, lambda x: x in [0, 1]),
34
+ Optional('id'): And(str, len),
35
+ Optional('language'): And(str, len),
36
+ # Non-empty strings with internal dashes and underscores.
37
+ Optional('name'): And(str, len, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$')),
38
+ }
39
+ )
42
40
 
43
- # Schema for a rank or filter item
44
- rank_filter_item_schema = Schema({
45
- Optional('image_url'):
46
- And(str, Regex(r'^https?://')),
47
- Optional('text_raw'):
48
- And(str, len),
49
- Optional('metadata'):
50
- dict,
51
- Optional('image_bytes'):
52
- bytes,
53
- Optional('geo_point'): {
54
- 'longitude': float,
55
- 'latitude': float,
56
- 'geo_limit': int
57
- },
58
- Optional("concepts"):
59
- And(list, lambda x: all(concept_schema.is_valid(item) and len(item) > 0 for item in x)),
41
+ # Schema for a rank or filter item
42
+ rank_filter_item_schema = Schema(
43
+ {
44
+ Optional('image_url'): And(str, Regex(r'^https?://')),
45
+ Optional('text_raw'): And(str, len),
46
+ Optional('metadata'): dict,
47
+ Optional('image_bytes'): bytes,
48
+ Optional('geo_point'): {'longitude': float, 'latitude': float, 'geo_limit': int},
49
+ Optional("concepts"): And(
50
+ list, lambda x: all(concept_schema.is_valid(item) and len(item) > 0 for item in x)
51
+ ),
52
+ ## input filters
53
+ Optional('input_types'): And(
54
+ list,
55
+ lambda input_types: all(
56
+ input_type in ('image', 'video', 'text', 'audio') for input_type in input_types
57
+ ),
58
+ ),
59
+ Optional('input_dataset_ids'): list,
60
+ Optional('input_status_code'): int,
61
+ }
62
+ )
60
63
 
61
- ## input filters
62
- Optional('input_types'):
63
- And(list, lambda input_types: all(input_type in ('image', 'video', 'text', 'audio')
64
- for input_type in input_types)),
65
- Optional('input_dataset_ids'):
66
- list,
67
- Optional('input_status_code'):
68
- int,
69
- })
70
-
71
- # Schema for rank and filter args
72
- return Schema([rank_filter_item_schema])
64
+ # Schema for rank and filter args
65
+ return Schema([rank_filter_item_schema])
clarifai/urls/helper.py CHANGED
@@ -2,119 +2,142 @@ from urllib.parse import urlparse
2
2
 
3
3
 
4
4
  class ClarifaiUrlHelper(object):
5
- """Lots of helper functionality for dealing with urls around modules."""
5
+ """Lots of helper functionality for dealing with urls around modules."""
6
6
 
7
- def __init__(self, auth, module_manager_imv_id="module_manager_install"):
8
- """
9
- Args:
10
- auth: a ClarifaiAuthHelper object.
11
- """
12
- self._auth = auth
13
- self._module_manager_imv_id = module_manager_imv_id
7
+ def __init__(self, auth, module_manager_imv_id="module_manager_install"):
8
+ """
9
+ Args:
10
+ auth: a ClarifaiAuthHelper object.
11
+ """
12
+ self._auth = auth
13
+ self._module_manager_imv_id = module_manager_imv_id
14
14
 
15
- @property
16
- def auth(self):
17
- return self._auth
15
+ @property
16
+ def auth(self):
17
+ return self._auth
18
18
 
19
- def module_ui_url(self, user_id, app_id, module_id, module_version_id):
20
- """This is the path to the module in community."""
21
- return "%s/%s/%s/modules/%s/versions/%s" % (
22
- self.auth.ui,
23
- user_id,
24
- app_id,
25
- module_id,
26
- module_version_id,
27
- )
19
+ def module_ui_url(self, user_id, app_id, module_id, module_version_id):
20
+ """This is the path to the module in community."""
21
+ return "%s/%s/%s/modules/%s/versions/%s" % (
22
+ self.auth.ui,
23
+ user_id,
24
+ app_id,
25
+ module_id,
26
+ module_version_id,
27
+ )
28
28
 
29
- def module_install_ui_url(self, dest_user_id, dest_app_id, module_url):
30
- """This is a url that allows for installation of the module from the community at 'module_url'
29
+ def module_install_ui_url(self, dest_user_id, dest_app_id, module_url):
30
+ """This is a url that allows for installation of the module from the community at 'module_url'
31
31
  into the destination app_id of the destination user_id."""
32
- return ("%s/%s/%s/installed_module_versions/%s/install?install=%s" %
33
- (self.auth.ui, dest_user_id, dest_app_id, self._module_manager_imv_id, module_url))
32
+ return "%s/%s/%s/installed_module_versions/%s/install?install=%s" % (
33
+ self.auth.ui,
34
+ dest_user_id,
35
+ dest_app_id,
36
+ self._module_manager_imv_id,
37
+ module_url,
38
+ )
34
39
 
35
- def imv_ui_url(self, dest_user_id, dest_app_id, imv_id):
36
- return ("%s/%s/%s/installed_module_versions/%s" % (self.auth.ui, dest_user_id, dest_app_id,
37
- imv_id))
40
+ def imv_ui_url(self, dest_user_id, dest_app_id, imv_id):
41
+ return "%s/%s/%s/installed_module_versions/%s" % (
42
+ self.auth.ui,
43
+ dest_user_id,
44
+ dest_app_id,
45
+ imv_id,
46
+ )
38
47
 
39
- def clarifai_url(self, user_id, app_id, resource_type, resource_id, version_id: str = None):
40
- """This is the path to the resource in community.
48
+ def clarifai_url(self, user_id, app_id, resource_type, resource_id, version_id: str = None):
49
+ """This is the path to the resource in community.
41
50
 
42
- Args:
43
- user_id: the author of the resource.
44
- app_id: the author's app the resource was created in.
45
- resource_type: the type of resource. One of "modules", "models", "concepts", "inputs", "workflows", "tasks", "installed_module_versions"
46
- resource_id: the resource ID
47
- version_id: the version of the resource.
48
- """
49
- if resource_type not in [
50
- "modules", "models", "concepts", "inputs", "workflows", "tasks",
51
- "installed_module_versions"
52
- ]:
53
- raise ValueError(
54
- "resource_type must be one of modules, models, concepts, inputs, workflows, tasks, installed_module_versions but was %s"
55
- % resource_type)
56
- if version_id is None:
57
- return "%s/%s/%s/%s/%s" % (self.auth.ui, user_id, app_id, resource_type, resource_id)
58
- return "%s/%s/%s/%s/%s/versions/%s" % (self.auth.ui, user_id, app_id, resource_type,
59
- resource_id, version_id)
51
+ Args:
52
+ user_id: the author of the resource.
53
+ app_id: the author's app the resource was created in.
54
+ resource_type: the type of resource. One of "modules", "models", "concepts", "inputs", "workflows", "tasks", "installed_module_versions"
55
+ resource_id: the resource ID
56
+ version_id: the version of the resource.
57
+ """
58
+ if resource_type not in [
59
+ "modules",
60
+ "models",
61
+ "concepts",
62
+ "inputs",
63
+ "workflows",
64
+ "tasks",
65
+ "installed_module_versions",
66
+ ]:
67
+ raise ValueError(
68
+ "resource_type must be one of modules, models, concepts, inputs, workflows, tasks, installed_module_versions but was %s"
69
+ % resource_type
70
+ )
71
+ if version_id is None:
72
+ return "%s/%s/%s/%s/%s" % (self.auth.ui, user_id, app_id, resource_type, resource_id)
73
+ return "%s/%s/%s/%s/%s/versions/%s" % (
74
+ self.auth.ui,
75
+ user_id,
76
+ app_id,
77
+ resource_type,
78
+ resource_id,
79
+ version_id,
80
+ )
60
81
 
61
- @classmethod
62
- def split_clarifai_app_url(cls, url):
63
- """
64
- clarifai.com uses fully qualified urls to resources.
65
- They are in the format of:
66
- https://clarifai.com/{user_id}/{app_id}/
67
- """
68
- url = url.replace("https://", "", 1).replace("http://", "", 1)
69
- o = urlparse(url)
70
- path = o.path
71
- path = path.lstrip("/")
72
- parts = path.split("/")
73
- if len(parts) != 3:
74
- raise ValueError(
75
- f"Provided url must have 2 parts after the domain name. The current parts are: {parts}")
76
- return tuple(parts[1:])
82
+ @classmethod
83
+ def split_clarifai_app_url(cls, url):
84
+ """
85
+ clarifai.com uses fully qualified urls to resources.
86
+ They are in the format of:
87
+ https://clarifai.com/{user_id}/{app_id}/
88
+ """
89
+ url = url.replace("https://", "", 1).replace("http://", "", 1)
90
+ o = urlparse(url)
91
+ path = o.path
92
+ path = path.lstrip("/")
93
+ parts = path.split("/")
94
+ if len(parts) != 3:
95
+ raise ValueError(
96
+ f"Provided url must have 2 parts after the domain name. The current parts are: {parts}"
97
+ )
98
+ return tuple(parts[1:])
77
99
 
78
- @classmethod
79
- def split_clarifai_url(cls, url):
80
- """
81
- clarifai.com uses fully qualified urls to resources.
82
- They are in the format of:
83
- https://clarifai.com/{user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}
84
- Those last two are optional.
100
+ @classmethod
101
+ def split_clarifai_url(cls, url):
102
+ """
103
+ clarifai.com uses fully qualified urls to resources.
104
+ They are in the format of:
105
+ https://clarifai.com/{user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}
106
+ Those last two are optional.
85
107
 
86
- """
87
- url = url.replace("https://", "", 1).replace("http://", "", 1)
88
- o = urlparse(url)
89
- path = o.path
90
- path = path.lstrip("/")
91
- parts = path.split("/")
92
- if len(parts) != 5 and len(parts) != 7:
93
- raise ValueError(
94
- "Provided url must have 4 or 6 parts after the domain name. These are: {user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}"
95
- )
96
- user_id, app_id, resource_type, resource_id = parts[1:5]
97
- if len(parts) == 7:
98
- resource_version_id = parts[6]
99
- else:
100
- resource_version_id = None
101
- return user_id, app_id, resource_type, resource_id, resource_version_id
108
+ """
109
+ url = url.replace("https://", "", 1).replace("http://", "", 1)
110
+ o = urlparse(url)
111
+ path = o.path
112
+ path = path.lstrip("/")
113
+ parts = path.split("/")
114
+ if len(parts) != 5 and len(parts) != 7:
115
+ raise ValueError(
116
+ "Provided url must have 4 or 6 parts after the domain name. These are: {user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}"
117
+ )
118
+ user_id, app_id, resource_type, resource_id = parts[1:5]
119
+ if len(parts) == 7:
120
+ resource_version_id = parts[6]
121
+ else:
122
+ resource_version_id = None
123
+ return user_id, app_id, resource_type, resource_id, resource_version_id
102
124
 
103
- @classmethod
104
- def split_module_ui_url(cls, install):
105
- """Takes in a path like https://clarifai.com/zeiler/app/modules/module1/versions/2 to split it apart into it's IDs.
125
+ @classmethod
126
+ def split_module_ui_url(cls, install):
127
+ """Takes in a path like https://clarifai.com/zeiler/app/modules/module1/versions/2 to split it apart into it's IDs.
106
128
 
107
- Returns:
108
- user_id: the author of the module.
109
- app_id: the author's app the module was created in.
110
- module_id: the module ID
111
- module_version_id: the version of the module.
112
- """
113
- user_id, app_id, resource_type, resource_id, resource_version_id = cls.split_clarifai_url(
114
- install)
129
+ Returns:
130
+ user_id: the author of the module.
131
+ app_id: the author's app the module was created in.
132
+ module_id: the module ID
133
+ module_version_id: the version of the module.
134
+ """
135
+ user_id, app_id, resource_type, resource_id, resource_version_id = cls.split_clarifai_url(
136
+ install
137
+ )
115
138
 
116
- if resource_type != "modules" or resource_version_id is None:
117
- raise ValueError(
118
- "Provided install url must have 6 parts after the domain name. These are {user_id}/{app_id}/modules/{module_id}/versions/{module_version_id}"
119
- )
120
- return user_id, app_id, resource_id, resource_version_id
139
+ if resource_type != "modules" or resource_version_id is None:
140
+ raise ValueError(
141
+ "Provided install url must have 6 parts after the domain name. These are {user_id}/{app_id}/modules/{module_id}/versions/{module_version_id}"
142
+ )
143
+ return user_id, app_id, resource_id, resource_version_id