Prediction Service
The team proposed the use of FastAPI over Flask for prediction service API following a quick comparison of FastAPI vs Flask from here and here, with focus on the built in automatic swagger UI documentation support and data validation support.
The definitions of Flask and FastAPI are linked in the Resources section at the bottom of this page.
Starting the Prediction Service
Note: The repository can be accessed here
-
Install the requirements
poetry install
-
Set/update the environment variables (listed at the bottom of this page)
-
Run the following for database migration:
poetry run alembic upgrade head
-
Start the API server
uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload
(Ctrl + C to stop) -
Set up the MODEL_PREDICTION_ENDPOINT environment variable to point to the regression model prediction endpoint.
-
Access the swagger ui here -
http://localhost:8000/swagger
-
The API documentations is available here -
http://localhost:8000/api-docs
Variables
Variable | Default Value | Description |
---|---|---|
MODEL_PREDICTION_ENDPOINT |
http://localhost:5001/invocations
|
The endpoint URL for making model prediction requests. |
POSTGRES_HOST |
localhost
|
The hostname or IP address of the PostgreSQL server. |
POSTGRES_USER |
admin
|
The username for authenticating to the PostgreSQL database. |
POSTGRES_PASSWORD |
password
|
The password for authenticating to the PostgreSQL database. |
POSTGRES_DB |
bridgeai
|
The name of the PostgreSQL database to connect to. |
POSTGRES_PORT |
5432
|
The port number on which the PostgreSQL server is listening. |