File size: 2,707 Bytes
6f84fec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""GradioUI.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/13606Sv5nfECx_rbwG8DGuXDHspZ6t4kA
"""

import gradio as gr
import joblib
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

# Load the model and scaler
model = joblib.load('model.joblib')
scaler = joblib.load('scaler.joblib')

# Prediction function
def predict_rent(BHK, Size, Furnishing_Status, Bathroom, floor_number,
                 Area_Type, City):

    try:
        # Prepare the input DataFrame with dummy variables
        input_data = pd.DataFrame({
            'BHK': [BHK],
            'Size': [Size],
            'Furnishing Status': [Furnishing_Status],
            'Bathroom': [Bathroom],
            'floor_number': [floor_number],
            'Area Type_Carpet Area': [0],
            'Area Type_Super Area': [0],
            'City_Chennai': [0],
            'City_Delhi': [0],
            'City_Hyderabad': [0],
            'City_Kolkata': [0],
            'City_Mumbai': [0],
        })

        # Update one-hot encoded fields
        if Area_Type == "Carpet Area":
            input_data['Area Type_Carpet Area'] = [1]
        elif Area_Type == "Super Area":
            input_data['Area Type_Super Area'] = [1]

        if City == "Chennai":
            input_data['City_Chennai'] = [1]
        elif City == "Delhi":
            input_data['City_Delhi'] = [1]
        elif City == "Hyderabad":
            input_data['City_Hyderabad'] = [1]
        elif City == "Kolkata":
            input_data['City_Kolkata'] = [1]
        elif City == "Mumbai":
            input_data['City_Mumbai'] = [1]

        rent = model.predict(input_data)[0]
        return f"💰 Predicted Rent: ${rent:,.2f} per month"

    except Exception as e:
        return f"❌ Error: {e}"

# Inputs
inputs = [
    gr.Number(label="BHK", minimum=1, maximum=6),
    gr.Number(label="Size (in sqft)", minimum=100, maximum=80000),
    gr.Number(label="Furnishing Status (0: Unfurnished, 1: Semi-Furnished, 2: Furnished)", minimum=0, maximum=2),
    gr.Number(label="Bathrooms", minimum=1, maximum=3),
    gr.Number(label="Floor Number", minimum=0, maximum=10),
    gr.Dropdown(choices=["Carpet Area", "Super Area"], label="Area Type"),
    gr.Dropdown(choices=["Chennai", "Delhi", "Hyderabad", "Kolkata", "Mumbai"], label="City"),
]

# Gradio UI
gr.Interface(
    fn=predict_rent,
    inputs=inputs,
    outputs=gr.Textbox(label="Prediction Result"),
    title="🏡 Rent Prediction App",
    description="Welcome to Leo's RealEstate! Our valued customer, please fill your preferences to get the predicted monthly rent."
).launch()