-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (25 loc) · 997 Bytes
/
app.py
File metadata and controls
36 lines (25 loc) · 997 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
32
33
34
35
36
from flask import Flask, jsonify, Response, request
from joblib import load
import sys
import traceback
app = Flask(__name__)
@app.route('/', methods = ['POST'])
def predict():
try:
data = request.get_json()
sepal_length = float(data['sepal_length'])
sepal_width = float(data['sepal_width'])
petal_length = float(data['petal_length'])
petal_width = float(data['petal_width'])
plant = [[sepal_length, sepal_width, petal_length, petal_width]]
sc = load('predictor/standard_scaler.joblib')
classifier = load('predictor/classifier.joblib')
plant = sc.transform(plant)
predicted_class = classifier.predict(plant)
return jsonify({'class': predicted_class[0]})
except:
etype, value, tb = sys.exc_info()
print(traceback.print_exception(etype, value, tb))
return Response(status=500)
if __name__ == '__main__':
app.run(host= '0.0.0.0')