clarifai 10.5.3__py3-none-any.whl → 10.7.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 (91) hide show
  1. clarifai/__init__.py +1 -0
  2. clarifai/client/app.py +26 -0
  3. clarifai/client/base.py +5 -0
  4. clarifai/client/input.py +116 -45
  5. clarifai/client/search.py +28 -42
  6. clarifai/client/user.py +33 -0
  7. clarifai/constants/dataset.py +2 -0
  8. clarifai/datasets/export/inputs_annotations.py +6 -2
  9. clarifai/rag/rag.py +8 -0
  10. clarifai/utils/constants.py +1 -0
  11. clarifai/utils/logging.py +3 -1
  12. clarifai/versions.py +2 -1
  13. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/METADATA +2 -2
  14. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/RECORD +18 -91
  15. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/WHEEL +1 -1
  16. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  17. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  18. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  19. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  20. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  21. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  22. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  23. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  24. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  25. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  26. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  27. clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
  28. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  29. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  30. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  31. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  32. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  33. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  34. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  35. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  36. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  37. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  38. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  39. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  40. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  41. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  42. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  43. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  44. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  45. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  46. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  47. clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
  48. clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
  49. clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
  50. clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  51. clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
  52. clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
  53. clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
  54. clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
  55. clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
  56. clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
  57. clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
  58. clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
  59. clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
  60. clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
  61. clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
  62. clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
  63. clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
  64. clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
  65. clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
  66. clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
  67. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  68. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  69. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  70. clarifai/runners/deepgram_live_transcribe.py +0 -98
  71. clarifai/runners/deepgram_live_transcribe.py~ +0 -98
  72. clarifai/runners/deepgram_runner.py +0 -131
  73. clarifai/runners/deepgram_runner.py~ +0 -130
  74. clarifai/runners/example_llama2.py~ +0 -72
  75. clarifai/runners/matt_example.py +0 -89
  76. clarifai/runners/matt_example.py~ +0 -87
  77. clarifai/runners/matt_llm_example.py +0 -129
  78. clarifai/runners/matt_llm_example.py~ +0 -128
  79. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  80. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  81. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  82. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  83. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  84. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  85. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  86. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  87. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  88. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  89. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/LICENSE +0 -0
  90. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/entry_points.txt +0 -0
  91. {clarifai-10.5.3.dist-info → clarifai-10.7.0.dist-info}/top_level.txt +0 -0
@@ -1,128 +0,0 @@
1
- from clarifai_grpc.grpc.api import resources_pb2, service_pb2
2
- from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
3
- from collections.abc import Iterator
4
- from google.protobuf import json_format
5
-
6
- from clarifai.client.runner import Runner
7
- import time
8
- from threading import Thread
9
-
10
- import grpc
11
- import requests
12
-
13
- from transformers import (AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer)
14
-
15
- model_name_or_path = "TheBloke/Llama-2-7B-chat-GPTQ"
16
- model_basename = "model"
17
- use_triton = False
18
- tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
19
- model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map='auto')
20
- streamer = TextIteratorStreamer(tokenizer)
21
- print("Model loaded")
22
-
23
-
24
- class MyRunner(Runner):
25
- """A custom runner that adds "Hello World" to the end of the text and replaces the domain of the
26
- image URL as an example.
27
- """
28
-
29
- def run_input(self, input: resources_pb2.Input, output_info: resources_pb2.OutputInfo,
30
- **kwargs) -> resources_pb2.Output:
31
- """This is the method that will be called when the runner is run. It takes in an input and
32
- returns an output.
33
- """
34
-
35
- output = resources_pb2.Output()
36
-
37
- data = input.data
38
-
39
- # Optional use of output_info
40
- params_dict = {}
41
- if "params" in output_info:
42
- params_dict = output_info["params"]
43
-
44
- if data.text.raw != "":
45
- output.data.text.raw = data.text.raw + "Hello World" + params_dict.get(
46
- "hello", "") + kwargs.get("extra", "")
47
- if data.image.url != "":
48
- output.data.text.raw = data.image.url.replace("samples.clarifai.com",
49
- "newdomain.com" + params_dict.get("domain",))
50
- return output
51
-
52
- def generate(self, request: service_pb2.PostModelOutputsRequest
53
- ) -> Iterator[service_pb2.MultiOutputResponse]:
54
- """Example yielding a whole batch of streamed stuff back.
55
- """
56
-
57
- output_info = None
58
- if request.model.model_version.id != "":
59
- output_info = json_format.MessageToDict(
60
- request.model.model_version.output_info, preserving_proto_field_name=True)
61
-
62
- for inp in request.inputs:
63
- data = inp.data
64
- print('start')
65
- if data.text.raw != "":
66
- input_text = data.text.raw
67
- elif data.text.url != "":
68
- input_text = str(requests.get(data.text.url).text)
69
- else:
70
- raise Exception("Need to include data.text.raw or data.text.url in your inputs.")
71
-
72
- st = time.time()
73
- max_tokens = 1024
74
- # # Method 1
75
- inputs = tokenizer(input_text, return_tensors='pt') #.input_ids.cuda()
76
- generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_tokens)
77
- thread = Thread(target=model.generate, kwargs=generation_kwargs)
78
- thread.start()
79
- times = []
80
- st = time.time()
81
- for new_text in streamer:
82
- duration = time.time() - st
83
- st = time.time()
84
- print(f"Duration: {duration}")
85
- times.append(duration)
86
- # for new_text in ["hello", "world", "i'm", "streaming"]:
87
-
88
- # out = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=max_tokens)
89
- # out_text = tokenizer.decode(out[0], skip_special_tokens=True)
90
- # output.data.text.raw = out_text.replace(input_text, '')
91
-
92
- # # # Method 2
93
- # print('before')
94
- # pipe = pipeline(
95
- # "text-generation",
96
- # model=model,
97
- # tokenizer=tokenizer,
98
- # streamer=streamer,
99
- # max_new_tokens=max_tokens,
100
- # temperature=0.7,
101
- # top_p=0.95,
102
- # repetition_penalty=1.15,
103
- # return_full_text=False)
104
- # print('pipe')
105
- # a = pipe(input_text)
106
- # print(a)
107
- print("Posting: ", new_text)
108
- output = resources_pb2.Output()
109
- output.data.text.raw = new_text
110
- result = service_pb2.MultiOutputResponse(
111
- status=status_pb2.Status(
112
- code=status_code_pb2.SUCCESS,
113
- description="Success",
114
- ),
115
- outputs=[output],
116
- )
117
- yield result
118
- print(f"Total time: {time.time() - st}")
119
- print(f"Average time: {sum(times) / len(times)}")
120
-
121
-
122
- if __name__ == '__main__':
123
- # Make sure you set these env vars before running the example.
124
- # CLARIFAI_PAT
125
- # CLARIFAI_USER_ID
126
-
127
- # You need to first create a runner in the Clarifai API and then use the ID here.
128
- MyRunner(runner_id="matt-test-runner", base_url="http://q6:32013", num_parallel_polls=1).start()