Send a POST request to infer your ML model with FastAPI
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.
I prefer conda but you do you. You need at least python 3.7
Create environment (if you don't already have one)
conda create -n serve_scikit_model python=3.7
conda activate serve_scikit_model
pip install serveitlearn
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
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
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size serveitlearn-0.1.1-py3-none-any.whl (9.7 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size serveitlearn-0.1.1.tar.gz (4.2 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for serveitlearn-0.1.1-py3-none-any.whl