ToDo:
- [x]
Install all project requirements with pip:
pip install -r requirements.txtWe'll be using Uvicorn, a fast ASGI server (it can run asynchronous code in a single process) to launch our application. Use the following command to start the server:
uvicorn app.api:app \
--host 0.0.0.0 \
--port 5000 \
--reload \
--reload-dir app \
--reload-dir modelsOr
uvicorn app.api:app --host 0.0.0.0 --port 8000 --reload --reload-dir deploy-GAISSA --reload-dir app In detail:
uvicorn app.api:appis the location of app (appdirectory >api.pyscript >appobject);--reloadmakes the server reload every time we update;--reload-dir appmakes it only reload on updates to theapp/directory;--reload-dir modelsmakes it also reload on updates to themodels/directory;
API running.
Now you can test the app:
We can now test that the application is working. These are some of the possibilities:
-
Visit localhost:5000
-
Use
curlcurl -X GET http://localhost:5000/
-
Access the API programmatically, e.g.:
import json import requests response = requests.get("http://localhost:5000/") print (json.loads(response.text))
-
Use an external tool like Postman, which lets you execute and manage tests that can be saved and shared with others.
Visit Swagger UI in http://localhost:5000/docs for documentation endpoint and select one of the models. The documentation generated via Redoc is accessible at the /redoc endpoint.
API User Interface in localhost:5000/docs endpoint.
To make an inference, click on the "Try it out" button and click execute.
You should obtain a "200" code response after executing the POST method of the model:
API response on Swagger UI.
API response on terminal.
The API in this project is freely inspired by the Made with ML tutorial: "APIs for Machine Learning" and FastAPI Lab.
Follow the guide https://madewithml.com/courses/mlops/api/
- Add new model class.
File: ../app/models.py
- Add a new class according to your new model, parent class is
Model(). - Make sure
NewModel.predict()method is implemented according to the model. - Add ML_task
- Add a new class according to your new model, parent class is
- Create a model schema.
File: ../app/schemas.py
- Create a schema with one example.
- Add endpoint.
File: ../app/api.py
- According to the new model information (Model Class and schema), add the endpoint to enable POST requests and make predictions using the model.



