This repository defines a Flask web app for nbaspa.
The usage below assumes that you have used nbaspa
to download and clean your training data, build your
model, and produce impact ratings.
Install the requirements via pip
,
$ python -m pip install -r requirements.txt .
set an environment variable to indicate the path to your nbaspa
data directory,
$ export DATA_DIR=nba-data
and launch the web app.
$ python wsgi.py
You can change the --host
, --port
, and --config
. The --config
is either production
or
development
, and it refers to the Flask configuration of config.py
.
First, build the docker container
$ docker build --tag nbaspa_app .
Run the container with the port of your choice.
$ docker run --rm -p 8080:8080 -e PORT=8080 -e DATA_DIR=nba-data nbaspa_app
You may need to mount a filesystem to have access to a local data directory:
$ docker run \
--rm \
-p 8080:8080 \
-e PORT=8080 \
-e DATA_DIR=/opt/nba-data \
--mount type=bind,src=/opt/<PATH_TO_PARENT_DIRECTORY>,target=/opt \
nbaspa_app
Pull the gcloud
image:
$ docker pull gcr.io/google.com/cloudsdktool/cloud-sdk:latest
and authenticate gcloud
with service account credentials:
$ docker run \
--name gcloud-config \
gcr.io/google.com/cloudsdktool/cloud-sdk gcloud auth activate-service-account [email protected] --key-file=/path/key.json --project=PROJECT_ID
To change the configuration to point to Google Cloud Storage, supply the FLASK_CONFIG
environment variable:
$ docker run \
--rm \
--volumes-from gcloud-config \
-p 8080:8080 \
-e PORT=8080 \
-e DATA_DIR=<BUCKET_NAME>/<FOLDER_NAME> \
-e FLASK_CONFIG=production \
nbaspa_app
A huge thank you to Todd Birchard for his excellent Flask tutorial series. In particular, this repository uses
- Organizing Flask Apps with Blueprints,
- Demystifying Flask's Application Factory, and
- The Art of Routing in Flask
The docker image used for deploying the web application is adapted from the Google Cloud Run documentation. Additionally, this project leverages bulma for the styling.