-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
35 lines (24 loc) · 878 Bytes
/
model.py
File metadata and controls
35 lines (24 loc) · 878 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
# Build Simple model for practice with Docker and AWS
import pandas as pd
from flask import Flask, jsonify, request, render_template
from sklearn.externals import joblib
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
data = request.values
data = pd.DataFrame(data, index=[0])
prediction = '${:,.2f}'.format(list(reg.predict(data))[0] * 1000)
return render_template('index.html', label=prediction)
@app.route('/predictapi', methods=['POST'])
def predictapi():
json_ = request.get_json()
query_df = pd.DataFrame(json_, index=[0])
prediction = list(reg.predict(query_df))
return jsonify({'prediction': prediction})
if __name__ == '__main__':
reg = joblib.load('model.pkl')
app.run(host='0.0.0.0', port=5000)