-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (26 loc) · 753 Bytes
/
app.py
File metadata and controls
31 lines (26 loc) · 753 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
31
import pickle
import flask
from flask import Flask, jsonify, request
import json
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():
# stub input features
# parse input features from request
#request_json = request.get_json()
#x = float(request_json['input'])
args = request.args
x = float(args['input'])
# load model
model = load_models()
prediction = model.predict([[x]])[0]
response = json.dumps({'response': prediction})
return response, 200
if __name__ == '__main__':
app.run(debug=True)