xplainable-client 1.2.1.post3__tar.gz → 1.2.2__tar.gz
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.
- xplainable_client-1.2.2/PKG-INFO +140 -0
- xplainable_client-1.2.2/README.md +118 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/pyproject.toml +3 -3
- xplainable_client-1.2.2/xplainable_client/client/__init__.py +33 -0
- xplainable_client-1.2.2/xplainable_client/client/_client_cog_base.py +7 -0
- xplainable_client-1.2.2/xplainable_client/client/_collections.py +213 -0
- xplainable_client-1.2.2/xplainable_client/client/_datasets.py +51 -0
- xplainable_client-1.2.2/xplainable_client/client/_deployments.py +390 -0
- xplainable_client-1.2.2/xplainable_client/client/_gpt.py +36 -0
- xplainable_client-1.2.2/xplainable_client/client/_inference.py +29 -0
- xplainable_client-1.2.2/xplainable_client/client/_misc.py +210 -0
- xplainable_client-1.2.2/xplainable_client/client/_models.py +494 -0
- xplainable_client-1.2.2/xplainable_client/client/_preprocessing.py +250 -0
- xplainable_client-1.2.2/xplainable_client/client/_session.py +108 -0
- xplainable_client-1.2.2/xplainable_client/models/ebm.py +111 -0
- xplainable_client-1.2.2/xplainable_client.egg-info/PKG-INFO +140 -0
- xplainable_client-1.2.2/xplainable_client.egg-info/SOURCES.txt +25 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client.egg-info/requires.txt +2 -2
- xplainable-client-1.2.1.post3/PKG-INFO +0 -362
- xplainable-client-1.2.1.post3/README.md +0 -340
- xplainable-client-1.2.1.post3/xplainable_client/__init__.py +0 -2
- xplainable-client-1.2.1.post3/xplainable_client/client.py +0 -929
- xplainable-client-1.2.1.post3/xplainable_client/datasets.py +0 -32
- xplainable-client-1.2.1.post3/xplainable_client.egg-info/PKG-INFO +0 -362
- xplainable-client-1.2.1.post3/xplainable_client.egg-info/SOURCES.txt +0 -16
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/setup.cfg +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/__init__.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/encoders.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/exceptions.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/helpers.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/metrics.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client/utils/model_parsers.py +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client.egg-info/dependency_links.txt +0 -0
- {xplainable-client-1.2.1.post3 → xplainable_client-1.2.2}/xplainable_client.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: xplainable-client
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: The client for persisting and deploying models to Xplainable cloud.
|
|
5
|
+
Author-email: xplainable pty ltd <contact@xplainable.io>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: ipywidgets==8.0.6
|
|
14
|
+
Requires-Dist: numpy>=1.20.3
|
|
15
|
+
Requires-Dist: pandas<=1.9.0,>=1.5.2
|
|
16
|
+
Requires-Dist: pyperclip==1.8.2
|
|
17
|
+
Requires-Dist: Requests==2.31.0
|
|
18
|
+
Requires-Dist: scikit_learn
|
|
19
|
+
Requires-Dist: setuptools
|
|
20
|
+
Requires-Dist: urllib3==2.2.0
|
|
21
|
+
Requires-Dist: xplainable
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<div align="center">
|
|
25
|
+
<img src="https://raw.githubusercontent.com/xplainable/xplainable/main/docs/assets/logo/xplainable-logo.png">
|
|
26
|
+
<h1 align="center">xplainable</h1>
|
|
27
|
+
<h3 align="center">Real-time explainable machine learning for business optimisation</h3>
|
|
28
|
+
|
|
29
|
+
**Xplainable** makes tabular machine learning transparent, fair, and actionable.
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
## Why Was Xplainable Created?
|
|
33
|
+
In machine learning, there has long been a trade-off between accuracy and explainability. This drawback has led to the creation of explainable ML libraries such as [Shap](https://github.com/slundberg/shap) and [Lime](https://github.com/marcotcr/lime) which make estimations of model decision processes. These can be incredibly time-expensive and often present steep learning curves making them challenging to implement effectively in production environments.
|
|
34
|
+
|
|
35
|
+
To solve this problem, we created `xplainable`. **xplainable** presents a suite of novel machine learning algorithms specifically designed to match the performance of popular black box models like [XGBoost](https://github.com/dmlc/xgboost) and [LightGBM](https://github.com/microsoft/LightGBM) while providing complete transparency, all in real-time.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Xplainable Cloud
|
|
39
|
+
This Python package is free and open-source. To add more value to data teams within organisations, we also created Xplainable Cloud that brings your models to a collaborative environment.
|
|
40
|
+
|
|
41
|
+
### Preprocessing with Xplainable Cloud
|
|
42
|
+
Before modeling, it's essential to preprocess your data. Xplainable Cloud facilitates this process by allowing you to create and manage preprocessors in the cloud.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import xplainable as xp
|
|
47
|
+
import os
|
|
48
|
+
from xplainable_client import Client
|
|
49
|
+
|
|
50
|
+
#Initialising the client
|
|
51
|
+
XClient = Client(api_key=os.environ['XP_API_KEY'])
|
|
52
|
+
|
|
53
|
+
#Creating a Preprocessor ID
|
|
54
|
+
preprocessor_id = XClient.create_preprocessor_id(
|
|
55
|
+
preprocessor_name="Preprocessor Name",
|
|
56
|
+
preprocessor_description="Preprocessor Description",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
#Creating a Preprocessor Version
|
|
60
|
+
preprocessor_version = XClient.create_preprocessor_version(
|
|
61
|
+
preprocessor_id, #preprocessor_id,
|
|
62
|
+
pipeline, # <-- Pass the pipeline
|
|
63
|
+
df # <-- Pass the raw dataframe
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
#Loading the Preprocessor Client
|
|
67
|
+
pp_cloud = XClient.load_preprocessor(
|
|
68
|
+
preprocessor_id,
|
|
69
|
+
preprocessor_version["version_id"],
|
|
70
|
+
gui_object=False # Set to true to load the GUI object, keep as False for pipeline
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Modelling with Xplainable Cloud
|
|
75
|
+
|
|
76
|
+
After preprocessing, the next step is to create and train your model. Xplainable Cloud supports model versioning and ID creation to streamline this process.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
|
|
80
|
+
#Creating a Model Id
|
|
81
|
+
model_id = XClient.create_model_id(
|
|
82
|
+
model,
|
|
83
|
+
model_name="Model Name",
|
|
84
|
+
model_description='Model Description'
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
#Creating a Model Version
|
|
88
|
+
version_id = XClient.create_model_version(
|
|
89
|
+
model,
|
|
90
|
+
model_id,
|
|
91
|
+
X_train,
|
|
92
|
+
y_train
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Deployments with Xplainable Cloud
|
|
98
|
+
Once your model is ready, deploying it is straightforward with Xplainable Cloud. You can deploy, activate, and manage API keys for your model deployment keys within your IDE or environment.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
#Creating a Model Deployment
|
|
102
|
+
deployment = XClient.deploy(
|
|
103
|
+
hostname="https://inference.xplainable.io",
|
|
104
|
+
model_id=model_id,
|
|
105
|
+
version_id=version_id
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
#Activating the Deployment
|
|
109
|
+
XClient.activate_deployment(deployment['deployment_id'])
|
|
110
|
+
|
|
111
|
+
#Generating an API Key
|
|
112
|
+
deploy_key = XClient.generate_deploy_key(
|
|
113
|
+
'API Key Name',
|
|
114
|
+
deployment['deployment_id'],
|
|
115
|
+
7 #-> Days until expiration
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
#Hitting the endpoint
|
|
119
|
+
response = requests.post(
|
|
120
|
+
url="https://inference.xplainable.io/v1/predict",
|
|
121
|
+
headers={'api_key': deploy_key['deploy_key']},
|
|
122
|
+
json=body
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
#Obtaining the value response
|
|
126
|
+
value = response.json()
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
<div align="center">
|
|
130
|
+
<br></br>
|
|
131
|
+
<br></br>
|
|
132
|
+
Thanks for trying xplainable!
|
|
133
|
+
<br></br>
|
|
134
|
+
<strong>Made with ❤️ in Australia</strong>
|
|
135
|
+
<br></br>
|
|
136
|
+
<hr>
|
|
137
|
+
© copyright xplainable pty ltd
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
|
|
2
|
+
<div align="center">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/xplainable/xplainable/main/docs/assets/logo/xplainable-logo.png">
|
|
4
|
+
<h1 align="center">xplainable</h1>
|
|
5
|
+
<h3 align="center">Real-time explainable machine learning for business optimisation</h3>
|
|
6
|
+
|
|
7
|
+
**Xplainable** makes tabular machine learning transparent, fair, and actionable.
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
## Why Was Xplainable Created?
|
|
11
|
+
In machine learning, there has long been a trade-off between accuracy and explainability. This drawback has led to the creation of explainable ML libraries such as [Shap](https://github.com/slundberg/shap) and [Lime](https://github.com/marcotcr/lime) which make estimations of model decision processes. These can be incredibly time-expensive and often present steep learning curves making them challenging to implement effectively in production environments.
|
|
12
|
+
|
|
13
|
+
To solve this problem, we created `xplainable`. **xplainable** presents a suite of novel machine learning algorithms specifically designed to match the performance of popular black box models like [XGBoost](https://github.com/dmlc/xgboost) and [LightGBM](https://github.com/microsoft/LightGBM) while providing complete transparency, all in real-time.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Xplainable Cloud
|
|
17
|
+
This Python package is free and open-source. To add more value to data teams within organisations, we also created Xplainable Cloud that brings your models to a collaborative environment.
|
|
18
|
+
|
|
19
|
+
### Preprocessing with Xplainable Cloud
|
|
20
|
+
Before modeling, it's essential to preprocess your data. Xplainable Cloud facilitates this process by allowing you to create and manage preprocessors in the cloud.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import xplainable as xp
|
|
25
|
+
import os
|
|
26
|
+
from xplainable_client import Client
|
|
27
|
+
|
|
28
|
+
#Initialising the client
|
|
29
|
+
XClient = Client(api_key=os.environ['XP_API_KEY'])
|
|
30
|
+
|
|
31
|
+
#Creating a Preprocessor ID
|
|
32
|
+
preprocessor_id = XClient.create_preprocessor_id(
|
|
33
|
+
preprocessor_name="Preprocessor Name",
|
|
34
|
+
preprocessor_description="Preprocessor Description",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
#Creating a Preprocessor Version
|
|
38
|
+
preprocessor_version = XClient.create_preprocessor_version(
|
|
39
|
+
preprocessor_id, #preprocessor_id,
|
|
40
|
+
pipeline, # <-- Pass the pipeline
|
|
41
|
+
df # <-- Pass the raw dataframe
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
#Loading the Preprocessor Client
|
|
45
|
+
pp_cloud = XClient.load_preprocessor(
|
|
46
|
+
preprocessor_id,
|
|
47
|
+
preprocessor_version["version_id"],
|
|
48
|
+
gui_object=False # Set to true to load the GUI object, keep as False for pipeline
|
|
49
|
+
)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Modelling with Xplainable Cloud
|
|
53
|
+
|
|
54
|
+
After preprocessing, the next step is to create and train your model. Xplainable Cloud supports model versioning and ID creation to streamline this process.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
|
|
58
|
+
#Creating a Model Id
|
|
59
|
+
model_id = XClient.create_model_id(
|
|
60
|
+
model,
|
|
61
|
+
model_name="Model Name",
|
|
62
|
+
model_description='Model Description'
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
#Creating a Model Version
|
|
66
|
+
version_id = XClient.create_model_version(
|
|
67
|
+
model,
|
|
68
|
+
model_id,
|
|
69
|
+
X_train,
|
|
70
|
+
y_train
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Deployments with Xplainable Cloud
|
|
76
|
+
Once your model is ready, deploying it is straightforward with Xplainable Cloud. You can deploy, activate, and manage API keys for your model deployment keys within your IDE or environment.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
#Creating a Model Deployment
|
|
80
|
+
deployment = XClient.deploy(
|
|
81
|
+
hostname="https://inference.xplainable.io",
|
|
82
|
+
model_id=model_id,
|
|
83
|
+
version_id=version_id
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
#Activating the Deployment
|
|
87
|
+
XClient.activate_deployment(deployment['deployment_id'])
|
|
88
|
+
|
|
89
|
+
#Generating an API Key
|
|
90
|
+
deploy_key = XClient.generate_deploy_key(
|
|
91
|
+
'API Key Name',
|
|
92
|
+
deployment['deployment_id'],
|
|
93
|
+
7 #-> Days until expiration
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
#Hitting the endpoint
|
|
97
|
+
response = requests.post(
|
|
98
|
+
url="https://inference.xplainable.io/v1/predict",
|
|
99
|
+
headers={'api_key': deploy_key['deploy_key']},
|
|
100
|
+
json=body
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
#Obtaining the value response
|
|
104
|
+
value = response.json()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<div align="center">
|
|
108
|
+
<br></br>
|
|
109
|
+
<br></br>
|
|
110
|
+
Thanks for trying xplainable!
|
|
111
|
+
<br></br>
|
|
112
|
+
<strong>Made with ❤️ in Australia</strong>
|
|
113
|
+
<br></br>
|
|
114
|
+
<hr>
|
|
115
|
+
© copyright xplainable pty ltd
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
|
|
@@ -7,7 +7,7 @@ find = {}
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "xplainable-client"
|
|
10
|
-
version = "1.2.
|
|
10
|
+
version = "1.2.2"
|
|
11
11
|
authors = [
|
|
12
12
|
{ name="xplainable pty ltd", email="contact@xplainable.io" },
|
|
13
13
|
]
|
|
@@ -26,12 +26,12 @@ classifiers = [
|
|
|
26
26
|
|
|
27
27
|
dependencies = [
|
|
28
28
|
"ipywidgets==8.0.6",
|
|
29
|
-
"numpy
|
|
29
|
+
"numpy>=1.20.3",
|
|
30
30
|
"pandas>=1.5.2,<=1.9.0",
|
|
31
31
|
"pyperclip==1.8.2",
|
|
32
32
|
"Requests==2.31.0",
|
|
33
33
|
"scikit_learn",
|
|
34
34
|
"setuptools",
|
|
35
35
|
"urllib3==2.2.0",
|
|
36
|
-
"xplainable
|
|
36
|
+
"xplainable"
|
|
37
37
|
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .datasets import *
|
|
2
|
+
from functools import cached_property
|
|
3
|
+
|
|
4
|
+
from ._models import *
|
|
5
|
+
from ._misc import *
|
|
6
|
+
from requests.packages.urllib3.util.retry import Retry
|
|
7
|
+
from ._session import Session
|
|
8
|
+
from ._misc import Misc
|
|
9
|
+
from ._models import Models
|
|
10
|
+
from ._preprocessing import Preprocessing
|
|
11
|
+
from ._deployments import Deployments
|
|
12
|
+
from ._gpt import GPT
|
|
13
|
+
from ._collections import Collections
|
|
14
|
+
from ._datasets import Datasets
|
|
15
|
+
from ._inference import Inference
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Client(Misc, Models, Preprocessing, GPT, Collections):
|
|
19
|
+
|
|
20
|
+
def __init__(self, api_key=None, hostname='https://api.xplainable.io', silent_mode=False):
|
|
21
|
+
self.session = Session(api_key=api_key, hostname=hostname, silent_mode=silent_mode)
|
|
22
|
+
Misc.__init__(self, self.session)
|
|
23
|
+
Models.__init__(self, self.session)
|
|
24
|
+
Preprocessing.__init__(self, self.session)
|
|
25
|
+
Deployments.__init__(self, self.session)
|
|
26
|
+
GPT.__init__(self, self.session)
|
|
27
|
+
Collections.__init__(self, self.session)
|
|
28
|
+
Datasets.__init__(self, self.session)
|
|
29
|
+
Inference.__init__(self, self.session)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
from ._client_cog_base import *
|
|
2
|
+
from ._models import Models
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Collections(Client_Cog):
|
|
6
|
+
|
|
7
|
+
def create_collection(self, model_id: str, name: str, description: str):
|
|
8
|
+
""" Creates a new collection.
|
|
9
|
+
Args:
|
|
10
|
+
model_id (str): The model id.
|
|
11
|
+
name (str): The name of the collection.
|
|
12
|
+
description (str): The description of the collection.
|
|
13
|
+
Returns:
|
|
14
|
+
int: The id of the collection created.
|
|
15
|
+
"""
|
|
16
|
+
payload = {
|
|
17
|
+
"name": name,
|
|
18
|
+
"description": description
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
response = self.session._session.put(
|
|
22
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/create-collection",
|
|
23
|
+
json=payload
|
|
24
|
+
)
|
|
25
|
+
data = self.session.get_response_content(response)
|
|
26
|
+
return data
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_model_collections(self, model_id: str):
|
|
30
|
+
""" Gets all collections of a model.
|
|
31
|
+
Args:
|
|
32
|
+
model_id (str): The model id.
|
|
33
|
+
Returns:
|
|
34
|
+
dict: Dictionary of collections.
|
|
35
|
+
"""
|
|
36
|
+
response = self.session._session.get(
|
|
37
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections"
|
|
38
|
+
)
|
|
39
|
+
data = self.session.get_response_content(response)
|
|
40
|
+
return data
|
|
41
|
+
|
|
42
|
+
def get_team_collections(self):
|
|
43
|
+
""" Gets all collections of a team.
|
|
44
|
+
Returns:
|
|
45
|
+
dict: Dictionary of collections.
|
|
46
|
+
"""
|
|
47
|
+
response = self.session._session.get(
|
|
48
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/collections"
|
|
49
|
+
)
|
|
50
|
+
data = self.session.get_response_content(response)
|
|
51
|
+
return data
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def edit_collection_name(self, model_id: str, collections_id: str, name: str):
|
|
55
|
+
""" Edits the name of a collection.
|
|
56
|
+
Args:
|
|
57
|
+
model_id (str): The model id.
|
|
58
|
+
collections_id (str): The collection id.
|
|
59
|
+
name (str): The new name of the collection.
|
|
60
|
+
Returns:
|
|
61
|
+
json: A json payload.
|
|
62
|
+
"""
|
|
63
|
+
payload = {
|
|
64
|
+
"name": name
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
response = self.session._session.patch(
|
|
68
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collections_id}/name",
|
|
69
|
+
json=payload
|
|
70
|
+
)
|
|
71
|
+
return response
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def edit_collection_description(self, model_id: str, collections_id: str, description: str):
|
|
75
|
+
""" Edits the description of a collection.
|
|
76
|
+
Args:
|
|
77
|
+
model_id (str): The model id.
|
|
78
|
+
collections_id (str): The collection id.
|
|
79
|
+
description (str): The new description of the collection.
|
|
80
|
+
Returns:
|
|
81
|
+
json: A json payload.
|
|
82
|
+
"""
|
|
83
|
+
payload = {
|
|
84
|
+
"description": description
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
response = self.session._session.patch(
|
|
88
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collections_id}/description",
|
|
89
|
+
json=payload
|
|
90
|
+
)
|
|
91
|
+
return response
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def delete_collection(self, model_id: str, collections_id: str):
|
|
95
|
+
""" Deletes a collection.
|
|
96
|
+
Args:
|
|
97
|
+
model_id (str): The model id.
|
|
98
|
+
collections_id (str): The collection id.
|
|
99
|
+
Returns:
|
|
100
|
+
json: A json payload.
|
|
101
|
+
"""
|
|
102
|
+
response = self.session._session.delete(
|
|
103
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collections_id}"
|
|
104
|
+
)
|
|
105
|
+
return response
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def delete_model_collections(self, model_id: str):
|
|
109
|
+
""" Deletes all collections of a model.
|
|
110
|
+
Args:
|
|
111
|
+
model_id (str): The model id.
|
|
112
|
+
Returns:
|
|
113
|
+
json: A json payload.
|
|
114
|
+
"""
|
|
115
|
+
response = self.session._session.delete(
|
|
116
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections"
|
|
117
|
+
)
|
|
118
|
+
return response
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def restore_collection(self, model_id: str, collection_id: str):
|
|
122
|
+
""" Restores a collection.
|
|
123
|
+
Args:
|
|
124
|
+
model_id (str): The model id.
|
|
125
|
+
collections_id (str): The collection id.
|
|
126
|
+
Returns:
|
|
127
|
+
json: A json payload.
|
|
128
|
+
"""
|
|
129
|
+
response = self.session._session.patch(
|
|
130
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collection_id}/restore"
|
|
131
|
+
)
|
|
132
|
+
return response
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def get_collection(self, model_id: str, collection_id: str):
|
|
136
|
+
""" Gets a collection.
|
|
137
|
+
Args:
|
|
138
|
+
model_id (str): The model id.
|
|
139
|
+
collections_id (str): The collection id.
|
|
140
|
+
Returns:
|
|
141
|
+
dict: Dictionary of collection.
|
|
142
|
+
"""
|
|
143
|
+
response = self.session._session.get(
|
|
144
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collection_id}"
|
|
145
|
+
)
|
|
146
|
+
data = self.session.get_response_content(response)
|
|
147
|
+
return data
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
#TODO: Implement.
|
|
151
|
+
# def add_scenario(self, model_id: str, version_id: str, collection_id: str):
|
|
152
|
+
# try:
|
|
153
|
+
# response = self.session._session.get(
|
|
154
|
+
# url=f'{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/versions/{version_id}'
|
|
155
|
+
# )
|
|
156
|
+
# return self.session.get_response_content(response)
|
|
157
|
+
# except Exception as e:
|
|
158
|
+
# raise ValueError(f'Model with ID {model_id}:{version_id} does not exist')
|
|
159
|
+
# return
|
|
160
|
+
|
|
161
|
+
# add_scenario
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def edit_scenario_notes(self, model_id: str, collection_id: str, scenario_id: str, notes: str):
|
|
165
|
+
""" Edits the notes of a scenario.
|
|
166
|
+
Args:
|
|
167
|
+
model_id (str): The model id.
|
|
168
|
+
collections_id (str): The collection id.
|
|
169
|
+
scenario_id (str): The scenario id.
|
|
170
|
+
notes (str): The new notes of the scenario.
|
|
171
|
+
Returns:
|
|
172
|
+
json: A json payload.
|
|
173
|
+
"""
|
|
174
|
+
payload = {
|
|
175
|
+
"notes": notes
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
response = self.session._session.patch(
|
|
179
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collection_id}/scenarios/{scenario_id}/notes",
|
|
180
|
+
json=payload
|
|
181
|
+
)
|
|
182
|
+
return response
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def delete_scenario(self, model_id: str, collection_id: str, scenario_id: str):
|
|
186
|
+
"""" Deletes a scenario.
|
|
187
|
+
Args:
|
|
188
|
+
model_id (str): The model id.
|
|
189
|
+
collections_id (str): The collection id.
|
|
190
|
+
scenario_id (str): The scenario id.
|
|
191
|
+
Returns:
|
|
192
|
+
json: A json payload.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
response = self.session._session.delete(
|
|
196
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collection_id}/scenarios/{scenario_id}"
|
|
197
|
+
)
|
|
198
|
+
return response
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def restore_scenario(self, model_id: str, collection_id: str, scenario_id: str):
|
|
202
|
+
""" Restores a scenario.
|
|
203
|
+
Args:
|
|
204
|
+
model_id (str): The model id.
|
|
205
|
+
collections_id (str): The collection id.
|
|
206
|
+
scenario_id (str): The scenario id.
|
|
207
|
+
Returns:
|
|
208
|
+
json: A json payload.
|
|
209
|
+
"""
|
|
210
|
+
response = self.session._session.patch(
|
|
211
|
+
url=f"{self.session.hostname}/v1/{self.session.__ext}/models/{model_id}/collections/{collection_id}/scenarios/{scenario_id}/restore"
|
|
212
|
+
)
|
|
213
|
+
return response
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from ._client_cog_base import *
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Datasets(Client_Cog):
|
|
8
|
+
|
|
9
|
+
# upload_dataset
|
|
10
|
+
|
|
11
|
+
def list_datasets(self):
|
|
12
|
+
|
|
13
|
+
response = requests.get('https://api.xplainable.io/v1/public-datasets')
|
|
14
|
+
|
|
15
|
+
if response.status_code != 200:
|
|
16
|
+
raise ValueError(f'Unable to list datasets. Check your connection and try again.')
|
|
17
|
+
|
|
18
|
+
return response.json()
|
|
19
|
+
|
|
20
|
+
def _get_url_path(self, name):
|
|
21
|
+
_base = 'xplainablepublic'
|
|
22
|
+
_type = 'blob.core.windows.net'
|
|
23
|
+
_loc = 'asset-repository/datasets'
|
|
24
|
+
|
|
25
|
+
return f'https://{_base}.{_type}/{_loc}/{name}/data.csv'
|
|
26
|
+
|
|
27
|
+
def load_dataset(self, name):
|
|
28
|
+
|
|
29
|
+
datasets = self.list_datasets()
|
|
30
|
+
|
|
31
|
+
if name not in datasets:
|
|
32
|
+
raise ValueError(f'{name} is not available. Run xp.list_datasets() to see available datasets.')
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
url = self._get_url_path(name)
|
|
36
|
+
df = pd.read_csv(url)
|
|
37
|
+
|
|
38
|
+
return df
|
|
39
|
+
|
|
40
|
+
except Exception as e:
|
|
41
|
+
raise ValueError(f'Unable to load dataset {name}. Check your connection and try again.')
|
|
42
|
+
|
|
43
|
+
# update_dataset
|
|
44
|
+
|
|
45
|
+
# detele_dataset
|
|
46
|
+
|
|
47
|
+
# list_dataset_children
|
|
48
|
+
|
|
49
|
+
# preview_dataset
|
|
50
|
+
|
|
51
|
+
# list_pub_datasets
|