ErickMVdO commited on
Commit
e745180
1 Parent(s): 3a43c1a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +242 -0
app.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch, numpy as np, pandas as pd
3
+ import skimage
4
+ import pickle
5
+
6
+ defaultColumns = ['MSSubClass',
7
+ 'MSZoning',
8
+ 'LotFrontage',
9
+ 'LotArea',
10
+ 'Street',
11
+ 'Alley',
12
+ 'LotShape',
13
+ 'LandContour',
14
+ 'Utilities',
15
+ 'LotConfig',
16
+ 'LandSlope',
17
+ 'Neighborhood',
18
+ 'Condition1',
19
+ 'Condition2',
20
+ 'BldgType',
21
+ 'HouseStyle',
22
+ 'OverallQual',
23
+ 'OverallCond',
24
+ 'YearBuilt',
25
+ 'YearRemodAdd',
26
+ 'RoofStyle',
27
+ 'RoofMatl',
28
+ 'Exterior1st',
29
+ 'Exterior2nd',
30
+ 'MasVnrType',
31
+ 'MasVnrArea',
32
+ 'ExterQual',
33
+ 'ExterCond',
34
+ 'Foundation',
35
+ 'BsmtQual',
36
+ 'BsmtCond',
37
+ 'BsmtExposure',
38
+ 'BsmtFinType1',
39
+ 'BsmtFinSF1',
40
+ 'BsmtFinType2',
41
+ 'BsmtFinSF2',
42
+ 'BsmtUnfSF',
43
+ 'TotalBsmtSF',
44
+ 'Heating',
45
+ 'HeatingQC',
46
+ 'CentralAir',
47
+ 'Electrical',
48
+ '1stFlrSF',
49
+ '2ndFlrSF',
50
+ 'LowQualFinSF',
51
+ 'GrLivArea',
52
+ 'BsmtFullBath',
53
+ 'BsmtHalfBath',
54
+ 'FullBath',
55
+ 'HalfBath',
56
+ 'BedroomAbvGr',
57
+ 'KitchenAbvGr',
58
+ 'KitchenQual',
59
+ 'TotRmsAbvGrd',
60
+ 'Functional',
61
+ 'Fireplaces',
62
+ 'FireplaceQu',
63
+ 'GarageType',
64
+ 'GarageYrBlt',
65
+ 'GarageFinish',
66
+ 'GarageCars',
67
+ 'GarageArea',
68
+ 'GarageQual',
69
+ 'GarageCond',
70
+ 'PavedDrive',
71
+ 'WoodDeckSF',
72
+ 'OpenPorchSF',
73
+ 'EnclosedPorch',
74
+ '3SsnPorch',
75
+ 'ScreenPorch',
76
+ 'PoolArea',
77
+ 'PoolQC',
78
+ 'Fence',
79
+ 'MiscFeature',
80
+ 'MiscVal',
81
+ 'MoSold',
82
+ 'YrSold',
83
+ 'SaleType',
84
+ 'SaleCondition']
85
+
86
+ categorical_columns = ['MSZoning',
87
+ 'Street',
88
+ 'Alley',
89
+ 'LotShape',
90
+ 'LandContour',
91
+ 'Utilities',
92
+ 'LotConfig',
93
+ 'LandSlope',
94
+ 'Neighborhood',
95
+ 'Condition1',
96
+ 'Condition2',
97
+ 'BldgType',
98
+ 'HouseStyle',
99
+ 'RoofStyle',
100
+ 'RoofMatl',
101
+ 'Exterior1st',
102
+ 'Exterior2nd',
103
+ 'MasVnrType',
104
+ 'ExterQual',
105
+ 'ExterCond',
106
+ 'Foundation',
107
+ 'BsmtQual',
108
+ 'BsmtCond',
109
+ 'BsmtExposure',
110
+ 'BsmtFinType1',
111
+ 'BsmtFinType2',
112
+ 'Heating',
113
+ 'HeatingQC',
114
+ 'CentralAir',
115
+ 'Electrical',
116
+ 'KitchenQual',
117
+ 'Functional',
118
+ 'FireplaceQu',
119
+ 'GarageType',
120
+ 'GarageFinish',
121
+ 'GarageQual',
122
+ 'GarageCond',
123
+ 'PavedDrive',
124
+ 'PoolQC',
125
+ 'Fence',
126
+ 'MiscFeature',
127
+ 'SaleType',
128
+ 'SaleCondition']
129
+
130
+ with open("model.pkl", "rb") as f:
131
+ model = pickle.load(f)
132
+
133
+ def house_price(LotArea, LotFrontage, YearBuilt, GrLivArea, GarageArea):
134
+
135
+ lot_area = float(LotArea)
136
+ lot_frontage = float(LotFrontage)
137
+ year_built = float(YearBuilt)
138
+ gr_liv_area = float(GrLivArea)
139
+ garage_area = float(GarageArea)
140
+
141
+ default = [20,
142
+ 'RL',
143
+ lot_frontage,
144
+ lot_area,
145
+ 'Pave',
146
+ 'Grvl',
147
+ 'Reg',
148
+ 'Lvl',
149
+ 'AllPub',
150
+ 'Inside',
151
+ 'Gtl',
152
+ 'NAmes',
153
+ 'Norm',
154
+ 'Norm',
155
+ '1Fam',
156
+ '1Story',
157
+ 5,
158
+ 5,
159
+ year_built,
160
+ 1950,
161
+ 'Gable',
162
+ 'CompShg',
163
+ 'VinylSd',
164
+ 'VinylSd',
165
+ 'None',
166
+ 0.0,
167
+ 'TA',
168
+ 'TA',
169
+ 'PConc',
170
+ 'TA',
171
+ 'TA',
172
+ 'No',
173
+ 'Unf',
174
+ 0.0,
175
+ 'Unf',
176
+ 0.0,
177
+ 0.0,
178
+ 0.0,
179
+ 'GasA',
180
+ 'Ex',
181
+ 'Y',
182
+ 'SBrkr',
183
+ 864,
184
+ 0,
185
+ 0,
186
+ gr_liv_area,
187
+ 0.0,
188
+ 0.0,
189
+ 2,
190
+ 0,
191
+ 3,
192
+ 1,
193
+ 'TA',
194
+ 6,
195
+ 'Typ',
196
+ 0,
197
+ 'Gd',
198
+ 'Attchd',
199
+ 2005.0,
200
+ 'Unf',
201
+ 2.0,
202
+ garage_area,
203
+ 'TA',
204
+ 'TA',
205
+ 'Y',
206
+ 0,
207
+ 0,
208
+ 0,
209
+ 0,
210
+ 0,
211
+ 0,
212
+ 'Gd',
213
+ 'MnPrv',
214
+ 'Shed',
215
+ 0,
216
+ 6,
217
+ 2007,
218
+ 'WD',
219
+ 'Normal']
220
+
221
+ df=pd.DataFrame([default], columns = defaultColumns)
222
+ df[categorical_columns] = df[categorical_columns].astype("category")
223
+ df[categorical_columns] = df[categorical_columns].apply(lambda x: x.cat.codes)
224
+ df = (df - df.mean()) / df.std()
225
+
226
+ predictions = model.predict(test)
227
+
228
+ return predictions[0]
229
+
230
+ iface = gr.Interface(
231
+ fn=car_purchase,
232
+ title="House Prices",
233
+ allow_flagging="never",
234
+ inputs=[
235
+ gr.inputs.Number(default=9600, label="LotArea"),
236
+ gr.inputs.Number(default=60.0, label="LotFrontage"),
237
+ gr.inputs.Number(default=2005, label="YearBuilt"),
238
+ gr.inputs.Number(default=864, label="GrLivArea"),
239
+ gr.inputs.Number(default=730, label="GarageArea"),
240
+ ],
241
+ outputs="text")
242
+ iface.launch()