-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
29 lines (25 loc) · 811 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
from flask import Flask, jsonify
from flask_restful import Resource, Api, reqparse
import pickle
app=Flask(__name__)
api=Api(app)
data_arg=reqparse.RequestParser()
data_arg.add_argument("id" , type=str)
# load ML model
model=pickle.load(open('model.pkl', 'rb'))
class predict(Resource):
def __init__(self):
self.model1 = model
def post(self):
# parse data from post request
args = data_arg.parse_args()
# convert string into int list
temp=args.id.strip('][').split(',')
temp = [float(i) for i in temp]
# predict output
out=self.model1.predict([temp])
# Return prediction
return jsonify({"message": int(out)})
api.add_resource(predict, '/')
if __name__ == '__main__':
app.run(debug=True)