kidu14 commited on
Commit
6f84fec
·
verified ·
1 Parent(s): 1278e2c

initial commit

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """GradioUI.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/13606Sv5nfECx_rbwG8DGuXDHspZ6t4kA
8
+ """
9
+
10
+ import gradio as gr
11
+ import joblib
12
+ import numpy as np
13
+ import pandas as pd
14
+ from sklearn.preprocessing import MinMaxScaler
15
+
16
+ # Load the model and scaler
17
+ model = joblib.load('model.joblib')
18
+ scaler = joblib.load('scaler.joblib')
19
+
20
+ # Prediction function
21
+ def predict_rent(BHK, Size, Furnishing_Status, Bathroom, floor_number,
22
+ Area_Type, City):
23
+
24
+ try:
25
+ # Prepare the input DataFrame with dummy variables
26
+ input_data = pd.DataFrame({
27
+ 'BHK': [BHK],
28
+ 'Size': [Size],
29
+ 'Furnishing Status': [Furnishing_Status],
30
+ 'Bathroom': [Bathroom],
31
+ 'floor_number': [floor_number],
32
+ 'Area Type_Carpet Area': [0],
33
+ 'Area Type_Super Area': [0],
34
+ 'City_Chennai': [0],
35
+ 'City_Delhi': [0],
36
+ 'City_Hyderabad': [0],
37
+ 'City_Kolkata': [0],
38
+ 'City_Mumbai': [0],
39
+ })
40
+
41
+ # Update one-hot encoded fields
42
+ if Area_Type == "Carpet Area":
43
+ input_data['Area Type_Carpet Area'] = [1]
44
+ elif Area_Type == "Super Area":
45
+ input_data['Area Type_Super Area'] = [1]
46
+
47
+ if City == "Chennai":
48
+ input_data['City_Chennai'] = [1]
49
+ elif City == "Delhi":
50
+ input_data['City_Delhi'] = [1]
51
+ elif City == "Hyderabad":
52
+ input_data['City_Hyderabad'] = [1]
53
+ elif City == "Kolkata":
54
+ input_data['City_Kolkata'] = [1]
55
+ elif City == "Mumbai":
56
+ input_data['City_Mumbai'] = [1]
57
+
58
+ rent = model.predict(input_data)[0]
59
+ return f"💰 Predicted Rent: ${rent:,.2f} per month"
60
+
61
+ except Exception as e:
62
+ return f"❌ Error: {e}"
63
+
64
+ # Inputs
65
+ inputs = [
66
+ gr.Number(label="BHK", minimum=1, maximum=6),
67
+ gr.Number(label="Size (in sqft)", minimum=100, maximum=80000),
68
+ gr.Number(label="Furnishing Status (0: Unfurnished, 1: Semi-Furnished, 2: Furnished)", minimum=0, maximum=2),
69
+ gr.Number(label="Bathrooms", minimum=1, maximum=3),
70
+ gr.Number(label="Floor Number", minimum=0, maximum=10),
71
+ gr.Dropdown(choices=["Carpet Area", "Super Area"], label="Area Type"),
72
+ gr.Dropdown(choices=["Chennai", "Delhi", "Hyderabad", "Kolkata", "Mumbai"], label="City"),
73
+ ]
74
+
75
+ # Gradio UI
76
+ gr.Interface(
77
+ fn=predict_rent,
78
+ inputs=inputs,
79
+ outputs=gr.Textbox(label="Prediction Result"),
80
+ title="🏡 Rent Prediction App",
81
+ description="Welcome to Leo's RealEstate! Our valued customer, please fill your preferences to get the predicted monthly rent."
82
+ ).launch()