created by Austin Poor
This is a quick proof of concept for creating a Flask web API as a front-end for long-running tasks -- like making ML model predictions.
It uses the distributed task queue, Celery, to pass heavy processing off to worker nodes while freeing up the Flask server for handling requests.
When a user makes a request, the API diverts the processing to a Celery worker and responds with a location where the result will be stored when the processing is complete.
You can start redis, celery, and the flask api with the included dockerfiles and docker-compose file (with the command $ docker-compose up) or you can do the following:
- Install the required packages in requirements.txt, if necessary.
- Run build-model.py to train a
scikit-learnlogistic regression model on the iris dataset and then save it to themodels/directory. - Start up Redis on port
6379 - Start up Celery with the command:
$ celery -A tasks worker - Run app.py to start up the
Flaskserver
Then, the API will be up and running at: http://localhost:5000/
You can test the server by running test-api.py.