-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (24 loc) · 1022 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
from flask import Flask, request, url_for, redirect, render_template, jsonify
from xgboost import XGBRegressor
from datetime import datetime
import numpy as np
from src.utils.common_func import info_parser
model = XGBRegressor()
hdb_details = pd.read_csv('resale-flat-prices/hdb-property-information.csv',
usecols=['blk_no', 'street', 'year_completed'])
model.load_model('model_xgb.json')
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
# predict function, POST method to take in inputs
@app.route('/predict', methods=['POST', 'GET'])
def predict():
feature_list = request.form.to_dict()
print(feature_list)
new_features = info_parser(feature_list, mrt_array, malls_array, hdb_details)
prediction = model.predict(new_features)
return render_template('index.html',
prediction_text=f"Your house is predicted to be valued at ${prediction[0]:.2f}")
if __name__ == "__main__":
app.run(debug=True)