-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (24 loc) · 734 Bytes
/
Copy pathapp.py
File metadata and controls
30 lines (24 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import json
import pandas as pd
import numpy as np
from pickle import load
from flask import Flask, request, jsonify
app = Flask(__name__)
model_file = 'prod_model.joblib'
prod_model = load(open( model_file, 'rb' ))
@app.route('/')
def index():
return 'you have arrived brother'
@app.route('/heartbeat')
def heartbeat():
return 'thump thump\n'
@app.route('/get_predictions/', methods=['POST'])
def predict(model=prod_model):
if request.method == 'POST':
data = json.loads( request.data )
X = pd.read_json(data)
predictions = model.predict(X).tolist()
return jsonify( predictions )
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get('PORT', 80)))