Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

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

## [0.2.0a1]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,21 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"from unboxapi.tasks import TaskType\n",
"\n",
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Banking Churn Project\",\n",
" description=\"Project for predicting Banking Churn\"\n",
" description=\"Project for Predicting Banking Churn\",\n",
" task_type=TaskType.TabularClassification,\n",
")\n",
"'''\n",
"# Use this for loading the project on subsequent runs\n",
"project = client.load_project(\n",
" name=\"Banking Churn Project\"\n",
")\n",
"'''\n",
"\n",
"dataset = project.add_dataframe(\n",
" df=x_val,\n",
" class_names=class_names,\n",
Expand All @@ -270,7 +271,6 @@
" function=predict_proba, \n",
" model=sklearn_model,\n",
" model_type=ModelType.sklearn,\n",
" task_type=TaskType.TabularClassification,\n",
" class_names=class_names,\n",
" name='Churn Classifier',\n",
" description='this is my churn classification model',\n",
Expand All @@ -292,6 +292,14 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4ecb0cf",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Sklearn Fetal Health Project\",\n",
" description=\"Project for predicting fetal health\"\n",
" description=\"Project for predicting fetal health\",\n",
" task_type=TaskType.TabularClassification\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand Down Expand Up @@ -214,7 +215,6 @@
" function=predict_proba, \n",
" model=clf,\n",
" model_type=ModelType.sklearn,\n",
" task_type=TaskType.TabularClassification,\n",
" class_names=class_names,\n",
" name='Fetal Classifier - N3',\n",
" description='this is my second tabular classification model',\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Sklearn Fraud Classifier\",\n",
" description=\"Project for Classifying Fraud\"\n",
" description=\"Project for Classifying Fraud\",\n",
" task_type=TaskType.TabularClassification\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand Down Expand Up @@ -287,7 +288,6 @@
" function=predict_proba, \n",
" model=sklearn_model,\n",
" model_type=ModelType.sklearn,\n",
" task_type=TaskType.TabularClassification,\n",
" class_names=class_names,\n",
" name='Fraud detection',\n",
" description='this is my fraud classification model',\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Sklearn Iris Tabular\",\n",
" description=\"Project for Iris Tabular data\"\n",
" description=\"Project for Iris Tabular data\",\n",
" task_type=TaskType.TabularClassification,\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand Down Expand Up @@ -189,7 +190,6 @@
" function=predict_proba, \n",
" model=classifiers['L1 logistic'],\n",
" model_type=ModelType.sklearn,\n",
" task_type=TaskType.TabularClassification,\n",
" class_names=class_names,\n",
" name='Iris - L1 Logistic',\n",
" description='this is my first tabular classification model',\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/text-classification/fasttext/fasttext.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Fasttext Demo\",\n",
" description=\"Fasttext Demo Project\"\n",
" description=\"Fasttext Demo Project\",\n",
" task_type=TaskType.TextClassification,\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand All @@ -193,7 +194,6 @@
" function=get_predictions, \n",
" model=model,\n",
" model_type=ModelType.fasttext,\n",
" task_type=TaskType.TextClassification,\n",
" class_names=class_names,\n",
" name='Cooking Fast Text',\n",
" description='this is my fasttext model',\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Sklearn Banking Project\",\n",
" description=\"Project to Demo Sklearn with Unbox\"\n",
" description=\"Project to Demo Sklearn with Unbox\",\n",
" task_type=TaskType.TextClassification,\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand All @@ -211,7 +212,6 @@
" function=predict_function, \n",
" model=model,\n",
" model_type=ModelType.sklearn,\n",
" task_type=TaskType.TextClassification,\n",
" class_names=label_list,\n",
" name='Banking Model',\n",
" description='this is my sklearn banking model'\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Fasttext Stacked Model\",\n",
" description=\"Project to Demo Fasttext Stacked\"\n",
" description=\"Project to Demo Fasttext Stacked\",\n",
" task_type=TaskType.TextClassification,\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand Down Expand Up @@ -257,7 +258,6 @@
" dependent_dir=folder_name,\n",
" custom_model_code=custom_model_code,\n",
" model_type=ModelType.custom,\n",
" task_type=TaskType.TextClassification,\n",
" class_names=all_class_names,\n",
" requirements_txt_file=\"./requirements.txt\",\n",
" name='Stacked model',\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/text-classification/transformers/transformers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
"# Comment this out and uncomment the next section to load the project\n",
"project = client.create_project(\n",
" name=\"Transformer Demo Project\",\n",
" description=\"Project to Demo Transformers with Unbox\"\n",
" description=\"Project to Demo Transformers with Unbox\",\n",
" task_type=TaskType.TextClassification,\n",
")\n",
"\n",
"# Use this for loading the project on subsequent runs\n",
Expand All @@ -140,7 +141,6 @@
" function=predict_proba, \n",
" model=model,\n",
" model_type=ModelType.transformers,\n",
" task_type=TaskType.TextClassification,\n",
" class_names=['negative', 'positive'],\n",
" name='transformers.sentiment_analyzer',\n",
" description='this is my transformers sentiment model',\n",
Expand Down
31 changes: 20 additions & 11 deletions unboxapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import csv
import os
import pandas as pd
import shutil
import tarfile
import tempfile
import uuid

from enum import Enum
from typing import Dict, List, Optional

from .api import Api
import pandas as pd
from bentoml.saved_bundle.bundler import _write_bento_content_to_dir
from bentoml.utils.tempdir import TempDirectory
from .exceptions import UnboxException, UnboxInvalidRequest
from .models import Model, ModelType, create_template_model

from .api import Api
from .datasets import Dataset
from .tasks import TaskType
from typing import Dict, List, Optional
from .exceptions import UnboxDuplicateTask, UnboxException, UnboxInvalidRequest
from .models import Model, ModelType, create_template_model
from .projects import Project
from .version import __version__
from .tasks import TaskType
from .version import __version__ # noqa: F401


class DeploymentType(Enum):
Expand Down Expand Up @@ -62,9 +62,13 @@ def __init__(self, api_key: str):
else:
self.upload = self.api.transfer_blob

def create_project(self, name: str, description: str):
def create_project(self, name: str, description: str, task_type: TaskType):
endpoint = "projects"
payload = dict(name=name, description=description)
payload = dict(
name=name,
description=description,
taskType=task_type.value,
)
project_data = self.api.post_request(endpoint, body=payload)
return Project(project_data, self.upload, self.subscription_plan, self)

Expand All @@ -73,6 +77,12 @@ def load_project(self, name: str):
project_data = self.api.get_request(endpoint)
return Project(project_data, self.upload, self.subscription_plan, self)

def create_or_load_project(self, name: str, description: str, task_type: TaskType):
try:
return self.create_project(name, description, task_type)
except UnboxDuplicateTask:
return self.load_project(name)

def add_model(
self,
name: str,
Expand Down Expand Up @@ -440,7 +450,6 @@ def add_model(
project_id=project_id,
description=description,
classNames=class_names,
taskType=task_type.value,
architectureType=model_type.name,
kwargs=list(kwargs.keys()),
featureNames=feature_names,
Expand Down
2 changes: 1 addition & 1 deletion unboxapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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


Expand Down
9 changes: 6 additions & 3 deletions unboxapi/projects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .models import Model
from unboxapi import tasks

from .datasets import Dataset
from .models import Model


class Project:
Expand Down Expand Up @@ -40,8 +42,9 @@ def add_model(
*args,
**kwargs,
) -> Model:
kwargs["project_id"] = self.id
return self.client.add_model(*args, **kwargs)
return self.client.add_model(
*args, project_id=self.id, task_type=tasks.TaskType(self.taskType), **kwargs
)

def add_dataset(
self,
Expand Down