Example #1
from flask import Flask, current_app
from flask import jsonify, redirect, url_for, escape
from flask import request, session
from flask import g as Globals

from actions import update

app = Flask(__name__, static_url_path='')
app.model = 0

def static_proxy(path):
    return app.send_static_file(path)

def index():
    return app.send_static_file('index.html')

@app.route('/api', methods=['POST'])
def api():
    blob = request.get_json()
    app.model = update(blob, app.model)

    return jsonify({
        'model': app.model

Example #2
from geopy import geocoders

import dill
#dill.settings["recurse"] = True

import requests
from bokeh.plotting import figure
from bokeh.embed import components

import pandas as pd

app = Flask(__name__)

app.vars = {}
with open("knn_model.pkl", "rb") as f:
    app.model = dill.load(f)

def main():
    return redirect('/index')

@app.route('/index', methods=['GET', 'POST'])
def index():
    if request.method=='GET':
        return render_template('index.html')
        app.vars["street"] = request.form["street"]
        app.vars["city"] = request.form["city"]
        app.vars["state"] = request.form["state"]
        app.vars["numberofblightviolationtickets"] = request.form["numberofblightviolationtickets"]
        app.vars["numberofcrimes"] = request.form["numberofcrimes"]
from __future__ import unicode_literals
import json
from flask import Flask, request
from sklearn.externals import joblib
from settings import MODEL_FILENAME

app = Flask("Fraud Detection")

# load model at startup time
app.model = joblib.load(MODEL_FILENAME)

@app.route(u"/predict", methods=[u"POST"])
def predict_fraud():
    input_data = request.get_json()
    if u"features" not in input_data:
        return json.dumps({u"error": u"No features found in input"}), 400
    if not input_data[u"features"] or not isinstance(input_data[u"features"], list):
        return json.dumps({u"error": u"No feature values available"}), 400
    if isinstance(input_data[u"features"][0], list):
        results = app.model.predict_proba(input_data[u"features"]).tolist()
        results = app.model.predict_proba([input_data[u"features"]]).tolist()
    return json.dumps({u"scores": [result[1] for result in results]}), 200
Example #4
import os
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename
import cPickle as pkl
from single_img_processing import PreprocessPredict

app = Flask(__name__)

app.config['UPLOAD_FOLDER'] = 'static/uploads/'
app.config['ALLOWED_EXTENSIONS'] = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

app.model = None

def load_pickle():
    print 'Loading Model...'
    app.model = pkl.load(open('model.pkl', 'rb'))

def predict_watch_type(img):
    return app.model.predict()

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']

def index():
    return render_template('index.html', prediction='This is an example of a casual watch', img_path='static/uploads/audemar.png')

@app.route('/upload', methods=['POST'])
Example #5
labels_json = codecs.open(config_dir + '/labels.json', 'r', encoding).read()
app.labels = json.loads(labels_json)

# Cubes Model
print 'Loading Cubes Model...'
cubes_conn = httplib.HTTPConnection(
  app.appjson.get('cubes_hostname') or 'localhost',
  app.appjson.get('cubes_port') or 5000 
  cubes_conn.request('GET', "/model")
except Exception, e: 
  raise Exception('Failed to access the Cubes server...(' + str(e) + ')')

app.model = json.loads(

# Cubes Dimensions
app.dimensions = []
for name, elem in app.model.get('dimensions').items():
  levels = []
  for level_name in elem.get('levels').keys():
    if level_name == 'default': break
    else: levels.append(str(level_name))

      name = str(name), 
      label = app.labels.get('dimensions').get(name) or name, 
      levels = levels