This repository shows an example using FastAPI and Docker to run a simple machine learning model (Random Forest Classifier) trained with the scikit-learn library.
There are two important scripts in this repository:
- generate-model.py: This file downloads the dataset (mnist_784), trains the model (Random Forest Classifier) and generates a new file with the already trained model.
- app.py: This file creates an endpoint to process HTTP requests to get a prediction using the pre-trained model
Note: It is mandatory to have Python and Pip installed in your environment
To install the dependencies run the following command:
pip install -r requirements.txt
To train the model run the following command:
python generate-model.py
To run the FastAPI application run the following command:
uvicorn app:app --reload
To build the docker container run the following command:
docker build -t hfmartinez/ml-fastapi .
To run the docker container use the following command:
docker run --name test -p 5500:5500 hfmartinez/ml-fastapi