Deploying a Machine Learning Model as a REST API with Flask

This is perhaps the best known database to be found in the pattern recognition literature. The data set contains 3 classes of 50 instances each, where each class refers to a type of iris plant. One class is linearly separable from the other 2; the latter are NOT linearly separable from each other.
Predicted attribute: class of iris plant.
# Clone the project
git clone https://github.com/AchilleasKn/flask_api_python.git
# Change Directory
cd flask_api_python/api
# Install pip for Python3
apt install python3-pip
# Install the requirements
pip3 install -r requirements.txt
# Run the script in Python
python3 api.py
This image is based on the python:3.6-jessie official image
This image is based on Alpine Linux image which is a lightweight version of Linux
# Clone the project
git clone https://github.com/AchilleasKn/flask_api_python.git
# Change Directory
cd flask_api_python/api
# Build the docker image
docker build -t flask_api .
# For the alpine version run the following
#docker build -f Dockerfile.alpine -t flask_api .
# Run the flask_api image and expose the 5000 port
docker run -d -p 5000:5000 flask_api
# To see the running containers
docker ps
# To see the logs of our running container
docker logs <Container ID>
# Pull the docker image
docker pull achilleaskn/flask_api_python:latest
# For the alpine version run the following
#docker pull achilleaskn/flask_api_python:alpine.latest
# Run the flask_api image and expose the 5000 port
docker run -d -p 5000:5000 achilleaskn/flask_api_python:latest
# For the alpine version run the following
#docker run -d -p 5000:5000 achilleaskn/flask_api_python:alpine.latest
# To see the running containers
docker ps
# To see the logs of our running container
docker logs <Container ID>
Once it is running, the API can be queried using HTTP POST requests. I recommend using postman for testing.
URL: http://0.0.0.0:5000/predict
{
"feature_array":[4.9, 2.9, 1.2, 0.3]
}
The response should look like this:
{
"prediction": [
0
]
}
{
"feature_array":[6.4, 3.2, 4.5, 1.5]
}
The response should look like this:
{
"prediction": [
1
]
}
{
"feature_array":[6.2, 3.1, 5.3, 2.4]
}
The response should look like this:
{
"prediction": [
2
]
}
Content type
Image
Digest
Size
456.1 MB
Last updated
almost 8 years ago
docker pull achilleaskn/flask_api_python