Suggest to run this in a virtual environment then install the requirements.
pip install -r requirements.txt
-
Fire up a terminal in this directory and run this command
export FLASK_APP=app.py && flask run
1.1 To run in httpsexport FLASK_APP=app.py && flask run --cert=cert.pem --key=key.pem
-
Then navigate to
localhost:5000/predict
-
Upload the data file in
./data
(Suggest to trypickle_scikit_lr_compas_xtest_pkl.sav
) -
Wait for results
-
cd to api-model-server directory and run:
source venv/bin/activate
-
To run a regression model server, run:
bash regression_run_http.sh
to start a HTTP server on port 5000and
bash regression_run_https.sh
to start a HTTPS server on port 5000 -
To run a classification model server, run:
bash classification_run_http.sh
to start a HTTP server on port 5001and
bash classification_run_https.sh
to start a HTTPS server on port 5001
-
Fire up a terminal in this directory and run this command
flask app
-
Run this curl command (replace the file path accordingly)
curl -X POST -F file=@"./data/pickle_scikit_lr_compas_xtest_pkl.sav" http://localhost:5000/predict
-
Or run this curl command (replace the value accordingly)
This will return 0
curl -X POST http://localhost:5000/predict_one -H "Content-Type: application/x-www-form-urlencoded" -d "count=0&gender=0&race=5&charge=1&age=2"
This will return 1
curl -X POST http://localhost:5000/predict_one -H "Content-Type: application/x-www-form-urlencoded" -d "count=10&gender=1&race=5&charge=1&age=2"
-
Or run this curl command (replace the value accordingly) for mulitple dataset
curl -X POST http://localhost:5000/predict_all -H 'Content-Type: application/json' -d '{"input": "[[0, 1, 0, 0, 0], [0, 1, 0, 0, 0], [0, 1, 3, 11, 1], [0, 1, 2, 0, 0], [0, 1, 5, 2, 0], [1, 0, 0, 1, 0], [0, 1, 5, 0, 0], [0, 1, 0, 1, 1], [0, 1, 0, 9, 0], [1, 1, 0, 1, 0]]"}'
-
Note that this is not the only way to write a model server
- The response might differ from server to server.
- The way to upload the input data could differ too.