Skip to the content.

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

  1. Install the requirements poetry install

  2. Set/update the environment variables (listed at the bottom of this page)

  3. Run the following for database migration: poetry run alembic upgrade head

  4. Start the API server uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload (Ctrl + C to stop)

  5. Set up the MODEL_PREDICTION_ENDPOINT environment variable to point to the regression model prediction endpoint.

  6. Access the swagger ui here - http://localhost:8000/swagger

  7. 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.


Resources

  1. What is Flask?

  2. What is FastAPI?