Spaces:
Sleeping
Sleeping
Commit
•
8ab368f
1
Parent(s):
898904e
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,57 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import numpy as np
|
3 |
import gradio as gr
|
4 |
+
import pickle
|
5 |
+
from sklearn.linear_model import LinearRegression
|
6 |
|
7 |
+
# Load the model
|
8 |
+
with open('HYD_Rent_Predictor.pkl', 'rb') as model_file:
|
9 |
+
best_model = pickle.load(model_file)
|
10 |
+
if isinstance(best_model, LinearRegression):
|
11 |
+
best_model.check_input = False
|
12 |
|
13 |
+
# Load the columns
|
14 |
+
with open('columns.json', 'r') as f:
|
15 |
+
data_columns = json.load(f)['data_columns']
|
16 |
+
|
17 |
+
def predict_price(locality, balconies, bathroom, furnishingDesc, parking, property_size, type_bhk, floor):
|
18 |
+
loc_index = np.where(np.array(data_columns) == locality.lower())[0][0]
|
19 |
+
|
20 |
+
x = np.zeros(len(data_columns))
|
21 |
+
x[0] = balconies
|
22 |
+
x[1] = bathroom
|
23 |
+
x[2] = furnishingDesc
|
24 |
+
x[3] = parking
|
25 |
+
x[4] = property_size
|
26 |
+
x[5] = type_bhk
|
27 |
+
x[6] = floor
|
28 |
+
|
29 |
+
if loc_index >= 0:
|
30 |
+
x[loc_index] = 1
|
31 |
+
|
32 |
+
return best_model.predict([x])[0]
|
33 |
+
|
34 |
+
# Gradio interface
|
35 |
+
def interface(locality, balconies, bathroom, furnishingDesc, parking, property_size, type_bhk, floor):
|
36 |
+
result = predict_price(locality, balconies, bathroom, furnishingDesc, parking, property_size, type_bhk, floor)
|
37 |
+
return f"Predicted Rent: {result:.2f} INR"
|
38 |
+
|
39 |
+
furnishing_options = [0.5, 0, 1] # Replace with actual options
|
40 |
+
parking_options = [0, 1, 2, 3] # Replace with actual options
|
41 |
+
type_bhk_options = [0.5, 1, 2, 3, 4, 5] # Replace with actual options
|
42 |
+
|
43 |
+
inputs = [
|
44 |
+
gr.inputs.Textbox(label="Locality"),
|
45 |
+
gr.inputs.Slider(0, 10, step=1, default=1, label="Balconies"),
|
46 |
+
gr.inputs.Slider(1, 5, step=1, default=1, label="Bathrooms"),
|
47 |
+
gr.inputs.Dropdown(furnishing_options, label="Furnishing Description"),
|
48 |
+
gr.inputs.Dropdown(parking_options, label="Parking"),
|
49 |
+
gr.inputs.Number(default=1000, label="Property Size (in sqft)"),
|
50 |
+
gr.inputs.Dropdown(type_bhk_options, label="Type BHK"),
|
51 |
+
gr.inputs.Number(default=1, label="Floor"),
|
52 |
+
]
|
53 |
+
|
54 |
+
outputs = gr.outputs.Textbox()
|
55 |
+
|
56 |
+
# Create Gradio interface
|
57 |
+
gr.Interface(fn=interface, inputs=inputs, outputs=outputs, title="Hyderabad House Rent Prediction").launch()
|