This project is a simple API making the AI servicces available over the HTTP protocol. It is made with flask and also uses numpy, Pillow as well as tensorflow for loading the AI model.
Here's the steps you must follow to make the API work :
All the examples are shown for Ubuntu/Debian
- Install python
sudo apt install python3
- Install pip, the python package manager
sudo apt install python3-pip
- Install the project dependencies. This is quite simple since the project has a requirements.txt file. You can install the dependencies by typing:
pip install - r requirements.txt
- Start the project
flask run
- You can see that the API start on port 5000.
- The API only has 2 routes :
- /ping -> to check if the API is indeed running
- /predict_image -> take an image in paramaters and returns the AI result
-
To the preditc an image using Postman :
- Create a post request to http://{SERVER_IP}:5000/predict_image
- Go to body, select "form-data", name the Key "image" and select "file" as a type, then select your image in the "value" column
- Press send
-
Here's the code generated by postman for an axios request (Node.js) :
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('image', fs.createReadStream('image_test.jpeg'));
var config = {
method: 'post',
maxBodyLength: Infinity,
url: 'http://ocalhost:5000/predict_image',
headers: {
...data.getHeaders()
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
