As part of MLOps, this assignment aims to deploy the ML model on a web server using Fast Api. FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints. For keeping the task simple a simple MNIST digit classifier is chosen to serve for this purpose. The API is used in the Swagger UI for checking the model prediction. For monitoring the health of the server Prometheus and Grafana is used. Everything is done in Docker container.
FastApi_implement.py
This is the main code file which includes codes for deployment of the model on fastapi. It also contains custom metrics of prometheus to monitor API health.MNIST_Model.keras
is the keras trained model trained on MNIST digit data.Dockerfile
is a text file that contains instructions for building a Docker image.docker-compose.yml
is the configuration file that is used to define and run multi-container Docker applications. It contains service which is responsible for the creation of the container, we have total 4 containers web1, web2, prometheus, grafana. They also have their respective ports on which their servers will run.prometheus.yml
this .yml file specifies which servers to monitor, for our case it is web1, web2..dockerignore
file contains name of the files which wont be considered by docker while making the docker image.A7 -Dockerize and Monitor FastAPI for MNIST digit prediction.pdf
contains the problem statement of the assignment.result
contains the screen shots of the prometheus and grafana UI.requirements.txt
contains list of all depedencies
- Change directory to the one containing FastAPI_implement.py and MNIST_model.keras.
- Create Dockerfile in the same directory.
- Define all the configurations about the container in docker-compose.yml file.
- To track the fastAPI server create prometheus.yml file.
- To get the docker image type in the terminal
docker-compose up --build
- Once docker image is set up for later use only type
docker-compose up
- If everything works fine the servers can be accessed from Fastapi ![http://localhost:8000/docs] Prometheus ![http://localhost:9090] Grafana ![http://localhost:3000]
- In Grafana first add datasource from promtheus to get the metrics
- Next set up the dashboard Here following SS are attached for example