wizata-dsapi 1.3.42__py3-none-any.whl → 1.3.44__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.
@@ -76,6 +76,12 @@ _registry = {
76
76
  "cloud_dsapi": ['lists', 'get_by_id', 'create', 'update', 'delete', 'search'],
77
77
  "cloud_context": ['get_by_id', 'create', 'update', 'delete', 'search']
78
78
  },
79
+ "models":
80
+ {
81
+ "class": ModelInfo,
82
+ "cloud_dsapi": ['download_model', 'download_file' , 'upload_model' , 'upload_file'],
83
+ "cloud_context": ['download_model' , 'download_file' , 'upload_model' , 'upload_file']
84
+ },
79
85
  "pipelines":
80
86
  {
81
87
  "class": Pipeline,
@@ -2,6 +2,7 @@ import uuid
2
2
  from .solution_component import SolutionComponent
3
3
  from .paged_query_result import PagedQueryResult
4
4
  from .pipeline import AlertType
5
+ from .mlmodel import ModelInfo, ModelFile
5
6
  from datetime import datetime
6
7
  import pandas
7
8
 
@@ -276,3 +277,58 @@ class ApiInterface:
276
277
  :param list cc: for email only - cc recipients list.
277
278
  """
278
279
  pass
280
+
281
+ def download_model(self, identifier: str) -> ModelInfo:
282
+ """
283
+ download a model image directly from the repository, auto-select alias if necessary.
284
+ :param identifier: exact identifier including alias of the model or no alias to auto-select active version.
285
+ :return: ModelInfo with trained_model loaded, extra file must be downloaded separately.
286
+ """
287
+ pass
288
+
289
+ def download_file(self,
290
+ model: ModelInfo = None,
291
+ file: ModelFile = None,
292
+ identifier: str = None,
293
+ path: str = None):
294
+ """
295
+ download a model extra file from the repository.
296
+ :param model: model (ModelInfo), alternatively can use identifier
297
+ :param file: file (ModelFile), alternatively can use path
298
+ :param identifier: identifier including alias of the model.
299
+ :param path: path name of the file including the extension.
300
+ :return: bytes content.
301
+ """
302
+ pass
303
+
304
+ def upload_file(self,
305
+ content,
306
+ model: ModelInfo = None,
307
+ file: ModelFile = None,
308
+ identifier: str = None,
309
+ path: str = None
310
+ ):
311
+ """
312
+ upload a model extra file to the repository.
313
+ please use upload_model for a trained_model
314
+ :param content: the bytes content of the file.
315
+ :param model: model (ModelInfo), alternatively can use identifier
316
+ :param file: file (ModelFile), alternatively can use path
317
+ :param identifier: identifier including alias of the model.
318
+ :param path: path name of the file including the extension.
319
+ :return: bytes content.
320
+ """
321
+ pass
322
+
323
+ def upload_model(self,
324
+ model_info: ModelInfo,
325
+ bytes_content=None):
326
+ """
327
+ upload a model within the model repository.
328
+ - by default use model_info.trained_model and convert it to a pickle
329
+ - for already torch or pickle please pass the bytes_content
330
+ - model_info.file_format must be set properly to 'pkl' or 'pt'
331
+ :param model_info: model info, with at least key (+twin, +property, +alias) and trained_model.
332
+ :param bytes_content: bytes[] of your torch or pickle model.
333
+ """
334
+ pass
wizata_dsapi/context.py CHANGED
@@ -1,7 +1,11 @@
1
1
  import uuid
2
2
  import pandas
3
+ import numpy as np
4
+ import io
5
+ import json
6
+ import pickle
3
7
 
4
- from .mlmodel import ModelInfo
8
+ from .mlmodel import ModelInfo, ModelFile
5
9
  from .plot import Plot
6
10
  from .ilogger import ILogger
7
11
  from .api_interface import ApiInterface
@@ -188,22 +192,40 @@ class Context(ILogger):
188
192
  if self.__new_plot is not None:
189
193
  return self.__new_plot.figure
190
194
 
191
- def set_model(self, trained_model, input_columns, output_columns=None, has_anomalies=False, scaler=None):
195
+ def set_model(self,
196
+ trained_model,
197
+ **kwargs):
192
198
  """
193
199
  set model to be added to the context.
194
200
  :param trained_model: Trained Model to be stored as a pickled object.
195
- :param list input_columns: List of str defining input columns to call the model (df.columns)
196
- :param list output_columns: List of output columns - Optional as can be detected automatically during validation.
197
- :param bool has_anomalies: False by default, define if the model set anomalies
198
- :param scaler: Scaler to be stored if necessary.
199
- :return: ML Model object prepared.
201
+ :param scaler: Scaler extra file to be stored.
202
+ :return: ModelInfo object
200
203
  """
201
204
  model_info = ModelInfo(key="undefined")
202
205
  model_info.trained_model = trained_model
206
+
207
+ scaler = kwargs.pop("scaler", None)
203
208
  model_info.scaler = scaler
204
- model_info.input_columns = input_columns
205
- model_info.output_columns = output_columns
206
- model_info.has_anomalies = has_anomalies
209
+
210
+ for key, value in kwargs.items():
211
+
212
+ if isinstance(value, (pandas.Index, pandas.Series, np.ndarray)):
213
+ content = json.dumps(value.tolist()).encode('utf-8')
214
+ filename = f"{key}.json"
215
+ elif isinstance(value, (dict, list)):
216
+ content = json.dumps(value).encode('utf-8')
217
+ filename = f"{key}.json"
218
+ else:
219
+ content = pickle.dumps(value)
220
+ filename = f"{key}.pkl"
221
+
222
+ model_info.add_file(
223
+ file=ModelFile(
224
+ content=io.BytesIO(content),
225
+ path=filename
226
+ )
227
+ )
228
+
207
229
  self.__new_model = model_info
208
230
  return model_info
209
231
 
wizata_dsapi/mlmodel.py CHANGED
@@ -122,7 +122,7 @@ class ModelInfo:
122
122
  """
123
123
 
124
124
  def __init__(self,
125
- key: str,
125
+ key: str = None,
126
126
  twin_hardware_id: str = None,
127
127
  property_value: str = None,
128
128
  alias: str = None,
wizata_dsapi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.3.42"
1
+ __version__ = "1.3.44"
@@ -13,6 +13,7 @@ import plotly
13
13
  import msal
14
14
  import os
15
15
  import types
16
+
16
17
  import wizata_dsapi
17
18
  import urllib.parse
18
19
  import base64
@@ -26,7 +27,7 @@ from .api_dto import ApiDto, VarType, ApiDtoInterface
26
27
  from .business_label import BusinessLabel
27
28
  from .plot import Plot
28
29
  from .request import Request
29
- from .mlmodel import ModelInfo, ModelList
30
+ from .mlmodel import ModelInfo, ModelList, ModelFile
30
31
  from .experiment import Experiment
31
32
  from .script import Script
32
33
  from .execution import Execution, ExecutionStatus
@@ -1936,6 +1937,100 @@ class WizataDSAPIClient(ApiInterface, ApiDtoInterface):
1936
1937
  image = PipelineImage.loads(pipeline_image_id=pipeline_image_id, g_bytes=response_bytes)
1937
1938
  return image
1938
1939
 
1940
+ def download_model(self, identifier: str) -> ModelInfo:
1941
+ """
1942
+ download a model image directly from the repository, auto-select alias if necessary.
1943
+ :param identifier: exact identifier including alias of the model or no alias to auto-select active version.
1944
+ :return: ModelInfo with trained_model loaded, extra file must be downloaded separately.
1945
+ """
1946
+ response = requests.get(self.__url() + f"models/{identifier}/",
1947
+ headers=self.__header())
1948
+ if response.status_code == 200:
1949
+ model_info = ModelInfo()
1950
+ model_info.from_json(response.json())
1951
+ self.load_model(model_info)
1952
+ return model_info
1953
+ else:
1954
+ self.__raise_error(response)
1955
+
1956
+
1957
+ def download_file(self,
1958
+ model: ModelInfo = None,
1959
+ file: ModelFile = None,
1960
+ identifier: str = None,
1961
+ path: str = None):
1962
+ """
1963
+ download a model extra file from the repository.
1964
+ :param model: model (ModelInfo), alternatively can use identifier
1965
+ :param file: file (ModelFile), alternatively can use path
1966
+ :param identifier: identifier including alias of the model.
1967
+ :param path: path name of the file including the extension.
1968
+ :return: bytes content.
1969
+ """
1970
+
1971
+ if model is None and identifier is None:
1972
+ raise TypeError('model or identifier must be provided')
1973
+
1974
+ if file is None and path is None:
1975
+ raise TypeError('file or path must be provided')
1976
+
1977
+ if identifier is None:
1978
+ identifier = model.identifier(include_alias=True)
1979
+
1980
+ if path is None:
1981
+ path = file.path
1982
+
1983
+ response = requests.get(self.__url() + f"models/{identifier}/files/{path}/",
1984
+ headers=self.__header())
1985
+ if response.status_code == 200:
1986
+ return response.content
1987
+ else:
1988
+ self.__raise_error(response)
1989
+
1990
+
1991
+ def upload_file(self,
1992
+ content,
1993
+ model: ModelInfo = None,
1994
+ file: ModelFile = None,
1995
+ identifier: str = None,
1996
+ path: str = None
1997
+ ):
1998
+ """
1999
+ upload a model extra file to the repository.
2000
+ please use upload_model for a trained_model
2001
+ :param content: the bytes content of the file.
2002
+ :param model: model (ModelInfo), alternatively can use identifier
2003
+ :param file: file (ModelFile), alternatively can use path
2004
+ :param identifier: identifier including alias of the model.
2005
+ :param path: path name of the file including the extension.
2006
+ :return: bytes content.
2007
+ """
2008
+ if path == "trained_model.pkl" or path == "trained_model.pt" or path == "_metadata.json":
2009
+ raise RuntimeError("upload_file cannot be used to upload reserved metadata or the primary trained model")
2010
+
2011
+ if model is None and identifier is None:
2012
+ raise TypeError('model or identifier must be provided')
2013
+
2014
+ if file is None and path is None:
2015
+ raise TypeError('file or path must be provided')
2016
+
2017
+ if identifier is None:
2018
+ identifier = model.identifier(include_alias=True)
2019
+
2020
+ if path is None:
2021
+ path = file.path
2022
+
2023
+ headers = self.__header()
2024
+ headers["Content-Type"] = "application/octet-stream"
2025
+ response = requests.post(self.__url() + f"models/{identifier}/files/{path}",
2026
+ headers=headers,
2027
+ data=content,
2028
+ timeout=60)
2029
+ if response.status_code != 200 and response.status_code != 201:
2030
+ return
2031
+ else:
2032
+ self.__raise_error(response)
2033
+
1939
2034
  def load_model(self, model):
1940
2035
  """
1941
2036
  load a model pickle or torch from the repository ready to be used.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wizata_dsapi
3
- Version: 1.3.42
3
+ Version: 1.3.44
4
4
  Summary: Wizata Data Science Toolkit
5
5
  Author: Wizata S.A.
6
6
  Author-email: info@wizata.com
@@ -1,10 +1,10 @@
1
1
  wizata_dsapi/__init__.py,sha256=aVeizk2zzmAX0TLNG9o7vcmG8KB73XiXw1_qozrJN2w,2072
2
- wizata_dsapi/api_config.py,sha256=6Pnnv62X_QrTUXaa1MtFZeQaqMUJC-9Y5BW7B4gef10,5139
2
+ wizata_dsapi/api_config.py,sha256=lrjUOKnGBYgjSqvXdTf4gEcf-luTSV6DPdo3AbmIExU,5404
3
3
  wizata_dsapi/api_dto.py,sha256=zyzj6-Kcxi59vVAvThfsuq7RLUE2O_FZ3TJ5LpKYPbE,2310
4
- wizata_dsapi/api_interface.py,sha256=DURk-0ey16T8sV5e2Y2G_YybPEusJvZuY0oD5L7AnXo,10903
4
+ wizata_dsapi/api_interface.py,sha256=ju3Wz1e2uOS1_SrSihc0AECkWLRNNGHMhpMhV2L6tjo,13315
5
5
  wizata_dsapi/bucket.py,sha256=Zz9olv-pymikAutGitSuGWrAPiawOTW86JDDHG4ugTc,1150
6
6
  wizata_dsapi/business_label.py,sha256=u0TVfUNfoR9qSv8lzpf6rNjlg3G9xTiz6itefcKfeak,4151
7
- wizata_dsapi/context.py,sha256=NNc9YYkfuchy2nFouVccaoKi6VAxhgLAH-eaRWxNsaQ,11643
7
+ wizata_dsapi/context.py,sha256=U546V_Lf5JXuQMm3_A9bFTJ0xV3hpND2PYVT5sJ7SIA,11928
8
8
  wizata_dsapi/dataframe_toolkit.py,sha256=7D8JrhsFSGXeO3mRAd2e2cLmdjbXRjk04IuaMG8F974,9078
9
9
  wizata_dsapi/datapoint.py,sha256=UUatqzWMwC4ucM6HdeQDWtLS4fGqEsDABCNVmxoP5Hg,14635
10
10
  wizata_dsapi/datastore.py,sha256=BSHZmCSJ679boBA1eCkaWGJCy1CUeipKKGt2jDHzdVo,2663
@@ -16,7 +16,7 @@ wizata_dsapi/experiment.py,sha256=QYQ1CJ-MTWsXq08xYbm5sAp95dRxbPOmGDgaAOoBMDQ,46
16
16
  wizata_dsapi/group_system.py,sha256=6rUKe0_J3YWACysyBlzuw_TEpKNXgLOMxhpWsNxOzwY,1708
17
17
  wizata_dsapi/ilogger.py,sha256=iYnID-Z-qrYhie26C43404aIuU4_tHSKXbDeQIdo82Q,807
18
18
  wizata_dsapi/insight.py,sha256=ABFZ04DqYxxzqAEfU1tzlTZqqrigM-zN-8Lbetko3g0,6468
19
- wizata_dsapi/mlmodel.py,sha256=Bdx4bZdrvcR4IZyVH1_yDtU94qe4M8LOFK7I0QqdknQ,24541
19
+ wizata_dsapi/mlmodel.py,sha256=m-mVF-o632nbs_IJ2H73KM2hfcRwnUGFmPt5oVrU8Ws,24548
20
20
  wizata_dsapi/model_toolkit.py,sha256=UNyw5CFSgZeXydQFsiDIRTjoMeqIsdyIIuiwumLW5bA,1574
21
21
  wizata_dsapi/paged_query_result.py,sha256=0Iyt2Kd4tvrfthhT-tk9EmSERsbJTaPNON2euHcBn6k,1150
22
22
  wizata_dsapi/pipeline.py,sha256=CtB6-HwJ2OtqUIbwAVTcawLmvYfudgIwGiPZARwTobM,31778
@@ -31,10 +31,10 @@ wizata_dsapi/template.py,sha256=wtCRKKk3PchH4RrNgNYlEF_9C6bzZwKIeLyEvgv6Fdo,1370
31
31
  wizata_dsapi/trigger.py,sha256=w3BZYP-L3SUwvaT0oCTanh_Ewn57peZvlt7vxzHv9J8,5129
32
32
  wizata_dsapi/twin.py,sha256=S0DUzQf1smZXZTdXpXZPtkZYCfKIhw53EecCnsl9i4Q,11017
33
33
  wizata_dsapi/twinregistration.py,sha256=Mi6-YuwroiEXc0c1hgrOaphh4hNVoHupxOnXedVtJtE,13377
34
- wizata_dsapi/version.py,sha256=oDD-gNOpF2G3g0V7E6KiCHvmVS1vd65OXRkXno_Seug,23
34
+ wizata_dsapi/version.py,sha256=yfbEU3o2fygwnHirL_qJkT1waQWT3nPKCejVacR9wrU,23
35
35
  wizata_dsapi/wizard_function.py,sha256=RbM7W7Gf-6Rhp_1dU9DBYkHaciknGAGvuAndhAS_vyo,942
36
36
  wizata_dsapi/wizard_request.py,sha256=v6BaqKLKvTWmUSo0_gda9FabAQz5x_-GOH1Av50GzFo,3762
37
- wizata_dsapi/wizata_dsapi_client.py,sha256=FbEmlKDDQPCqe1rDfpAvXBWfkVXcnbtKeI592D39ucw,80570
37
+ wizata_dsapi/wizata_dsapi_client.py,sha256=KycD4Rv2yoqCx7kugTUfw_4Z064TYTUvEfyKjzkQOjc,84395
38
38
  wizata_dsapi/words.py,sha256=tV8CqzCqODZCV7PgBxBF5exBxeF_ya9t5DiUy-cg6Sg,1535
39
39
  wizata_dsapi/models/__init__.py,sha256=O5PHqw8lKILw4apO-MfDxPz73wK0vADD9y3xjuzX7Tw,104
40
40
  wizata_dsapi/models/common.py,sha256=1dTqE80-mFJnUwEdNlJdhJzfZ2N5Kp8Nb3LQ8uwPtLc,3808
@@ -42,8 +42,8 @@ wizata_dsapi/plots/__init__.py,sha256=qgnSFqrjOPur-807M8uh5awIfjM1ZHXUXcAqHc-r2l
42
42
  wizata_dsapi/plots/common.py,sha256=jdPsJqLHBwSKc6dX83BSGPqSRxzIVNHSYO5yI_8sjGk,6568
43
43
  wizata_dsapi/scripts/__init__.py,sha256=hAxiETSQf0qOHde1si1tEAJU48seqEgHrchCzS2-LvQ,80
44
44
  wizata_dsapi/scripts/common.py,sha256=efwq-Rd0lvYljIs3gSFz9izogBD7asOU2cTK-IvHTkM,4244
45
- wizata_dsapi-1.3.42.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
46
- wizata_dsapi-1.3.42.dist-info/METADATA,sha256=BSG1K5kI-ImyB0u_ScxiCvw_PhNQ7Ex-hmDFiwKaMZ8,5651
47
- wizata_dsapi-1.3.42.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
- wizata_dsapi-1.3.42.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
49
- wizata_dsapi-1.3.42.dist-info/RECORD,,
45
+ wizata_dsapi-1.3.44.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
46
+ wizata_dsapi-1.3.44.dist-info/METADATA,sha256=i_n4AhQNWvPwDhReZHuOrcZJQRbjVDA8UNWmarv2JNU,5651
47
+ wizata_dsapi-1.3.44.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
+ wizata_dsapi-1.3.44.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
49
+ wizata_dsapi-1.3.44.dist-info/RECORD,,