Example #1
0
from flask import render_template, Flask, request, Response
import ipdb
import json
import pickle
import numpy as np

app = Flask(__name__)
app.model = None
app.vectorizer = None


@app.route("/")
@app.route("/index")
def index():
    return "Hello, world!"


@app.route("/refresh", methods=["POST"])
def refresh():
    # ipdb.set_trace()
    app.model = pickle.load(request.files["filedata"])
    print "Model successfully uploaded"
    return "Success"


@app.route("/vectorizer", methods=["POST"])
def vector():
    app.vectorizer = pickle.load(request.files["filedata"])
    print "Vectorizer successfully uploaded"
    return "Success"
Example #2
0
print "Loading labels.json..."
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
)
try:
    cubes_conn.request("GET", "/model")
except Exception, e:
    raise Exception("Failed to access the Cubes server...(" + str(e) + ")")

app.model = json.loads(cubes_conn.getresponse().read().decode(encoding))

# 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))

    app.dimensions.append(
        CubesDimension(name=str(name), label=app.labels.get("dimensions").get(name) or name, levels=levels)
    )