File size: 1,408 Bytes
d0fe3e2 52bf674 d0fe3e2 52bf674 d0fe3e2 8cc6c21 bab29c4 d0fe3e2 210f9e3 4184ac4 210f9e3 8f71a16 d0fe3e2 4184ac4 |
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 |
import gradio as gr
import pickle
import json
import numpy as np
# Load model and columns
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:] # Extract location columns (FROM FORTH COLUMN TO END FOUND IN LOCATION)
def predict_price(total_sqft, bath, bhk, location):
# Prepare the input array
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
# Make prediction
return model.predict([x])[0]
# Create the Gradio interface
inputs = [
gr.Number(minimum=1,label="Total Square Feet"),
gr.Number(minimum=1,label="Bath"),
gr.Number(minimum=1,label="BHK [Bedroom, Hall, and Kitchen]"),
gr.Dropdown(choices=locations, label="Location")
]
outputs = gr.Textbox(label="Predicted Price (Lakh)")
# Add the link under the output prediction
#link = gr.Markdown("For more details, visit [Github](https://github.com/94etienne/AI_PROJECTS_RESEARCH/blob/main/1_banglore_home_price.rar)")
# Footer content
footer = "Etienne NTAMBARA @AI_Engineer"
# Launch the interface
gr.Interface(fn=predict_price, inputs=inputs, outputs=outputs, title="Real Estate Price Prediction", article=footer).launch()
|