|
import gradio as gr |
|
import pickle |
|
import json |
|
import numpy as np |
|
|
|
|
|
with open("banglore_home_prices_model.pickle", "rb") as f: |
|
model = pickle.load(f) |
|
|
|
with open("columns.json", "r") as f: |
|
data_columns = json.load(f)["data_columns"] |
|
|
|
locations = data_columns[3:] |
|
|
|
def predict_price(total_sqft, bath, bhk, location): |
|
|
|
x = np.zeros(len(data_columns)) |
|
x[0] = total_sqft |
|
x[1] = bath |
|
x[2] = bhk |
|
if location in locations: |
|
loc_index = data_columns.index(location) |
|
x[loc_index] = 1 |
|
|
|
|
|
return model.predict([x])[0] |
|
|
|
|
|
inputs = [ |
|
gr.Number(label="Total Square Feet"), |
|
gr.Number(label="Bath"), |
|
gr.Number(label="BHK"), |
|
gr.Dropdown(choices=locations, label="Location") |
|
] |
|
|
|
outputs = gr.Textbox(label="Predicted Price (Lakh)") |
|
|
|
|
|
footer = "Etienne NTAMBARA @AI_Engineer" |
|
|
|
|
|
gr.Interface(fn=predict_price, inputs=inputs, outputs=outputs, title="Real Estate Price Prediction", article=footer).launch() |
|
|