Skip to content

Commit 71ae07b

Browse files
committed
Client side changes to support tasktype being a property of projects now
1 parent e47d090 commit 71ae07b

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

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

Lines changed: 11 additions & 2 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",
@@ -292,6 +293,14 @@
292293
"metadata": {},
293294
"outputs": [],
294295
"source": []
296+
},
297+
{
298+
"cell_type": "code",
299+
"execution_count": null,
300+
"id": "b4ecb0cf",
301+
"metadata": {},
302+
"outputs": [],
303+
"source": []
295304
}
296305
],
297306
"metadata": {

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,

unboxapi/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# UNBOX_ENDPOINT = "https://api-dev.unbox.ai/api"
1414
# UNBOX_ENDPOINT = "https://api.unbox.ai/api"
15-
UNBOX_ENDPOINT = "http://localhost:8080/v1"
15+
UNBOX_ENDPOINT = "http://localhost:8080/api"
1616
UNBOX_STORAGE_PATH = os.path.expanduser("~/unbox/unbox-onpremise/userStorage")
1717

1818

unboxapi/projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def add_model(
4141
**kwargs,
4242
) -> Model:
4343
kwargs["project_id"] = self.id
44+
kwargs["task_type"] = self.taskType # Not camelcase due to API response stored via __getattr__
4445
return self.client.add_model(*args, **kwargs)
4546

4647
def add_dataset(

0 commit comments

Comments
 (0)