Package: shippedbrain
shippedbrainClient library to publish models onapp.shippedbrain.comCreateserverless REST endpointsfor machine learning models and gethosted web pagesinstantly.pip install shippedbrainUsing the CLI:shippedbrain upload --model_name My-Amazing-Model --run_id 6f252757005748708cd3aad75d1ff462Using the Python API:Uploading a logged mlflow model from and existingrun_idusing theshippedbrain.upload_runfunctionimportpandasaspdfromsklearnimportdatasetsfromsklearn.ensembleimportRandomForestClassifierimportmlflowimportnumpyasnpimportmlflow.sklearnfrommlflow.models.signatureimportinfer_signaturefromshippedbrainimportshippedbrainiris=datasets.load_iris()iris_train=pd.DataFrame(iris.data,columns=iris.feature_names)# each input has shape (4, 4)input_example=input_example=iris_train.head()withmlflow.start_run(run_name="YOUR_RUN_NAME")asrun:clf=RandomForestClassifier(max_depth=7,random_state=0)clf.fit(iris_train,iris.target)signature=infer_signature(iris_train,clf.predict(iris_train))mlflow.sklearn.log_model(clf,"iris_rf",signature=signature,input_example=input_example)shippedbrain.upload_run(run_id=run.info.run_id,email="YOUR_EMAIL",# can be left blank if env. var. SHIPPED_BRAIN_EMAIL is setpassword="YOUR_PASSWORD",# can be left blank if env. var. SHIPPED_BRAIN_PASSWORD is setmodel_name="YOUR_MODEL_NAME")Uploading a Random Forest model in scikit-learn using theshippedbrain.upload_modelfunctionfromshippedbrainimportshippedbrainimportpandasaspdfromsklearnimportdatasetsfromsklearn.ensembleimportRandomForestClassifierfrommlflow.models.signatureimportinfer_signatureiris=datasets.load_iris()iris_train=pd.DataFrame(iris.data,columns=iris.feature_names)clf=RandomForestClassifier(max_depth=7,random_state=0)clf.fit(iris_train,iris.target)signature=infer_signature(iris_train,clf.predict(iris_train))input_example={"sepal length (cm)":5.1,"sepal width (cm)":3.5,"petal length (cm)":1.4,"petal width (cm)":0.2}# Upload the sklearn modelshippedbrain.upload_model(email="YOUR_EMAIL",# can be left blank if env. var. SHIPPED_BRAIN_EMAIL is setpassword="YOUR_PASSWORD",# can be left blank if env. var. SHIPPED_BRAIN_PASSWORD is setmodel_name="MODEL_NAME",signature=signature,input_example=input_example,sk_model=clf,# named arg. required by mlflow.sklearn.log_modelartifact_path="sklearn-model"# named arg. required by mlflow.sklearn.log_model)Shipped BrainShipped Brainis an AI platform that allows anyone to share and upload machine learning models fast and easily.Managed REST API endpointsUse anywhereWhen a model is published onapp.shippedbrain.comit gets its unique and standardized REST API endpoint automatically that can be embedded anywhere.To use a shipped brain model you just need to make an HTTP POST request to the model's endpoint:app.shippedbrain.com/api/v0/<your-model-name>/<version>Straightforward deployments with one line of codePublic REST endpoints that anyone can try and verify - managed for youNo serving code and zero configurationHosted Model PagesInteractive web pages to get started easilyAn interactive web page for every model - automatically created and hosted for you.Share your models' web pages and allow anyone to experiment with your models in the browser or using the REST API.An interactive web page for every model - automatically created and hosted for youIn-app experimentation using model input examplesAuto-generated model signatures on your models' web pagesData Science PortfolioBuild a home for your AIStart creating your data science portfolio. Share you Shipped Brain profile with other AI specialists, companies or include it in your resumé. Your shipped brain profiles is a great way to showcase all your models.Leverage Shipped Brain's profiles and infrastructure to manage your online presence as an AI specialistShare your profile and models on social media platforms with one clickAboutshippedbrainTheshippedbrainclient library provides a convenient way to publish models onapp.shippedbrain.com.It integrates with the widely usedmlflowlibrary, so anymlflowmodel will work on shipped brain.Model Publish WorkflowsThere are 2 main ways in which you can publish models onto shipped brain:Publish a trained model using theshippedbrain.upload_modelfunctionPublish a model from an existingmlfowlogged model run, via the CLI commandshippedbrain uploador Python API using theshippedbrain.upload_runfunctionFor more information on how to log models withmlflowread thedocumentationUsageTheshippedbrainclient library has aPython APIandCLIflavors.Use environment variables to set your shipped brain email and password (advised)SHIPPED_BRAIN_EMAILSHIPPED_BRAIN_PASSWORDShipped Brain models signature and input exampleAll models published onapp.shippedbrain.comhave a validmlflowinput_exampleandsignatureWhen working with ML models you often need to know some basic functional properties of the model at hand, such as “What inputs does it expect?” and “What output does it produce?”. MLflow models can include the following additional metadata about model inputs and outputs that can be used by downstream tooling:Model Signature- description of a model’s inputs and outputs.Model Input Example- example of a valid model input.CLIshippedbrain [OPTIONS] COMMAND [ARGS]...Commandsupload- Deploy a model toapp.shippedbrain.com: create a REST endpoint and hosted model pageuploadcommandDeploy a model toapp.shippedbrain.com- create a REST endpoint and get a hosted model web pageOptions:-r,--run_id(TEXT) - The run_id of logged mlflow model  [required]-m,--model_name(TEXT) - The model name to display onapp.shippedbrain.com[required]-f,--flavor(TEXT) - The mlflow flow flavor of the model--help- Get help on how to use the 'upload' commandNB:The model must have been logged with validinput_exampleandsignature. For more information refer to the official mlflow documentation:MLflow Model Input ExampleMLflow Model SignatureExample:Run:shippedbrain upload --run_id <some_run_id> --model_name <my-model-name>Prompt:The command above will prompt the user to input their shipped brain email and password.email: your@email.com
password:If the environment variablesSHIPPED_BRAIN_EMAILorSHIPPED_BRAIN_PASSWORDare set, the respective prompt options will be skipped.Example:shippedbrain upload --run_id 6f252757005748708cd3aad75d1ff462 --model_name Some-Model-NamePython APITo publish a model programmatically you can either use theshippedbrain.upload_runorshippedbrain.upload_modelfunctions.####shippedbrain.upload_runPublish a model from an existingmlflowlog model run.Arguments:run_id(str) - run_id of logged modelmlflowrunemail(str) - shipped brain account email; ifSHIPPED_BRAIN_EMAILis set, argument can be left blankpassword(str) - shipped brain account password; ifSHIPPED_BRAIN_PASSWORDis set, argument can be left blankmodel_name(str) - model name to display onapp.shippedbrain.comExamplefromshippedbrainimportshippedbrainfromsklearn.ensembleimportRandomForestRegressorimportmlflowwithmlflow.start_run(run_name="YOUR_RUN_NAME")asrun:params={"n_estimators":5,"random_state":42}sk_learn_rfr=RandomForestRegressor(**params)shippedbrain.upload_run(run_id=run.info.run_id,email="YOUR_EMAIL",# can be left blank if env. var. SHIPPED_BRAIN_EMAIL is setpassword="YOUR_PASSWORD",# can be left blank if env. var. SHIPPED_BRAIN_PASSWORD is setmodel_name="YOUR_MODEL_NAME")####shippedbrain.upload_modelPublish a trained model directly toapp.shippedbrain.com.Arguments:flavor: (str) - valid mlflow model flavor; refer to theoriginal mlflow documentationemail(str) - shipped brain account email; if "SHIPPED_BRAIN_EMAIL" is set, argument can be left blankpassword(str) - shipped brain account password; if "SHIPPED_BRAIN_PASSWORD" is set, argument can be left blankmodel_name(str) - model name to display onapp.shippedbrain.cominput_example(pandas.DataFrames | numpy.ndarrays)- model inputs can be column-based (i.e DataFrames) or tensor-based (i.e numpy.ndarrays). A model input example provides an instance of a valid model input. More info. inMLflow Model Input Examplesignature(mlflow.types.schema.Schema) - the Model signature defines the schema of a model’s inputs and outputs. Model inputs and outputs can be either column-based or tensor-based. Column-based inputs and outputs can be described as a sequence of (optionally) named columns with type specified. ModelSignature can beinferredfrom training dataset and model predictions using or constructed by hand by passing an input and output (Schema)[https://mlflow.org/docs/latest/python_api/mlflow.types.html#mlflow.types.Schema].More info inMLflow Model Signature**kwargs- named arguments required by the selectedflavorThekwargsarguments depends on theflavorargument. Please verify the required named arguments of the select flavor inMLflow Python API.Examplefromshippedbrainimportshippedbrainimportpandasaspdfromsklearnimportdatasetsfromsklearn.ensembleimportRandomForestClassifierfrommlflow.models.signatureimportinfer_signatureiris=datasets.load_iris()iris_train=pd.DataFrame(iris.data,columns=iris.feature_names)clf=RandomForestClassifier(max_depth=7,random_state=0)clf.fit(iris_train,iris.target)signature=infer_signature(iris_train,clf.predict(iris_train))input_example={"sepal length (cm)":5.1,"sepal width (cm)":3.5,"petal length (cm)":1.4,"petal width (cm)":0.2}# Upload the sklearn modelshippedbrain.upload_model(email="YOUR_EMAIL",# can be left blank if env. var. SHIPPED_BRAIN_EMAIL is setpassword="YOUR_PASSWORD",# can be left blank if env. var. SHIPPED_BRAIN_PASSWORD is setmodel_name="MODEL_NAME",signature=signature,input_example=input_example,sk_model=clf,artifact_path="sklearn-model")Run and end-to-end example from this repoYou can find an example under the./examples/elastic_netdirectory.train_and_log.py: trains linear model and logs it to mlflowrequirements.txt: python requirements to run exampleBefore running the./examples/elastic_net/train_and_log.pyscript you should update the following variables:SHIPPED_BRAIN_EMAILwith your shipped brain account emailSHIPPED_BRAIN_PASSWORDwith your shipped brain account passwordMODEL_NAMEwith the name of your published model on shipped brainRun the example:Install the requirements:pip install -r ./examples/elastic_net/Train and publish the model:python ./examples/elastic_net/train_and_log.py --publishYou can omit the--publishflag if you do not want your model to be published onapp.shippedbrain.comUsing the CLITo upload the trained model toapp.shippedbrain.comyou just need to collect therun_idof the logged model:--model_name- specify the model name published onapp.shippedbrain.com--run_id- therun_idof the logged modelRun:shippedbrain upload --model_name ElasticWine --run_id <some_run_id>Typical workflow integration using the Python APIIfSHIPPED_BRAIN_EMAILand/orSHIPPED_BRAIN_PASSWORDare set argumentsemailandpasswordcan be left blank, respectivelyimportmlflowfromshippedbrainimportshippedbrain# other imports...SHIPPED_BRAIN_EMAIL="your_email@mail.com"SHIPPED_BRAIN_PASSWORD="your_password"MODEL_NAME="ElasticWine"withmlflow.start_run()asrun:# required to upload a valid model on shipped brainsignature=# use mlflow.models.signature.infer_signatureinput_example=# one input example of your data Union[pandas.DataFrame | numpy.ndarray]# train modelmodel=# trained model# log modelmlflow.sklearn.log_model(model,"model",signature=signature,input_example=input_example)print(f"run_id='{run.info.run_id}'")# publish modelshippedbrain.upload_run(email=SHIPPED_BRAIN_EMAIL,password=SHIPPED_BRAIN_PASSWORD,run_id=run.info.run_id,model_name=MODEL_NAME)