diff --git a/README.md b/README.md index fbd93279..2d58d754 100644 --- a/README.md +++ b/README.md @@ -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') ``` diff --git a/unboxapi/__init__.py b/unboxapi/__init__.py index fdc79387..3529739f 100644 --- a/unboxapi/__init__.py +++ b/unboxapi/__init__.py @@ -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 @@ -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) @@ -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 @@ -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()))