-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (26 loc) · 840 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
from flask import Flask, jsonify, request
import numpy as np
import joblib
import flask
app = Flask(__name__)
# To load a model
lr = joblib.load('model.pkl')
# Open when we on the root url
@app.route('/')
def hello_world():
return 'Hello World!'
# Html page rendered
@app.route('/index')
def index():
return flask.render_template('index.html')
# Will make predictions
@app.route('/predict', methods=['POST'])
def predict():
to_predict_list = request.form.to_dict()
to_predict_list = list(to_predict_list.values())
to_predict_list = np.array(list(map(float, to_predict_list))).reshape(1, -1)
print(to_predict_list)
prediction = lr.predict(to_predict_list)
return jsonify({'prediction': list(prediction)})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)