Skip to main content

Send a POST request to infer your ML model with FastAPI

Project description

Introduction

You may train the most awesome model in the world but if you can't deploy it then people can enjoy your work. Deoployment in ML has always been an issue that we never gets discussed in courses. It is assumed that you can just do this without any training. However, in my experience, I found it not as easy to deploy my models with much flexibility. That's why I decided to create serve-it-learn. The idea for the name purely from Vincent D. Warmerdam's brain fart.

Installation

I prefer conda but you do you. You need at least python 3.7

  1. Create environment (if you don't already have one) conda create -n serve_scikit_model python=3.7

  2. Activate it conda activate serve_scikit_model

  3. Install it pip install serveitlearn

Getting started

This is a dummy example. You need to add your own code to load the model and perform predictions.

from serveitlearn.decorator import app, predict, initalize

# Declare function that initalizes the model and any other data sources
@initalize
def my_initalization():
    pass

# Declare function that will make the prediction based on the query

@predict
def my_prediction(query_dict):
    pass

Full example

If you want to see a full example, then you have to take few more after installation because it requires loading scikit-learn model and I didn't release a pickle or joblib due to potiential security reasons.

The example, loads Iris dataset, trains a simple SVC model and deploys it using `serveitlearn.

$ git clone https://github.com/samarpan-rai/serveitlearn

$ cd serveitlearn/examples/

$ pip install -r requirements.txt

$ uviron

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serveitlearn-0.1.1.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

serveitlearn-0.1.1-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page