-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
41 lines (26 loc) · 966 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
32
33
34
35
36
37
38
39
40
41
from flask import Flask, request, url_for, redirect, render_template, jsonify
import xgboost
import pandas as pd
import joblib
import numpy as np
app = Flask(__name__)
reg1 =joblib.load('Xgb.pkl')
cols = ['LSTAT','RM','PTRATIO','INDUS']
@app.route('/')
def home():
return render_template("home.html")
@app.route('/predict', methods=['POST'])
def predict():
int_features = [int(x) for x in request.form.values()]
final = np.array(int_features)
final1 = pd.DataFrame([final], columns=cols)
prediction = reg1.predict(final1)
return render_template('home.html', pred='Predicted House price will be {}'.format(prediction))
@app.route('/predict_api', methods=['POST'])
def predict_api():
data = request.get_json(force=True)
data_unseen = pd.DataFrame([data])
prediction = reg1.predict(data_unseen)
return jsonify(prediction)
if __name__ == '__main__':
app.run(debug=True)