Soumyajit Khan
commited on
Commit
·
292572f
1
Parent(s):
0f74347
Add application file
Browse files- Mumbai.jpg +3 -0
- __pycache__/util.cpython-311.pyc +0 -0
- app.py +90 -0
- artifacts/Mumbai_Price_predictor.pickle +3 -0
- artifacts/columns.json +1 -0
- requirement.txt +3 -0
- server.py +44 -0
- setup.sh +3 -0
- util.py +83 -0
Mumbai.jpg
ADDED
![]() |
Git LFS Details
|
__pycache__/util.cpython-311.pyc
ADDED
Binary file (3.8 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import base64
|
4 |
+
|
5 |
+
|
6 |
+
def load_options():
|
7 |
+
type_url = "http://127.0.0.1:5000/get_type_names"
|
8 |
+
region_url = "http://127.0.0.1:5000/get_region_names"
|
9 |
+
|
10 |
+
type_response = requests.get(type_url)
|
11 |
+
region_response = requests.get(region_url)
|
12 |
+
|
13 |
+
if type_response.status_code == 200 and region_response.status_code == 200:
|
14 |
+
types = type_response.json()['type']
|
15 |
+
regions = region_response.json()['region']
|
16 |
+
return types, regions
|
17 |
+
else:
|
18 |
+
return [], []
|
19 |
+
|
20 |
+
types, regions = load_options()
|
21 |
+
|
22 |
+
|
23 |
+
def encode_image(image_path):
|
24 |
+
with open(image_path, "rb") as image_file:
|
25 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
26 |
+
|
27 |
+
image_base64 = encode_image("Mumbai.jpg")
|
28 |
+
|
29 |
+
st.markdown(f"""
|
30 |
+
<style>
|
31 |
+
.stApp {{
|
32 |
+
background-image: url('data:image/jpeg;base64,{image_base64}');
|
33 |
+
background-size: cover;
|
34 |
+
background-position: center;
|
35 |
+
background-repeat: no-repeat;
|
36 |
+
}}
|
37 |
+
|
38 |
+
|
39 |
+
div[data-testid="stMarkdownContainer"] {{
|
40 |
+
color: white;
|
41 |
+
font-size: 2em;
|
42 |
+
|
43 |
+
}}
|
44 |
+
|
45 |
+
div.stButton > button:first-child {{
|
46 |
+
background-color: #4CAF50;
|
47 |
+
color: white;
|
48 |
+
font-size: 1.2em;
|
49 |
+
padding: 10px 20px;
|
50 |
+
border: none;
|
51 |
+
border-radius: 5px;
|
52 |
+
cursor: pointer;
|
53 |
+
}}
|
54 |
+
|
55 |
+
div.stButton > button:first-child:hover {{
|
56 |
+
background-color: #45a049;
|
57 |
+
}}
|
58 |
+
|
59 |
+
</style>
|
60 |
+
""", unsafe_allow_html=True)
|
61 |
+
|
62 |
+
|
63 |
+
st.title("Mumbai House Price Predictor")
|
64 |
+
|
65 |
+
bhk = st.number_input("BHK", min_value=1, step=1)
|
66 |
+
type_ = st.selectbox("Type", options=types, format_func=lambda x: x.capitalize())
|
67 |
+
area = st.number_input("Area (in sqft)", min_value=400, step=50)
|
68 |
+
region = st.selectbox("Region", options=regions + ["Other"], format_func=lambda x: x.capitalize(), help="Input a region name. If not in the list, it will be considered as 'other'")
|
69 |
+
status = st.selectbox("Status", ["Under Construction", "Ready to move"])
|
70 |
+
age = st.selectbox("Age", ["Unknown", "Resale", "New"])
|
71 |
+
|
72 |
+
def get_prediction(bhk, type_, area, region, status, age):
|
73 |
+
url = "http://127.0.0.1:5000/predict_house_price"
|
74 |
+
data = {
|
75 |
+
"bhk": bhk,
|
76 |
+
"type": type_,
|
77 |
+
"area": area,
|
78 |
+
"region": region,
|
79 |
+
"status": status,
|
80 |
+
"age": age
|
81 |
+
}
|
82 |
+
response = requests.post(url, data=data)
|
83 |
+
return response.json()
|
84 |
+
|
85 |
+
if st.button("Predict Price"):
|
86 |
+
result = get_prediction(bhk, type_, area, region, status, age)
|
87 |
+
st.markdown(f"<div style='color: white; font-size: 1.2em;'>Estimated Price: {result['estimated_price']} INR</div>", unsafe_allow_html=True)
|
88 |
+
|
89 |
+
if __name__ == "__main__":
|
90 |
+
st.write("Streamlit app is running...")
|
artifacts/Mumbai_Price_predictor.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a33ff4bf30ce5f0d8f430e59e812f32fc4026b3513d1acc3ebaff56baa7fbbf2
|
3 |
+
size 241683318
|
artifacts/columns.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"data_columns": ["bhk", "area", "status", "age", "apartment", "independent house", "penthouse", "studio apartment", "villa", "agripada", "airoli", "ambarnath", "ambernath east", "ambernath west", "andheri east", "andheri west", "anjurdive", "badlapur east", "badlapur west", "bandra east", "bandra kurla complex", "bandra west", "belapur", "bhandup east", "bhandup west", "bhayandar east", "bhayandar west", "bhiwandi", "boisar", "borivali east", "borivali west", "byculla", "chembur", "colaba", "dadar east", "dadar west", "dahisar", "deonar", "diva", "dombivali", "dombivali east", "dronagiri", "ghansoli", "ghatkopar east", "ghatkopar west", "girgaon", "goregaon east", "goregaon west", "jogeshwari east", "jogeshwari west", "juhu", "juinagar", "kalamboli", "kalyan east", "kalyan west", "kamothe", "kandivali east", "kandivali west", "kanjurmarg", "karanjade", "karjat", "khar", "kharghar", "khopoli", "koper khairane", "kurla", "lower parel", "mahalaxmi", "mahim", "malad east", "malad west", "marine lines", "matunga", "mazagaon", "mira road east", "mulund east", "mulund west", "nahur east", "naigaon east", "nala sopara", "neral", "nerul", "nilje gaon", "palghar", "panvel", "parel", "powai", "prabhadevi", "rasayani", "sanpada", "santacruz east", "santacruz west", "seawoods", "sewri", "shil phata", "sion", "taloja", "tardeo", "thane east", "thane west", "titwala", "ulhasnagar", "ulwe", "umroli", "vasai", "vashi", "vikhroli", "ville parle east", "ville parle west", "virar", "wadala", "worli"]}
|
requirement.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
flask
|
3 |
+
requests
|
server.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import util
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
|
7 |
+
@app.route('/get_region_names', methods=['GET'])
|
8 |
+
def get_region_names():
|
9 |
+
response = jsonify({
|
10 |
+
'region': util.get_region_names()
|
11 |
+
})
|
12 |
+
response.headers.add('Access-Control-Allow-Origin', '*')
|
13 |
+
return response
|
14 |
+
|
15 |
+
@app.route('/get_type_names', methods=['GET'])
|
16 |
+
def get_type_names():
|
17 |
+
response = jsonify({
|
18 |
+
'type': util.get_type_names()
|
19 |
+
})
|
20 |
+
response.headers.add('Access-Control-Allow-Origin', '*')
|
21 |
+
return response
|
22 |
+
|
23 |
+
|
24 |
+
@app.route('/predict_house_price',methods =['GET','POST'])
|
25 |
+
def predict_house_price():
|
26 |
+
bhk = int(request.form['bhk'])
|
27 |
+
type_ = request.form['type']
|
28 |
+
area = float(request.form['area'])
|
29 |
+
region = request.form['region']
|
30 |
+
status = request.form['status']
|
31 |
+
age = request.form['age']
|
32 |
+
|
33 |
+
response = jsonify({
|
34 |
+
'estimated_price' : util.predict_price(bhk, type_, area, region, status, age)
|
35 |
+
})
|
36 |
+
|
37 |
+
return response
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == '__main__':
|
42 |
+
print("Starting Flask Server...")
|
43 |
+
util.load_saved_artifacts()
|
44 |
+
app.run()
|
setup.sh
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
nohup python server.py --host=0.0.0.0 &
|
2 |
+
|
3 |
+
streamlit run app.py
|
util.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pickle
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
__type_ = None
|
6 |
+
__region = None
|
7 |
+
__data_columns = None
|
8 |
+
__model = None
|
9 |
+
|
10 |
+
|
11 |
+
def predict_price(bhk, type_, area, region, status, age):
|
12 |
+
global __model
|
13 |
+
global __data_columns
|
14 |
+
|
15 |
+
status_map = {'Under Construction': 0, 'Ready to move': 1}
|
16 |
+
status_encoded = status_map.get(status, -1)
|
17 |
+
if status_encoded == -1:
|
18 |
+
raise ValueError("Invalid status provided")
|
19 |
+
|
20 |
+
age_map = {'Unknown': 0, 'Resale': 1, 'New': 2}
|
21 |
+
age_encoded = age_map.get(age, -1)
|
22 |
+
if age_encoded == -1:
|
23 |
+
raise ValueError("Invalid age provided")
|
24 |
+
|
25 |
+
|
26 |
+
type_ = type_.lower()
|
27 |
+
region = region.lower()
|
28 |
+
|
29 |
+
x = np.zeros(len(__data_columns))
|
30 |
+
|
31 |
+
x[0] = bhk
|
32 |
+
x[1] = area
|
33 |
+
x[2] = status_encoded
|
34 |
+
x[3] = age_encoded
|
35 |
+
|
36 |
+
if type_ in __data_columns:
|
37 |
+
type_index = __data_columns.index(type_)
|
38 |
+
x[type_index] = 1
|
39 |
+
else:
|
40 |
+
raise ValueError(f"Invalid type provided: {type_}")
|
41 |
+
|
42 |
+
try:
|
43 |
+
region_index = __data_columns.index(region)
|
44 |
+
except ValueError:
|
45 |
+
region_index = -1
|
46 |
+
|
47 |
+
if region_index >= 0:
|
48 |
+
x[region_index] = 1
|
49 |
+
|
50 |
+
return round(__model.predict([x])[0],2)
|
51 |
+
|
52 |
+
|
53 |
+
def load_saved_artifacts():
|
54 |
+
print("loading saved artifacts....")
|
55 |
+
global __data_columns
|
56 |
+
global __region
|
57 |
+
global __type_
|
58 |
+
global __model
|
59 |
+
|
60 |
+
with open("./artifacts/columns.json","r") as f:
|
61 |
+
__data_columns = json.load(f)["data_columns"]
|
62 |
+
__region = __data_columns[9:]
|
63 |
+
__type_ = __data_columns[4:9]
|
64 |
+
|
65 |
+
with open("./artifacts/Mumbai_Price_predictor.pickle","rb") as f:
|
66 |
+
__model = pickle.load(f)
|
67 |
+
print("Loading Artifacts Completed !!")
|
68 |
+
|
69 |
+
|
70 |
+
def get_region_names():
|
71 |
+
return __region
|
72 |
+
|
73 |
+
def get_type_names():
|
74 |
+
return __type_
|
75 |
+
|
76 |
+
|
77 |
+
if __name__ == "__main__":
|
78 |
+
load_saved_artifacts()
|
79 |
+
print(get_region_names())
|
80 |
+
print(get_type_names())
|
81 |
+
print(predict_price(2,'Apartment',650,'Agripada','Under Construction','Resale'))
|
82 |
+
print(predict_price(2,'Apartment',1650,'Agripada','Ready to move','Resale'))
|
83 |
+
print(predict_price(2,'Apartment',1650,'other','Ready to move','Resale'))
|