kidu14's picture
initial commit
6f84fec verified
# -*- 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()