-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
128 lines (105 loc) · 4.44 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from flask import Flask, render_template, jsonify, request
import data
import pickle
import requests
import numpy as numpy
import sklearn
from sklearn.preprocessing import StandardScaler
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, func, desc
import sqlalchemy.dialects.sqlite
import datetime as dt
import pandas as pd
import os
app = Flask(__name__,
static_folder='static',
template_folder='templates')
#load the ml model which we have saved earlier in .pkl format
model = pickle.load(open('model1.pkl', 'rb'))
@app.route('/index')
def home():
return render_template('index.html')
#define the route for post request method
@app.route("/predict", methods=['POST'])
#define the predict function which is going to predict the results from ml model based on the given values through html form
def predict():
if request.method == 'POST':
Total_Assessed_Value = float(request.form['Assessed_Value'].replace(',','').replace('$',''))
Parcel_Acreage = float(request.form['Acreage'])
Vacant = request.form['Vacant']
if (Vacant == 'Yes'):
Parcel_Vacancy_Y = 1
Parcel_Vacancy_N = 0
else:
Parcel_Vacancy_Y = 0
Parcel_Vacancy_N = 1
Property_Class = request.form['Property_Class']
if (Property_Class == 'Agricultural'):
Class_Code_Translated_Agricultural = 1
Class_Code_Translated_Commercial = 0
Class_Code_Translated_Exempt = 0
Class_Code_Translated_Industrial = 0
Class_Code_Translated_Residential = 0
elif (Property_Class =='Commercial'):
Class_Code_Translated_Agricultural = 0
Class_Code_Translated_Commercial = 1
Class_Code_Translated_Exempt = 0
Class_Code_Translated_Industrial = 0
Class_Code_Translated_Residential = 0
elif (Property_Class == 'Exempt'):
Class_Code_Translated_Agricultural = 0
Class_Code_Translated_Commercial = 0
Class_Code_Translated_Exempt = 1
Class_Code_Translated_Industrial = 0
Class_Code_Translated_Residential = 0
elif (Property_Class == 'Industrial'):
Class_Code_Translated_Agricultural = 0
Class_Code_Translated_Commercial = 0
Class_Code_Translated_Exempt = 0
Class_Code_Translated_Industrial = 1
Class_Code_Translated_Residential = 0
elif (Property_Class == 'Residential'):
Class_Code_Translated_Agricultural = 0
Class_Code_Translated_Commercial = 0
Class_Code_Translated_Exempt = 0
Class_Code_Translated_Industrial = 0
Class_Code_Translated_Residential = 1
# open file pickle.load x and y
new_data= [[Total_Assessed_Value, Parcel_Acreage, Parcel_Vacancy_Y, Parcel_Vacancy_N, Class_Code_Translated_Agricultural, Class_Code_Translated_Commercial, Class_Code_Translated_Exempt, Class_Code_Translated_Industrial, Class_Code_Translated_Residential]]
# apply x scaler to xdata
Xscaler = pickle.load(open("Xscaler1.pkl", "rb"))
Yscaler = pickle.load(open("Yscaler1.pkl", "rb"))
scaled = Xscaler.transform(new_data)
# for inverse transformation
#inversed = scaler.inverse_transform(scaled)
#print(inversed)
prediction = Yscaler.inverse_transform(model.predict(scaled))
# apply y scaler.inverse transform
output = round(prediction[0],2)
print (output)
if output: #condition for invalid values
return render_template('index.html', prediction_text ="This property is worth ${:,.2f}".format(output))
#html form to be displayed on screen when no values are inserted; without any output or prediction
else:
return render_template('index.html')
@app.route('/property', methods=['GET'])
def database_data():
propertydata = data.get_db_data()
response = jsonify(propertydata)
response.headers.add('Access-Control-Allow-Origin','*')
return response
@app.route('/explore')
def explore():
return render_template('explore.html')
@app.route('/')
def bio():
return render_template('bio.html')
@app.route('/comps')
def comps():
return render_template('comps.html')
if __name__ == '__main__':
# app.run(debug=True)
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)