forked from dwhitena/dockerized-DS-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
39 lines (31 loc) · 1.2 KB
/
api.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
34
35
36
37
38
39
from flask import Flask
from flask_restful import Resource, Api
from flask_restful import reqparse
from utils import makeprediction
app = Flask(__name__)
api = Api(app)
class Prediction(Resource):
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('slength', type=float, help='slength cannot be converted')
parser.add_argument('swidth', type=float, help='swidth cannot be converted')
parser.add_argument('plength', type=float, help='plength cannot be converted')
parser.add_argument('pwidth', type=float, help='pwidth cannot be converted')
args = parser.parse_args()
prediction = makeprediction.predict([
args['slength'],
args['swidth'],
args['plength'],
args['pwidth']
])
print "THE PREDICTION IS: " + str(prediction)
return {
'slength': args['slength'],
'swidth': args['swidth'],
'plength': args['plength'],
'pwidth': args['pwidth'],
'species': prediction
}
api.add_resource(Prediction, '/prediction')
if __name__ == '__main__':
app.run(debug=False)