-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
71 lines (57 loc) · 1.81 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, request, url_for, render_template
import pickle
import numpy as np
import json
app = Flask(__name__)
app.config.update(
dict(SECRET_KEY="powerful secretkey", WTF_CSRF_SECRET_KEY="a csrf secret key")
)
__locations = None
__data_columns = None
model = pickle.load(open("bangalore_home_prices_model.pickle","rb"))
def get_estimated_price(input_json):
try:
loc_index = __data_columns.index(input_json['location'].lower())
except:
loc_index = -1
x = np.zeros(244)
x[0] = input_json['sqft']
x[1] = input_json['bath']
x[2] = input_json['bhk']
if loc_index >= 0:
x[loc_index] = 1
result = round(model.predict([x])[0],2)
return result
def get_location_names():
return __locations
def load_saved_artifacts():
print("Loading the saved artifacts...start !")
global __data_columns
global __locations
global model
with open("columns.json") as f:
__data_columns = json.loads(f.read())["data_columns"]
__locations = __data_columns[3:]
@app.route("/")
def index():
return render_template('index.html')
@app.route("/prediction", methods=["POST"])
def prediction():
if request.method == 'POST':
input_json = {
"location": request.form['sLocation'],
"sqft": request.form['Squareft'],
"bhk": request.form['uiBHK'],
"bath": request.form['uiBathrooms']
}
result = get_estimated_price(input_json)
if result > 100:
result = round(result/100, 2)
result = str(result) + ' Crore'
else:
result = str(result) + ' Lakhs'
return render_template('prediction.html', result=result)
if __name__ == "__main__":
print("Starting Python Flask Server")
load_saved_artifacts()
app.run(debug=True)