RMHalak commited on
Commit
a9b4435
·
verified ·
1 Parent(s): d4d3bd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -64
app.py CHANGED
@@ -6,17 +6,6 @@ from utils import create_new_features, normalize, bucketize, init_new_pred
6
 
7
  st.set_page_config(layout="wide")
8
 
9
- st.markdown("""
10
- <style>
11
- .scroll-container {
12
- height: 500px; /* Set the height of the scrollable section */
13
- overflow-y: scroll;
14
- padding: 10px;
15
- border: 1px solid #ccc; /* Optional: Add border to make the scrollable area more visible */
16
- }
17
- </style>
18
- """, unsafe_allow_html=True)
19
-
20
  # load model and files
21
  with open('./trained_model.pkl', 'rb') as file:
22
  model = pickle.load(file)
@@ -31,61 +20,46 @@ with open("./cities_geo.json", "r") as f:
31
  col1, col2 = st.columns([1, 2]) # Adjust the width ratios as needed
32
 
33
  with col1:
34
- st.subheader('Features')
35
-
36
- with st.container():
37
- st.markdown('<div class="scroll-container">', unsafe_allow_html=True)
38
-
39
- # Create two columns for City and Waterfront
40
- col3, col4 = st.columns(2)
41
-
42
- # City dropdown in the first column
43
- with col3:
44
- city = st.selectbox('City', list(cities_geo.keys()))
45
-
46
- # Waterfront checkbox in the second column
47
- with col4:
48
- waterfront = st.checkbox('Waterfront', value=False)
49
 
50
- # city = st.selectbox('City', list(cities_geo.keys())) # Display city dropdown in the first column
51
- # waterfront = st.checkbox('Waterfront', value=False)
52
- bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=3)
53
- bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=2)
54
- sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=1000)
55
- sqft_lot = st.slider('Square Feet (Lot)', min_value=min_dict['sqft_lot'], max_value=max_dict['sqft_lot'], value=2000)
56
- floors = st.slider('Floors', min_value=min_dict['floors'], max_value=max_dict['floors'], value=1)
57
- view = st.slider('View', min_value=min_dict['view'], max_value=max_dict['view'], value=0)
58
- condition = st.slider('Condition', min_value=min_dict['condition'], max_value=max_dict['condition'], value=3)
59
- sqft_above = st.slider('Square Feet (Above)', min_value=min_dict['sqft_above'], max_value=max_dict['sqft_above'], value=1000)
60
- sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=0)
61
- yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=2000)
62
- yr_renovated = st.slider('Year Renovated', min_value=min_dict['yr_renovated'], max_value=max_dict['yr_renovated'], value=2010)
63
-
64
- st.markdown('</div>', unsafe_allow_html=True)
65
-
66
- new_pred = init_new_pred()
67
- new_pred['bedrooms'] = bedrooms
68
- new_pred['bathrooms'] = bathrooms
69
- new_pred['sqft_living'] = sqft_living
70
- new_pred['sqft_lot'] = sqft_lot
71
- new_pred['floors'] = floors
72
- new_pred['waterfront'] = int(waterfront)
73
- new_pred['view'] = view
74
- new_pred['condition'] = condition
75
- new_pred['sqft_above'] = sqft_above
76
- new_pred['sqft_basement'] = sqft_basement
77
- new_pred['yr_built'] = yr_built
78
- new_pred['yr_renovated'] = yr_renovated
79
- new_pred[f'city_{city}'] = 1
80
-
81
- # Process the prediction
82
- new_pred = pd.DataFrame([new_pred])
83
- new_pred = create_new_features(new_pred)
84
- new_pred = bucketize(new_pred)
85
- new_pred = normalize(new_pred)
86
 
87
- # Predict the price
88
- predicted_price = model.predict(new_pred)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  # Display the map in the second column
91
  with col2:
 
6
 
7
  st.set_page_config(layout="wide")
8
 
 
 
 
 
 
 
 
 
 
 
 
9
  # load model and files
10
  with open('./trained_model.pkl', 'rb') as file:
11
  model = pickle.load(file)
 
20
  col1, col2 = st.columns([1, 2]) # Adjust the width ratios as needed
21
 
22
  with col1:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ city = st.selectbox('City', list(cities_geo.keys())) # Display city dropdown in the first column
25
+ waterfront = st.checkbox('Waterfront', value=False)
26
+ bedrooms = st.slider('Bedrooms', min_value=min_dict['bedrooms'], max_value=max_dict['bedrooms'], value=3)
27
+ bathrooms = st.slider('Bathrooms', min_value=min_dict['bathrooms'], max_value=max_dict['bathrooms'], value=2)
28
+ sqft_living = st.slider('Square Feet (Living)', min_value=min_dict['sqft_living'], max_value=max_dict['sqft_living'], value=1000)
29
+ sqft_lot = st.slider('Square Feet (Lot)', min_value=min_dict['sqft_lot'], max_value=max_dict['sqft_lot'], value=2000)
30
+ floors = st.slider('Floors', min_value=min_dict['floors'], max_value=max_dict['floors'], value=1)
31
+ view = st.slider('View', min_value=min_dict['view'], max_value=max_dict['view'], value=0)
32
+ condition = st.slider('Condition', min_value=min_dict['condition'], max_value=max_dict['condition'], value=3)
33
+ sqft_above = st.slider('Square Feet (Above)', min_value=min_dict['sqft_above'], max_value=max_dict['sqft_above'], value=1000)
34
+ sqft_basement = st.slider('Square Feet (Basement)', min_value=min_dict['sqft_basement'], max_value=max_dict['sqft_basement'], value=0)
35
+ yr_built = st.slider('Year Built', min_value=min_dict['yr_built'], max_value=max_dict['yr_built'], value=2000)
36
+ yr_renovated = st.slider('Year Renovated', min_value=min_dict['yr_renovated'], max_value=max_dict['yr_renovated'], value=2010)
37
+
38
+ st.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ new_pred = init_new_pred()
41
+ new_pred['bedrooms'] = bedrooms
42
+ new_pred['bathrooms'] = bathrooms
43
+ new_pred['sqft_living'] = sqft_living
44
+ new_pred['sqft_lot'] = sqft_lot
45
+ new_pred['floors'] = floors
46
+ new_pred['waterfront'] = int(waterfront)
47
+ new_pred['view'] = view
48
+ new_pred['condition'] = condition
49
+ new_pred['sqft_above'] = sqft_above
50
+ new_pred['sqft_basement'] = sqft_basement
51
+ new_pred['yr_built'] = yr_built
52
+ new_pred['yr_renovated'] = yr_renovated
53
+ new_pred[f'city_{city}'] = 1
54
+
55
+ # Process the prediction
56
+ new_pred = pd.DataFrame([new_pred])
57
+ new_pred = create_new_features(new_pred)
58
+ new_pred = bucketize(new_pred)
59
+ new_pred = normalize(new_pred)
60
+
61
+ # Predict the price
62
+ predicted_price = model.predict(new_pred)
63
 
64
  # Display the map in the second column
65
  with col2: