Skip to content

Commit db06296

Browse files
Parthibwhoseoyster
authored andcommitted
Client side changes to support tasktype being a property of projects now
1 parent e47d090 commit db06296

File tree

12 files changed

+45
-24
lines changed

12 files changed

+45
-24
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
* Models and datasets must be added to projects. Added a `Project` helper class.
1313
* Deprecates `categorical_features_map` in favor of `categorical_feature_names` for model and dataset uploads.
14+
* Added a convenience method `create_or_load_project` which loads in a project in if it is already created.
15+
* Moved `TaskType` attribute from the `Model` level to the `Project` level. Creating a `Project` now requires specifying the `TaskType`.
1416

1517
## [0.2.0a1]
1618

examples/tabular-classification/churn-classifier/churn-classifier-sklearn.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,21 @@
233233
"metadata": {},
234234
"outputs": [],
235235
"source": [
236+
"\n",
236237
"from unboxapi.tasks import TaskType\n",
237238
"\n",
238239
"# Comment this out and uncomment the next section to load the project\n",
239240
"project = client.create_project(\n",
240241
" name=\"Banking Churn Project\",\n",
241-
" description=\"Project for predicting Banking Churn\"\n",
242+
" description=\"Project for Predicting Banking Churn\",\n",
243+
" task_type=TaskType.TabularClassification,\n",
242244
")\n",
243245
"'''\n",
244246
"# Use this for loading the project on subsequent runs\n",
245247
"project = client.load_project(\n",
246248
" name=\"Banking Churn Project\"\n",
247249
")\n",
248250
"'''\n",
249-
"\n",
250251
"dataset = project.add_dataframe(\n",
251252
" df=x_val,\n",
252253
" class_names=class_names,\n",
@@ -270,7 +271,6 @@
270271
" function=predict_proba, \n",
271272
" model=sklearn_model,\n",
272273
" model_type=ModelType.sklearn,\n",
273-
" task_type=TaskType.TabularClassification,\n",
274274
" class_names=class_names,\n",
275275
" name='Churn Classifier',\n",
276276
" description='this is my churn classification model',\n",
@@ -292,6 +292,14 @@
292292
"metadata": {},
293293
"outputs": [],
294294
"source": []
295+
},
296+
{
297+
"cell_type": "code",
298+
"execution_count": null,
299+
"id": "b4ecb0cf",
300+
"metadata": {},
301+
"outputs": [],
302+
"source": []
295303
}
296304
],
297305
"metadata": {

examples/tabular-classification/fetal-health/fetal-health-sklearn.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@
182182
"# Comment this out and uncomment the next section to load the project\n",
183183
"project = client.create_project(\n",
184184
" name=\"Sklearn Fetal Health Project\",\n",
185-
" description=\"Project for predicting fetal health\"\n",
185+
" description=\"Project for predicting fetal health\",\n",
186+
" task_type=TaskType.TabularClassification\n",
186187
")\n",
187188
"\n",
188189
"# Use this for loading the project on subsequent runs\n",
@@ -214,7 +215,6 @@
214215
" function=predict_proba, \n",
215216
" model=clf,\n",
216217
" model_type=ModelType.sklearn,\n",
217-
" task_type=TaskType.TabularClassification,\n",
218218
" class_names=class_names,\n",
219219
" name='Fetal Classifier - N3',\n",
220220
" description='this is my second tabular classification model',\n",

examples/tabular-classification/fraud-detection/fraud-classifier-sklearn.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@
253253
"# Comment this out and uncomment the next section to load the project\n",
254254
"project = client.create_project(\n",
255255
" name=\"Sklearn Fraud Classifier\",\n",
256-
" description=\"Project for Classifying Fraud\"\n",
256+
" description=\"Project for Classifying Fraud\",\n",
257+
" task_type=TaskType.TabularClassification\n",
257258
")\n",
258259
"\n",
259260
"# Use this for loading the project on subsequent runs\n",
@@ -287,7 +288,6 @@
287288
" function=predict_proba, \n",
288289
" model=sklearn_model,\n",
289290
" model_type=ModelType.sklearn,\n",
290-
" task_type=TaskType.TabularClassification,\n",
291291
" class_names=class_names,\n",
292292
" name='Fraud detection',\n",
293293
" description='this is my fraud classification model',\n",

examples/tabular-classification/iris-classifier/iris-tabular-sklearn.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@
157157
"# Comment this out and uncomment the next section to load the project\n",
158158
"project = client.create_project(\n",
159159
" name=\"Sklearn Iris Tabular\",\n",
160-
" description=\"Project for Iris Tabular data\"\n",
160+
" description=\"Project for Iris Tabular data\",\n",
161+
" task_type=TaskType.TabularClassification,\n",
161162
")\n",
162163
"\n",
163164
"# Use this for loading the project on subsequent runs\n",
@@ -189,7 +190,6 @@
189190
" function=predict_proba, \n",
190191
" model=classifiers['L1 logistic'],\n",
191192
" model_type=ModelType.sklearn,\n",
192-
" task_type=TaskType.TabularClassification,\n",
193193
" class_names=class_names,\n",
194194
" name='Iris - L1 Logistic',\n",
195195
" description='this is my first tabular classification model',\n",

examples/text-classification/fasttext/fasttext.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@
179179
"# Comment this out and uncomment the next section to load the project\n",
180180
"project = client.create_project(\n",
181181
" name=\"Fasttext Demo\",\n",
182-
" description=\"Fasttext Demo Project\"\n",
182+
" description=\"Fasttext Demo Project\",\n",
183+
" task_type=TaskType.TextClassification,\n",
183184
")\n",
184185
"\n",
185186
"# Use this for loading the project on subsequent runs\n",
@@ -193,7 +194,6 @@
193194
" function=get_predictions, \n",
194195
" model=model,\n",
195196
" model_type=ModelType.fasttext,\n",
196-
" task_type=TaskType.TextClassification,\n",
197197
" class_names=class_names,\n",
198198
" name='Cooking Fast Text',\n",
199199
" description='this is my fasttext model',\n",

examples/text-classification/sklearn/banking/demo-banking.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@
197197
"# Comment this out and uncomment the next section to load the project\n",
198198
"project = client.create_project(\n",
199199
" name=\"Sklearn Banking Project\",\n",
200-
" description=\"Project to Demo Sklearn with Unbox\"\n",
200+
" description=\"Project to Demo Sklearn with Unbox\",\n",
201+
" task_type=TaskType.TextClassification,\n",
201202
")\n",
202203
"\n",
203204
"# Use this for loading the project on subsequent runs\n",
@@ -211,7 +212,6 @@
211212
" function=predict_function, \n",
212213
" model=model,\n",
213214
" model_type=ModelType.sklearn,\n",
214-
" task_type=TaskType.TextClassification,\n",
215215
" class_names=label_list,\n",
216216
" name='Banking Model',\n",
217217
" description='this is my sklearn banking model'\n",

examples/text-classification/sklearn/stacked-models/fastttext-stacked.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@
225225
"# Comment this out and uncomment the next section to load the project\n",
226226
"project = client.create_project(\n",
227227
" name=\"Fasttext Stacked Model\",\n",
228-
" description=\"Project to Demo Fasttext Stacked\"\n",
228+
" description=\"Project to Demo Fasttext Stacked\",\n",
229+
" task_type=TaskType.TextClassification,\n",
229230
")\n",
230231
"\n",
231232
"# Use this for loading the project on subsequent runs\n",
@@ -257,7 +258,6 @@
257258
" dependent_dir=folder_name,\n",
258259
" custom_model_code=custom_model_code,\n",
259260
" model_type=ModelType.custom,\n",
260-
" task_type=TaskType.TextClassification,\n",
261261
" class_names=all_class_names,\n",
262262
" requirements_txt_file=\"./requirements.txt\",\n",
263263
" name='Stacked model',\n",

examples/text-classification/transformers/transformers.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
"# Comment this out and uncomment the next section to load the project\n",
127127
"project = client.create_project(\n",
128128
" name=\"Transformer Demo Project\",\n",
129-
" description=\"Project to Demo Transformers with Unbox\"\n",
129+
" description=\"Project to Demo Transformers with Unbox\",\n",
130+
" task_type=TaskType.TextClassification,\n",
130131
")\n",
131132
"\n",
132133
"# Use this for loading the project on subsequent runs\n",
@@ -140,7 +141,6 @@
140141
" function=predict_proba, \n",
141142
" model=model,\n",
142143
" model_type=ModelType.transformers,\n",
143-
" task_type=TaskType.TextClassification,\n",
144144
" class_names=['negative', 'positive'],\n",
145145
" name='transformers.sentiment_analyzer',\n",
146146
" description='this is my transformers sentiment model',\n",

unboxapi/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .api import Api
1212
from bentoml.saved_bundle.bundler import _write_bento_content_to_dir
1313
from bentoml.utils.tempdir import TempDirectory
14-
from .exceptions import UnboxException, UnboxInvalidRequest
14+
from .exceptions import UnboxDuplicateTask, UnboxException, UnboxInvalidRequest
1515
from .models import Model, ModelType, create_template_model
1616
from .datasets import Dataset
1717
from .tasks import TaskType
@@ -62,17 +62,29 @@ def __init__(self, api_key: str):
6262
else:
6363
self.upload = self.api.transfer_blob
6464

65-
def create_project(self, name: str, description: str):
65+
def create_project(self, name: str, description: str, task_type: TaskType):
6666
endpoint = "projects"
67-
payload = dict(name=name, description=description)
67+
payload = dict(
68+
name=name,
69+
description=description,
70+
taskType=task_type.value,
71+
)
6872
project_data = self.api.post_request(endpoint, body=payload)
73+
print(project_data)
6974
return Project(project_data, self.upload, self.subscription_plan, self)
7075

7176
def load_project(self, name: str):
7277
endpoint = f"me/projects/{name}"
7378
project_data = self.api.get_request(endpoint)
79+
print(project_data)
7480
return Project(project_data, self.upload, self.subscription_plan, self)
7581

82+
def create_or_load_project(self, name: str, description: str, task_type: TaskType):
83+
try:
84+
return self.create_project(name, description, task_type)
85+
except UnboxDuplicateTask:
86+
return self.load_project(name)
87+
7688
def add_model(
7789
self,
7890
name: str,
@@ -440,7 +452,6 @@ def add_model(
440452
project_id=project_id,
441453
description=description,
442454
classNames=class_names,
443-
taskType=task_type.value,
444455
architectureType=model_type.name,
445456
kwargs=list(kwargs.keys()),
446457
featureNames=feature_names,

0 commit comments

Comments
 (0)