Last active
July 18, 2017 23:48
-
-
Save francoismarceau29/a9e0164f8414a994aeaa1b2a77efabc1 to your computer and use it in GitHub Desktop.
Basic Flask template for AWS Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.externals import joblib | |
from boto.s3.key import Key | |
from boto.s3.connection import S3Connection | |
from flask import Flask | |
from flask import request | |
from flask import json | |
BUCKET_NAME = 'your-s3-bucket-name' | |
MODEL_FILE_NAME = 'your-model-name.pkl' | |
MODEL_LOCAL_PATH = '/tmp/' + MODEL_FILE_NAME | |
app = Flask(__name__) | |
@app.route('/', methods=['POST']) | |
def index(): | |
payload = json.loads(request.get_data().decode('utf-8')) | |
prediction = predict(payload['payload']) | |
data = {} | |
data['data'] = prediction[-1] | |
return json.dumps(data) | |
def load_model(): | |
print 'Loading model from S3' | |
def predict(data): | |
print 'Making predictions' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment