-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
33 lines (26 loc) · 769 Bytes
/
app.py
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
31
32
33
import flask
from flask import Flask, jsonify, request
import json
import pickle
from data_input import data_in
import numpy as np
app = Flask(__name__)
def load_models():
file_name = "models/model_file.p"
with open(file_name, 'rb') as pickled:
data = pickle.load(pickled)
model = data['model']
return model
@app.route('/predict', methods=['GET'])
def predict():
# parse input features from request
request_json = request.get_json()
x = request_json['input']
x_in = np.array(x).reshape(1,-1)
# load model
model = load_models()
prediction = model.predict(x_in)[0]
response = json.dumps({'response': prediction})
return response, 200
if __name__ == '__main__':
application.run(debug=True)