Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
import json
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load model and columns
|
7 |
+
with open("../model/banglore_home_prices_model.pickle", "rb") as f:
|
8 |
+
model = pickle.load(f)
|
9 |
+
|
10 |
+
with open("../model/columns.json", "r") as f:
|
11 |
+
data_columns = json.load(f)["data_columns"]
|
12 |
+
|
13 |
+
locations = data_columns[3:] # Extract location columns (FROM FORTH COLUMN TO END FOUND IN LOCATION)
|
14 |
+
|
15 |
+
def predict_price(total_sqft, bath, bhk, location):
|
16 |
+
# Prepare the input array
|
17 |
+
x = np.zeros(len(data_columns))
|
18 |
+
x[0] = total_sqft
|
19 |
+
x[1] = bath
|
20 |
+
x[2] = bhk
|
21 |
+
if location in locations:
|
22 |
+
loc_index = data_columns.index(location)
|
23 |
+
x[loc_index] = 1
|
24 |
+
|
25 |
+
# Make prediction
|
26 |
+
return model.predict([x])[0]
|
27 |
+
|
28 |
+
# Create the Gradio interface
|
29 |
+
inputs = [
|
30 |
+
gr.Number(label="Total Square Feet"),
|
31 |
+
gr.Number(label="Bath"),
|
32 |
+
gr.Number(label="BHK"),
|
33 |
+
gr.Dropdown(choices=locations, label="Location")
|
34 |
+
]
|
35 |
+
|
36 |
+
outputs = gr.Textbox(label="Predicted Price (Lakh)")
|
37 |
+
|
38 |
+
# Launch the interface
|
39 |
+
gr.Interface(fn=predict_price, inputs=inputs, outputs=outputs, title="Real Estate Price Prediction").launch()
|