Flask for web deployments

Let's begin by getting the imports out of the way:

import loggingimport flaskimport osimport numpy as npfrom flask import Flask, jsonify, render_template, requestfrom sklearn.externals import joblib

I am assuming that as a programmer, you can pick up Flask basics outside this book. Even then, for the sake of completeness, I am adding the main ideas that are relevant to us:

  • The main web app is defined in the Flask module, which is imported from Flask
  • jsonify converts any JSON-friendly dictionary into a JSON that can then be returned to the user
  • render_template is how we expose HTML pages and web interfaces to our users

Let's begin by declaring our app first:

app = Flask(__name__)

Next, we will use the route ...

Get Natural Language Processing with Python Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.