-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
51 lines (41 loc) · 1.43 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
# -*- coding: utf-8 -*-
"""app.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1iAxCWG6KFy__iY_277BYQemE4sKwqust
"""
import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
@app.route('/')
def home():
return render_template('sample.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
if request.method == 'POST':
sqft = int(request.form['sqft'])
bath = int(request.form['bathrooms'])
bhk = int(request.form['bedrooms'])
location = request.form['location']
model_list = [sqft, bath, bhk, location]
x_col = model.get_booster().feature_names
model_input = []
model_input.append(model_list[0])
model_input.append(model_list[1])
model_input.append(model_list[2])
for col in X[x_col[3:]]:
if X[[col]].columns == model_list[3]:
model_input.append(1)
else:
model_input.append(0)
data = np.array([model_input])
my_prediction = model.predict(data)
output = round(my_prediction[0], 3)
return render_template('sample.html', prediction_text='Price of the property would be around ₹ {}Lakhs'.format(output))
if __name__ == "__main__":
app.run(debug=True)