Lesson5 / app.py
ErickMVdO's picture
Create app.py
e745180
raw
history blame
3.91 kB
import gradio as gr
import torch, numpy as np, pandas as pd
import skimage
import pickle
defaultColumns = ['MSSubClass',
'MSZoning',
'LotFrontage',
'LotArea',
'Street',
'Alley',
'LotShape',
'LandContour',
'Utilities',
'LotConfig',
'LandSlope',
'Neighborhood',
'Condition1',
'Condition2',
'BldgType',
'HouseStyle',
'OverallQual',
'OverallCond',
'YearBuilt',
'YearRemodAdd',
'RoofStyle',
'RoofMatl',
'Exterior1st',
'Exterior2nd',
'MasVnrType',
'MasVnrArea',
'ExterQual',
'ExterCond',
'Foundation',
'BsmtQual',
'BsmtCond',
'BsmtExposure',
'BsmtFinType1',
'BsmtFinSF1',
'BsmtFinType2',
'BsmtFinSF2',
'BsmtUnfSF',
'TotalBsmtSF',
'Heating',
'HeatingQC',
'CentralAir',
'Electrical',
'1stFlrSF',
'2ndFlrSF',
'LowQualFinSF',
'GrLivArea',
'BsmtFullBath',
'BsmtHalfBath',
'FullBath',
'HalfBath',
'BedroomAbvGr',
'KitchenAbvGr',
'KitchenQual',
'TotRmsAbvGrd',
'Functional',
'Fireplaces',
'FireplaceQu',
'GarageType',
'GarageYrBlt',
'GarageFinish',
'GarageCars',
'GarageArea',
'GarageQual',
'GarageCond',
'PavedDrive',
'WoodDeckSF',
'OpenPorchSF',
'EnclosedPorch',
'3SsnPorch',
'ScreenPorch',
'PoolArea',
'PoolQC',
'Fence',
'MiscFeature',
'MiscVal',
'MoSold',
'YrSold',
'SaleType',
'SaleCondition']
categorical_columns = ['MSZoning',
'Street',
'Alley',
'LotShape',
'LandContour',
'Utilities',
'LotConfig',
'LandSlope',
'Neighborhood',
'Condition1',
'Condition2',
'BldgType',
'HouseStyle',
'RoofStyle',
'RoofMatl',
'Exterior1st',
'Exterior2nd',
'MasVnrType',
'ExterQual',
'ExterCond',
'Foundation',
'BsmtQual',
'BsmtCond',
'BsmtExposure',
'BsmtFinType1',
'BsmtFinType2',
'Heating',
'HeatingQC',
'CentralAir',
'Electrical',
'KitchenQual',
'Functional',
'FireplaceQu',
'GarageType',
'GarageFinish',
'GarageQual',
'GarageCond',
'PavedDrive',
'PoolQC',
'Fence',
'MiscFeature',
'SaleType',
'SaleCondition']
with open("model.pkl", "rb") as f:
model = pickle.load(f)
def house_price(LotArea, LotFrontage, YearBuilt, GrLivArea, GarageArea):
lot_area = float(LotArea)
lot_frontage = float(LotFrontage)
year_built = float(YearBuilt)
gr_liv_area = float(GrLivArea)
garage_area = float(GarageArea)
default = [20,
'RL',
lot_frontage,
lot_area,
'Pave',
'Grvl',
'Reg',
'Lvl',
'AllPub',
'Inside',
'Gtl',
'NAmes',
'Norm',
'Norm',
'1Fam',
'1Story',
5,
5,
year_built,
1950,
'Gable',
'CompShg',
'VinylSd',
'VinylSd',
'None',
0.0,
'TA',
'TA',
'PConc',
'TA',
'TA',
'No',
'Unf',
0.0,
'Unf',
0.0,
0.0,
0.0,
'GasA',
'Ex',
'Y',
'SBrkr',
864,
0,
0,
gr_liv_area,
0.0,
0.0,
2,
0,
3,
1,
'TA',
6,
'Typ',
0,
'Gd',
'Attchd',
2005.0,
'Unf',
2.0,
garage_area,
'TA',
'TA',
'Y',
0,
0,
0,
0,
0,
0,
'Gd',
'MnPrv',
'Shed',
0,
6,
2007,
'WD',
'Normal']
df=pd.DataFrame([default], columns = defaultColumns)
df[categorical_columns] = df[categorical_columns].astype("category")
df[categorical_columns] = df[categorical_columns].apply(lambda x: x.cat.codes)
df = (df - df.mean()) / df.std()
predictions = model.predict(test)
return predictions[0]
iface = gr.Interface(
fn=car_purchase,
title="House Prices",
allow_flagging="never",
inputs=[
gr.inputs.Number(default=9600, label="LotArea"),
gr.inputs.Number(default=60.0, label="LotFrontage"),
gr.inputs.Number(default=2005, label="YearBuilt"),
gr.inputs.Number(default=864, label="GrLivArea"),
gr.inputs.Number(default=730, label="GarageArea"),
],
outputs="text")
iface.launch()