Develop a Machine Learning API (Application Programming Interface) using FastAPI.
This is the last project of the program, congratulations for all the work done until now.
In this project, we aim to help you to discover how to create an API that might be requested to interact with a ML model. This is an interesting solution when you want to keep your model architecture secret or to make your model available to users already having an API. By creating an API, and deploying it, your model can so that receive request using the internet protocol as presented by the illustration below.
Source : The benefits of Machine Learning APIs - UbiOps
You will have a minimal API demo with FastAPI, this will just serve you to make sure that everything works correctly. Then, you will have to make your own API, this allowing you to interact with a Machine Learning model, that is to say:
- Pass data through a request;
- Get the data in using the API;
- Apply the necessary processing;
- Submit the processed data to the ML model to make the predictions;
- Process the predictions obtained and return them as the API's response ot the input request.
Your task is to build an API integrating a ML model using FastAPI. Clone this repository to use it as a template, do not forget to change the readme at the end of the project. Your work should follow these next steps.
-
Build a ML model to predict the Sepsis(Data set here), during the 2 first weeks.
-
Build an API using Fast API, during the remaining weeks, to embed the ML model built.
Upon completion of your project, you are required to write a blog post on your thought process on medium, LinkedIn, personal blog, or any other suitable blogging site.
Machine Learning :
-
Excellent: Have a pipeline/function that takes inputs and make accurate predictions.
-
Good: Have a pipeline/function that takes inputs and make predictions.
-
Fair: Have a pipeline/function that takes inputs but faces bugs while doing predictions.
API :
-
Excellent: Have an API that works correctly, taking inputs multiple inputs and returning all the related predictions.
-
Good: Have an API that launches, makes predictions and returns results.
-
Fair: Have an API that launches but having bugs regarding inputs handling or returning predictions.
Install the required packages to be able to run the evaluation locally.
You need to have Python 3
on your system (a Python version lower than 3.10). Then you can clone this repo and being at the repo's root :: repository_name> ...
follow the steps below:
-
Windows:
python -m venv venv; venv\Scripts\activate; python -m pip install -q --upgrade pip; python -m pip install -qr requirements.txt
-
Linux & MacOs:
python3 -m venv venv; source venv/bin/activate; python -m pip install -q --upgrade pip; python -m pip install -qr requirements.txt
The both long command-lines have a same structure, they pipe multiple commands using the symbol ;
but you may manually execute them one after another.
- Create the Python's virtual environment that isolates the required libraries of the project to avoid conflicts;
- Activate the Python's virtual environment so that the Python kernel & libraries will be those of the isolated environment;
- Upgrade Pip, the installed libraries/packages manager to have the up-to-date version that will work correctly;
- Install the required libraries/packages listed in the
requirements.txt
file so that it will be allow to import them into the python's scripts and notebooks without any issue.
NB: For MacOs users, please install Xcode
if you have an issue.
-
Run the demo apps (being at the repository root):
FastAPI:
-
Demo
uvicorn src.demo_01.api:app --reload
-
Go to your browser at the following address, to explore the api's documentation :
-
Here are some ressources you would read to have a good understanding of FastAPI :
- Tutorial - User Guide
- Video - Building a Machine Learning API in 15 Minutes
- FastAPI for Machine Learning: Live coding an ML web application
- Video - Deploy ML models with FastAPI, Docker, and Heroku
- FastAPI Tutorial Series
- Http status codes
Feel free to make a PR or report an issue 😃.
Oh, one more thing, please do not forget to put a description when you make your PR 🙂.