Giter VIP home page Giter VIP logo

flask-example's Introduction

flask-example

Minimal example of serving a scikit-learn model over a Python server, using the following Python web frameworks

  • Flask
  • Tornado
  • Sanic (Forthcoming)
  • AIOHTTP (Forthcoming)

Steps for flask example

  1. Fit a scikit-learn model - I do some light preprocessing, then fit a simple ridge regression model on the California housing dataset. python train.py
  2. Run flask server cd flask && python server.py
  3. Hit the server curl -i -H "Content-Type: application/json" -X POST http://127.0.0.1:5000/api/v0/house_value -d @flask/sample_request.json
  4. Update the model by re-running step 1. This just takes a bootstrap sample, but in production, you might retrain in batch.
  5. Tell the server to reload the model from disk curl -X POST http://127.0.0.1:5000/api/v0/update
  6. Re-run the curl request from step 3 and note that you get a different answer!

Tornado Example

  • A little more involved, to try to test the async capabilities of this framework

Sanic

  1. Start the server: docker run --rm -v $(pwd):/root/sanic -p 8000:8000 -v /Users/timothysweetser/git/flask-example/artifacts:/root/sanic/artifacts -w /root/sanic tsweetser/sanic python main.py
  2. Hit the server with a sample request: curl localhost:8000/api/v0/house_value -d @flask/sample_request.json
  3. Retrain the model: python train.py
  4. Tell the server to reload the model: curl localhost:8000/api/v0/update
  5. Rerun step 2 and note that you get a different answer!

Aiohttp

  • TODO

Warning

  • This is not a real production system - no error handling, data validation, authentication, logging, etc etc etc
  • Please file an issue or make a PR if you see any glaring errors

flask-example's People

Contributors

hacktuarial avatar

Watchers

 avatar

Forkers

emaasit

flask-example's Issues

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.