Code Monkey home page Code Monkey logo

flask-celery-ml's Introduction

Handling ML Predictions in a Flask App

created by Austin Poor

This repo demonstrates a technique for handling long-running processes (like ML model predictions) inside a Flask app, by passing them off to Celery.

While this is just a simple example, the same workflow could help in cases where you're performing slow, complicated tasks like making ML predictions, building recommendations, or updating a database.

Demo

The app is composed of Redis (the broker and backend for Celery), a Celery worker, and then the Flask app.

The Flask app is composed of a simple HTML landing page and two API endpoints.

The HTML page has 4 range sliders, allowing you to choose values for the width and height of the iris's sepal and petal, for prediction.

When you click the Submit button, a javascript function sends the parameters in a POST request to /api/predict, which schedules the prediction with the Celery worker, and returns the taskid that will store the result.

Then, after making the request, the browser polls the second API endpoint (/api/get-result/<taskid>) until the status changes from pending to SUCCESS (or to an error). It then updates the status and the prediction table.

Instructions to Run

Requirements

  • Python 3.6+
  • scikit-learn
  • Docker & docker-compose
  1. Download the repo
  2. Train the ml model with the train.py script
  3. Build and run the containers with docker-compose up --build
  4. Then go to localhost:5000

flask-celery-ml's People

Contributors

a-poor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.