This is a basic template of FastAPI. The App can also be deployed on docker (cf Docker).
The App predicts the class of the iris dataset.
Important: Once you clone the project, all the following commands have to be executed from the root directory of the project. If you have any troubles don't hesitate to reach me at : [email protected] or my linkedin
Warning : If you are using python 32-bit it may not work. Use docker instead, or go to src -> main.py and rename iris_predict.pkl
into iris_predict_32b.pkl
Install all package in requirements.txt
pip install -r requirements/api_requirements.txt
Then run the server with :
uvicorn src.main:app
or
python src/main_local.py
Once the API is running you can send requests --> How to send requests
For more information visit : https://fastapi.tiangolo.com/
Use the docker-compose.yml file to build the container and run the App inside using the following command :
docker-compose up
Once the container is running you can send requests --> How to send requests
For more information about Docker visit: https://www.docker.com/resources/what-container
Once the API is running go to : http://127.0.0.1:8000/docs
import json
import requests
# Respect the following structure.
data = {
"sepal_length": 5,
"sepal_width": 1,
"petal_length": 0,
"petal_width": 1
}
url = "http://127.0.0.1:8000/predictions"
response = requests.get(url, data=json.dump(data))
print(f"Predicted class : {response.json()['predicted']}")
Run request_sender.py
.
python src/tests/request_sender.py
Then enter the required data.