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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ $ pip install -e .

```python
import unboxapi
client = unboxapi.UnboxClient()
client = unboxapi.UnboxClient(email='you@domain.com', password='your_password')

# Package as a bento service and upload to Firebase Storage
client.add(function=predict_function, model=any_model)
# Package a model as a bento service and upload to Firebase
client.add_model(function=predict_function, model=any_model)

# Upload a dataset to Firebase
client.add_dataset(file_path='path/to/dataset.csv', name='dataset_name')

# Upload a pandas data frame to Firebase
client.add_dataframe(df='dataframe_object', name='dataset_name')
```
17 changes: 10 additions & 7 deletions unboxapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import bentoml, getpass, os, pandas as pd, tarfile, tempfile, uuid
import bentoml
import getpass
import os
import pandas as pd
import tarfile
import tempfile
import uuid

from bentoml.saved_bundle.bundler import _write_bento_content_to_dir
from bentoml.utils.tempdir import TempDirectory
Expand All @@ -15,7 +21,6 @@ def __init__(self, email: str = None, password: str = None):
self.flask_api = FlaskAPI()
self.firebase_api = FirebaseAPI(email=email, password=password)


def add_model(self, function, model):
bento_service = create_template_model('sklearn', 'text')
bento_service.pack('model', model)
Expand All @@ -31,10 +36,9 @@ def add_model(self, function, model):
with tarfile.open(tarfile_path, mode='w:gz') as tar:
tar.add(temp_dir, arcname=bento_service.name)

user_id = self.firebase_api.user['localId']
remote_path = f'users/{user_id}/models/{model_id}'
self.firebase_api.upload(remote_path, tarfile_path)

user_id = self.firebase_api.user['localId']
remote_path = f'users/{user_id}/models/{model_id}'
self.firebase_api.upload(remote_path, tarfile_path)

def add_dataset(self, file_path: str, name: str):
# For now, let's upload straight to Firebase Storage from here
Expand All @@ -51,7 +55,6 @@ def add_dataset(self, file_path: str, name: str):
id_token)
return response.json()


def add_dataframe(self, df: pd.DataFrame, name: str):
with tempfile.TemporaryDirectory() as tmp_dir:
dataset_file_path = os.path.join(tmp_dir, str(uuid.uuid1()))
Expand Down