rishikeshpaulcode commited on
Commit
8a373ce
·
1 Parent(s): c1ecce3

migrate whole codebase

Browse files
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: House Price Predictor
3
  emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
  sdk: docker
7
  app_port: 8501
8
  tags:
 
1
  ---
2
  title: House Price Predictor
3
  emoji: 🚀
4
+ colorFrom: green
5
+ colorTo: green
6
  sdk: docker
7
  app_port: 8501
8
  tags:
src/House_Price_Predictor.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29e6c6be87e5a50b8adb9cf8f227ebac41abd3e5fef38befa4e2871f89b68b5f
3
+ size 184446779
src/categories.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"Location": ["Agra", "Ahmadnagar", "Ahmedabad", "Allahabad", "Aurangabad", "Badlapur", "Bangalore", "Belgaum", "Bhiwadi", "Bhiwandi", "Bhopal", "Bhubaneswar", "Chandigarh", "Chennai", "Coimbatore", "Dehradun", "Durgapur", "Ernakulam", "Faridabad", "Ghaziabad", "Goa", "Greater Noida", "Guntur", "Gurgaon", "Guwahati", "Gwalior", "Haridwar", "Hyderabad", "Indore", "Jabalpur", "Jaipur", "Jamshedpur", "Jodhpur", "Kalyan", "Kanpur", "Kochi", "Kolkata", "Kozhikode", "Lucknow", "Ludhiana", "Madurai", "Mangalore", "Mohali", "Mumbai", "Mysore", "Nagpur", "Nashik", "Navi Mumbai", "Navsari", "Nellore", "New Delhi", "Noida", "Palakkad", "Palghar", "Panchkula", "Patna", "Pondicherry", "Pune", "Raipur", "Rajahmundry", "Ranchi", "Satara", "Shimla", "Siliguri", "Solapur", "Sonipat", "Surat", "Thane", "Thrissur", "Tirupati", "Trichy", "Trivandrum", "Udaipur", "Udupi", "Vadodara", "Vapi", "Varanasi", "Vijayawada", "Visakhapatnam", "Vrindavan", "Zirakpur"], "Transaction": ["Other", "Rent/Lease", "Resale", "New Property"], "Ownership": ["Co-operative Society", "Freehold", "Leasehold", "No data", "Power Of Attorney"], "Furnishing": ["Unfurnished", "Semi-Furnished", "Furnished"], "Facing": ["East", "No data", "North", "North - East", "North - West", "South", "South - East", "South -West", "West"], "Overlooking": ["Garden", "Park", "Scenery", "Pool", "Lake", "Sea", "Main Road"]}
src/streamlit_app.py CHANGED
@@ -1,7 +1,126 @@
1
  # import packages
2
  import streamlit as st
3
  import numpy as np
4
- from sklearn.ensemble import RandomForestRegressor
 
5
 
6
- # display message
7
- st.write("Hello World!!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # import packages
2
  import streamlit as st
3
  import numpy as np
4
+ import json
5
+ import pickle
6
 
7
+ # create custom styles
8
+ st.markdown(
9
+ '''
10
+ <style>
11
+ div.stButton > button p {
12
+ font-size: 21px !important;
13
+ forn-weight: bold !important;
14
+ }
15
+ </style>
16
+ ''',
17
+ unsafe_allow_html=True
18
+ )
19
+ st.markdown(
20
+ '''
21
+ <style>
22
+ div[data-testid="stSelectbox"] label[data-testid="stWidgetLabel"] p {
23
+ font-size: 22px !important;
24
+ font-weight: bold !important;
25
+ }
26
+ </style>
27
+ ''',
28
+ unsafe_allow_html=True
29
+ )
30
+ st.markdown(
31
+ '''
32
+ <style>
33
+ div[data-testid="stNumberInput"] label[data-testid="stWidgetLabel"] p {
34
+ font-size: 22px !important;
35
+ font-weight: bold !important;
36
+ }
37
+ </style>
38
+ ''',
39
+ unsafe_allow_html=True
40
+ )
41
+ st.markdown(
42
+ '''
43
+ <style>
44
+ .st-key-Pill1 label[data-testid="stWidgetLabel"] p,
45
+ .st-key-Pill2 label[data-testid="stWidgetLabel"] p {
46
+ font-size: 22px !important;
47
+ font-weight: bold !important;
48
+ }
49
+ </style>
50
+ ''',
51
+ unsafe_allow_html=True
52
+ )
53
+
54
+ # get unique categories of each feature
55
+ with open("./src/categories.json", "r") as file:
56
+ categories = json.load(file)
57
+
58
+ # load the model
59
+ with open("./src/House_Price_Predictor.pkl", "rb") as file:
60
+ model = pickle.load(file)
61
+
62
+ # function to transform given input to numeric
63
+ def to_numeric(input_dict):
64
+ feature_vals = []
65
+ feature_vals.append(categories["Location"].index(input_dict["location"]))
66
+ feature_vals.append(categories["Transaction"].index(input_dict["transaction_type"]))
67
+ feature_vals.append(categories["Ownership"].index(input_dict["ownership_type"]))
68
+ feature_vals.append(categories["Furnishing"].index(input_dict["furnish_type"]))
69
+ feature_vals.append(categories["Facing"].index(input_dict["face_direction"]))
70
+
71
+ if "Garden" in input_dict["overlookings"] or "Park" in input_dict["overlookings"] or "Scenery" in input_dict["overlookings"]:
72
+ feature_vals.append(1)
73
+ else:
74
+ feature_vals.append(0)
75
+
76
+ if "Main Road" in input_dict["overlookings"]:
77
+ feature_vals.append(1)
78
+ else:
79
+ feature_vals.append(0)
80
+
81
+ if "Pool" in input_dict["overlookings"] or "Lake" in input_dict["overlookings"] or "Sea" in input_dict["overlookings"]:
82
+ feature_vals.append(1)
83
+ else:
84
+ feature_vals.append(0)
85
+
86
+ feature_vals.append(input_dict["user_floor"] / input_dict["total_floors"])
87
+ feature_vals.append(input_dict["total_floors"])
88
+ feature_vals.append(input_dict["num_bathroom"])
89
+ feature_vals.append(input_dict["num_balcony"])
90
+ feature_vals.append(input_dict["num_parking"])
91
+ feature_vals.append(input_dict["carpet_area"])
92
+
93
+ return np.array(feature_vals)[np.newaxis, :]
94
+
95
+
96
+ if __name__ == "__main__":
97
+ # display header and description
98
+ st.title(":house: House Price Predictor")
99
+ st.write("This model predicts indian house prices by acting like a large committee of real estate experts, where each makes a guess based on property details like size and location.")
100
+
101
+ # create form to get independent features
102
+ input_dict = {}
103
+ input_dict["location"] = st.selectbox("Location:", options=categories["Location"])
104
+ input_dict["transaction_type"] = st.selectbox("Type of Transaction:", options=categories["Transaction"])
105
+ input_dict["ownership_type"] = st.selectbox("Type of Ownership:", options=categories["Ownership"])
106
+ input_dict["furnish_type"] = st.selectbox("Type of Furnishing:",options=categories["Furnishing"])
107
+ input_dict["face_direction"] = st.pills("Face Direction:", options=categories["Facing"], selection_mode="single", key="Pill1")
108
+ input_dict["overlookings"] = st.pills("Overlooking:", options=categories["Overlooking"], selection_mode="multi", key="Pill2")
109
+ input_dict["total_floors"] = st.number_input("Total Floors:", min_value=1, value="min", step=1)
110
+ input_dict["user_floor"] = st.number_input("Your Floor:", min_value=1, max_value=input_dict['total_floors'], value="min", step=1)
111
+ input_dict["num_bathroom"] = st.number_input("Number of Bathrooms:", min_value=0, value="min", step=1)
112
+ input_dict["num_balcony"] = st.number_input("Number of Balconies:", min_value=0, value="min", step=1)
113
+ input_dict["num_parking"] = st.number_input("Number of Car Parkings:", min_value=0, value="min", step=1)
114
+ input_dict["carpet_area"] = st.number_input("Total Carpet Area:", value=0.0, format="%.2f")
115
+ st.divider()
116
+
117
+ # get prediction when button is pressed
118
+ if st.button("Get Price", type="primary"):
119
+ input_values = to_numeric(input_dict)
120
+ predicted_price = model.predict(input_values)[0]
121
+
122
+ st.write("Predicted Price:")
123
+ if predicted_price < 1:
124
+ st.header(f"\u20B9 {round(predicted_price * 100, 2)} Lac")
125
+ else:
126
+ st.header(f"\u20B9 {round(predicted_price, 2)} Cr")