This repo contains source code to deploy a simple Flask web application via Microsoft Azure. The purpose of this repo is to demo building the Flask app, deploying the app inside of Azure cloud, and creating a CI/CD pipeline with Github Actions.
The app hosts a simple Random Forest model endpoint for predicting salaries of NHL players. As of 7/2/2024, the application can be accessed at https://flask-ml-service-v2.azurewebsites.net/. Predictions can be made against the model by sending a POST request to the url with the /predict endpoint (https://flask-ml-service-v2.azurewebsites.net/predict). Alternatively, running ./make_predictions_request_azure_app.sh from the root of this directory will send a POST request for a sample dataset of 10 players to the app endpoint. The source code of the actual Flask app can be found in app.py
NOTE: Considering the purpose of this app is geared towards building a CI/CD pipeline with GitHub Actions, creating a good performing model was not a focal point. In fact, it is a poor performing model from a metric standpoint, intentionally.
The Makefile includes five targets in total. Note, it is recommended to create a virtual environment prior to running make install. If you want to create a conda environment instead of a traditional venv environment, commands to do so are run via make install_conda_env target (described later below):
install: install all libraries set inrequirements.txtusing piplint: runs ruff against all python files in repo for linting purposesformat: runs black against all python files in repo for formatting purposestest: test that the app endpoint returns a200response codeinstall_conda_env: installs all packages set in conda_env.yml inside a conda environment (assumes that a conda environment named.flask-ml-cloud-serverless-demohas already been created) and activates that environment. The purpose being that, if running locally, users can run the Flask app using thecondaenvironment if desired instead of a traditionalpypienvironment.
On pushing a new commit to the main branch, GitHub Actions has been setup to run three commands from the Makefile:
make install
make lint
make test
The GitHub Actions workflow can be seen in .github/workflows/main.yml.
Running ./make_predictions_request_azure_app.sh from the root of this directory will send a POST request for a sample dataset of 10 players to the app endpoint. One record of the sample data (as a python dictionary) looks like such:
sample_record = {
"plusMinus": {
"0": -4,
},
"Position": {
"0": "D",
},
"G": {
"0": 0,
},
"A1": {
"0": 1,
},
"GP": {
"0": 36,
},
"Grit": {
"0": 139,
},
"TOI%": {
"0": 23.8,
},
"xGA": {
"0": 24.3,
},
"xGF": {
"0": 16.7,
},
"First Name": {
"0": "Alex",
},
"Last Name": {
"0": "Biega",
},
"Team": {
"0": "VAN",
}