Rhodham96 commited on
Commit
37e6a38
·
1 Parent(s): 5089ff4

changed format of columns

Browse files
Files changed (1) hide show
  1. app.py +61 -38
app.py CHANGED
@@ -5,7 +5,8 @@ import joblib
5
  def create_dataframe_from_user_input():
6
  """
7
  Collects user input for house features using Streamlit and
8
- returns a Pandas DataFrame.
 
9
  """
10
 
11
  # Define the lists of possible values for dropdown selections
@@ -24,7 +25,7 @@ def create_dataframe_from_user_input():
24
  flood_zone_type_list = ['NON_FLOOD_ZONE', 'POSSIBLE_FLOOD_ZONE', 'RECOGNIZED_FLOOD_ZONE',
25
  'RECOGNIZED_N_CIRCUMSCRIBED_FLOOD_ZONE', 'CIRCUMSCRIBED_WATERSIDE_ZONE',
26
  'CIRCUMSCRIBED_FLOOD_ZONE', 'POSSIBLE_N_CIRCUMSCRIBED_FLOOD_ZONE',
27
- 'POSSIBLE_N_CIRCUMSCRIBED_WATERSIDE_ZONE', 'RECOGNIZED_N_CIRCUMSCRIBED_WATERSIDE_FLOOD_ZONE']
28
  heating_type_list = ['GAS', 'FUELOIL', 'ELECTRIC', 'PELLET', 'WOOD', 'SOLAR', 'CARBON']
29
  kitchen_type_list = ['INSTALLED', 'HYPER_EQUIPPED', 'SEMI_EQUIPPED', 'NOT_INSTALLED',
30
  'USA_HYPER_EQUIPPED', 'USA_INSTALLED', 'USA_SEMI_EQUIPPED',
@@ -38,63 +39,87 @@ def create_dataframe_from_user_input():
38
  # Create Streamlit input fields
39
  st.header("Enter House Information")
40
 
41
- col1, col2 = st.columns(2) # Divide the layout in two columns
42
-
 
43
  with col1:
44
  property_type = st.selectbox("Property Type", type_list, key='type')
45
  property_subtype = st.selectbox("Subtype", subtype_list, key='subtype')
46
- bedroom_count = st.number_input("Bedroom Count", min_value=0, step=1, key='bedroomCount')
47
- bathroom_count = st.number_input("Bathroom Count", min_value=0, step=1, key='bathroomCount')
48
  province = st.selectbox("Province", province_list, key='province')
49
  locality = st.text_input("Locality", key='locality')
50
  post_code = st.number_input("Post Code", min_value=1000, max_value=9999, step=1, key='postCode')
51
- habitable_surface = st.number_input("Habitable Surface (sqm)", min_value=0.0, key='habitableSurface')
52
- room_count = st.number_input("Room Count", min_value=0, step=1, key='roomCount')
53
- monthly_cost = st.number_input("Monthly Cost (€)", min_value=0.0, key='monthlyCost')
54
- has_attic = st.selectbox("Has Attic", ['Yes', 'No'], key='hasAttic')
55
- has_basement = st.selectbox("Has Basement", ['Yes', 'No'], key='hasBasement')
56
- has_dressing_room = st.selectbox("Has Dressing Room", ['Yes', 'No'], key='hasDressingRoom')
57
- dining_room_surface = st.number_input("Dining Room Surface (sqm)", min_value=0.0, key='diningRoomSurface')
58
- has_dining_room = st.selectbox("Has Dining Room", ['Yes', 'No'], key='hasDiningRoom')
59
  building_condition = st.selectbox("Building Condition", building_condition_list, key='buildingCondition')
60
  building_construction_year = st.number_input("Building Construction Year", min_value=1000, max_value=2024, step=1, key='buildingConstructionYear')
61
  facade_count = st.number_input("Facade Count", min_value=0, step=1, key='facadeCount')
62
  floor_count = st.number_input("Floor Count", min_value=0, step=1, key='floorCount')
63
- street_facade_width = st.number_input("Street Facade Width (m)", min_value=0.0, key='streetFacadeWidth')
64
- has_lift = st.selectbox("Has Lift", ['Yes', 'No'], key='hasLift')
65
  flood_zone_type = st.selectbox("Flood Zone Type", flood_zone_type_list, key='floodZoneType')
66
- heating_type = st.selectbox("Heating Type", heating_type_list, key='heatingType')
67
- has_heat_pump = st.selectbox("Has Heat Pump", ['Yes', 'No'], key='hasHeatPump')
68
 
69
- with col2:
70
- has_photovoltaic_panels = st.selectbox("Has Photovoltaic Panels", ['Yes', 'No'], key='hasPhotovoltaicPanels')
71
- has_thermic_panels = st.selectbox("Has Thermic Panels", ['Yes', 'No'], key='hasThermicPanels')
 
 
 
 
 
 
 
 
 
 
 
 
72
  kitchen_surface = st.number_input("Kitchen Surface (sqm)", min_value=0.0, key='kitchenSurface')
73
  kitchen_type = st.selectbox("Kitchen Type", kitchen_type_list, key='kitchenType')
 
 
 
 
 
 
 
 
 
74
  land_surface = st.number_input("Land Surface (sqm)", min_value=0.0, key='landSurface')
75
- has_living_room = st.selectbox("Has Living Room", ['Yes', 'No'], key='hasLivingRoom')
76
- living_room_surface = st.number_input("Living Room Surface (sqm)", min_value=0.0, key='livingRoomSurface')
77
- has_balcony = st.selectbox("Has Balcony", ['Yes', 'No'], key='hasBalcony')
78
- has_garden = st.selectbox("Has Garden", ['Yes', 'No'], key='hasGarden')
79
  garden_surface = st.number_input("Garden Surface (sqm)", min_value=0.0, key='gardenSurface')
 
 
 
 
 
 
 
 
 
 
80
  garden_orientation = st.selectbox("Garden Orientation", garden_orientation_list, key='gardenOrientation')
 
 
 
 
81
  parking_count_indoor = st.number_input("Indoor Parking Count", min_value=0, step=1, key='parkingCountIndoor')
82
  parking_count_outdoor = st.number_input("Outdoor Parking Count", min_value=0, step=1, key='parkingCountOutdoor')
 
 
 
 
 
 
 
 
 
 
 
83
  has_air_conditioning = st.selectbox("Has Air Conditioning", ['Yes', 'No'], key='hasAirConditioning')
84
  has_armored_door = st.selectbox("Has Armored Door", ['Yes', 'No'], key='hasArmoredDoor')
85
  has_visiophone = st.selectbox("Has Visiophone", ['Yes', 'No'], key='hasVisiophone')
86
- has_office = st.selectbox("Has Office", ['Yes', 'No'], key='hasOffice')
87
- toilet_count = st.number_input("Toilet Count", min_value=0, step=1, key='toiletCount')
88
- has_swimming_pool = st.selectbox("Has Swimming Pool", ['Yes', 'No'], key='hasSwimmingPool')
89
  has_fireplace = st.selectbox("Has Fireplace", ['Yes', 'No'], key='hasFireplace')
90
- has_terrace = st.selectbox("Has Terrace", ['Yes', 'No'], key='hasTerrace')
91
- terrace_surface = st.number_input("Terrace Surface (sqm)", min_value=0.0, key='terraceSurface')
92
- terrace_orientation = st.selectbox("Terrace Orientation", terrace_orientation_list, key='terraceOrientation')
93
  accessible_disabled_people = st.selectbox("Accessible Disabled People", ['True', 'False'], key='accessibleDisabledPeople')
94
- epc_score = st.selectbox("EPC Score", epc_score_list, key='epcScore')
95
 
96
  # Create a button to trigger DataFrame creation
97
- if st.button("Predict"): # Changed button text to "Predict"
98
  # Create the DataFrame
99
  data = {
100
  'type': property_type,
@@ -147,9 +172,7 @@ def create_dataframe_from_user_input():
147
  'accessibleDisabledPeople': accessible_disabled_people == 'True',
148
  'epcScore': epc_score
149
  }
150
- df = pd.DataFrame(data, index=[0]) # Important : wrap data in a list.
151
- #st.subheader("Generated DataFrame")
152
- #st.dataframe(df)
153
  pipeline = joblib.load('saved/pipeline.pkl')
154
  model = joblib.load('saved/model.pkl')
155
  expected_columns = joblib.load('saved/columns.pkl')
@@ -161,8 +184,8 @@ def create_dataframe_from_user_input():
161
  df_test = df_test[expected_columns]
162
  preds = model.predict(df_test)
163
  st.subheader("Price prediction")
164
- st.write("House price : ", preds)
165
- return df # Return the dataframe.
166
 
167
  if __name__ == "__main__":
168
  create_dataframe_from_user_input()
 
5
  def create_dataframe_from_user_input():
6
  """
7
  Collects user input for house features using Streamlit and
8
+ returns a Pandas DataFrame. The input fields are organized
9
+ into categorized sections for better usability.
10
  """
11
 
12
  # Define the lists of possible values for dropdown selections
 
25
  flood_zone_type_list = ['NON_FLOOD_ZONE', 'POSSIBLE_FLOOD_ZONE', 'RECOGNIZED_FLOOD_ZONE',
26
  'RECOGNIZED_N_CIRCUMSCRIBED_FLOOD_ZONE', 'CIRCUMSCRIBED_WATERSIDE_ZONE',
27
  'CIRCUMSCRIBED_FLOOD_ZONE', 'POSSIBLE_N_CIRCUMSCRIBED_FLOOD_ZONE',
28
+ 'POSSIBLE_N_CIRCUMSCRIBED_WATERSIDE_ZONE', 'RECOGNIZED_N_CIRCUMSCRIBED_WATERSIDE_ZONE']
29
  heating_type_list = ['GAS', 'FUELOIL', 'ELECTRIC', 'PELLET', 'WOOD', 'SOLAR', 'CARBON']
30
  kitchen_type_list = ['INSTALLED', 'HYPER_EQUIPPED', 'SEMI_EQUIPPED', 'NOT_INSTALLED',
31
  'USA_HYPER_EQUIPPED', 'USA_INSTALLED', 'USA_SEMI_EQUIPPED',
 
39
  # Create Streamlit input fields
40
  st.header("Enter House Information")
41
 
42
+ # --- Property Details ---
43
+ st.subheader("Property Details")
44
+ col1, col2 = st.columns(2)
45
  with col1:
46
  property_type = st.selectbox("Property Type", type_list, key='type')
47
  property_subtype = st.selectbox("Subtype", subtype_list, key='subtype')
 
 
48
  province = st.selectbox("Province", province_list, key='province')
49
  locality = st.text_input("Locality", key='locality')
50
  post_code = st.number_input("Post Code", min_value=1000, max_value=9999, step=1, key='postCode')
51
+ with col2:
 
 
 
 
 
 
 
52
  building_condition = st.selectbox("Building Condition", building_condition_list, key='buildingCondition')
53
  building_construction_year = st.number_input("Building Construction Year", min_value=1000, max_value=2024, step=1, key='buildingConstructionYear')
54
  facade_count = st.number_input("Facade Count", min_value=0, step=1, key='facadeCount')
55
  floor_count = st.number_input("Floor Count", min_value=0, step=1, key='floorCount')
 
 
56
  flood_zone_type = st.selectbox("Flood Zone Type", flood_zone_type_list, key='floodZoneType')
57
+ epc_score = st.selectbox("EPC Score", epc_score_list, key='epcScore')
 
58
 
59
+ # --- Room Information ---
60
+ st.subheader("Room Information")
61
+ col3, col4 = st.columns(2)
62
+ with col3:
63
+ bedroom_count = st.number_input("Bedroom Count", min_value=0, step=1, key='bedroomCount')
64
+ bathroom_count = st.number_input("Bathroom Count", min_value=0, step=1, key='bathroomCount')
65
+ room_count = st.number_input("Room Count", min_value=0, step=1, key='roomCount')
66
+ has_attic = st.selectbox("Has Attic", ['Yes', 'No'], key='hasAttic')
67
+ has_basement = st.selectbox("Has Basement", ['Yes', 'No'], key='hasBasement')
68
+ has_dressing_room = st.selectbox("Has Dressing Room", ['Yes', 'No'], key='hasDressingRoom')
69
+ has_dining_room = st.selectbox("Has Dining Room", ['Yes', 'No'], key='hasDiningRoom')
70
+ dining_room_surface = st.number_input("Dining Room Surface (sqm)", min_value=0.0, key='diningRoomSurface')
71
+ with col4:
72
+ has_living_room = st.selectbox("Has Living Room", ['Yes', 'No'], key='hasLivingRoom')
73
+ living_room_surface = st.number_input("Living Room Surface (sqm)", min_value=0.0, key='livingRoomSurface')
74
  kitchen_surface = st.number_input("Kitchen Surface (sqm)", min_value=0.0, key='kitchenSurface')
75
  kitchen_type = st.selectbox("Kitchen Type", kitchen_type_list, key='kitchenType')
76
+ toilet_count = st.number_input("Toilet Count", min_value=0, step=1, key='toiletCount')
77
+ has_office = st.selectbox("Has Office", ['Yes', 'No'], key='hasOffice')
78
+ has_lift = st.selectbox("Has Lift", ['Yes', 'No'], key='hasLift')
79
+
80
+ # --- Surface Areas ---
81
+ st.subheader("Surface Areas")
82
+ col5, col6 = st.columns(2)
83
+ with col5:
84
+ habitable_surface = st.number_input("Habitable Surface (sqm)", min_value=0.0, key='habitableSurface')
85
  land_surface = st.number_input("Land Surface (sqm)", min_value=0.0, key='landSurface')
 
 
 
 
86
  garden_surface = st.number_input("Garden Surface (sqm)", min_value=0.0, key='gardenSurface')
87
+ with col6:
88
+ terrace_surface = st.number_input("Terrace Surface (sqm)", min_value=0.0, key='terraceSurface')
89
+ street_facade_width = st.number_input("Street Facade Width (m)", min_value=0.0, key='streetFacadeWidth')
90
+ monthly_cost = st.number_input("Monthly Cost (€)", min_value=0.0, key='monthlyCost')
91
+
92
+ # --- Outdoor Features ---
93
+ st.subheader("Outdoor Features")
94
+ col7, col8 = st.columns(2)
95
+ with col7:
96
+ has_garden = st.selectbox("Has Garden", ['Yes', 'No'], key='hasGarden')
97
  garden_orientation = st.selectbox("Garden Orientation", garden_orientation_list, key='gardenOrientation')
98
+ has_balcony = st.selectbox("Has Balcony", ['Yes', 'No'], key='hasBalcony')
99
+ has_terrace = st.selectbox("Has Terrace", ['Yes', 'No'], key='hasTerrace')
100
+ terrace_orientation = st.selectbox("Terrace Orientation", terrace_orientation_list, key='terraceOrientation')
101
+ with col8:
102
  parking_count_indoor = st.number_input("Indoor Parking Count", min_value=0, step=1, key='parkingCountIndoor')
103
  parking_count_outdoor = st.number_input("Outdoor Parking Count", min_value=0, step=1, key='parkingCountOutdoor')
104
+ has_swimming_pool = st.selectbox("Has Swimming Pool", ['Yes', 'No'], key='hasSwimmingPool')
105
+
106
+ # --- Additional Features ---
107
+ st.subheader("Additional Features")
108
+ col9, col10 = st.columns(2)
109
+ with col9:
110
+ heating_type = st.selectbox("Heating Type", heating_type_list, key='heatingType')
111
+ has_heat_pump = st.selectbox("Has Heat Pump", ['Yes', 'No'], key='hasHeatPump')
112
+ has_photovoltaic_panels = st.selectbox("Has Photovoltaic Panels", ['Yes', 'No'], key='hasPhotovoltaicPanels')
113
+ has_thermic_panels = st.selectbox("Has Thermic Panels", ['Yes', 'No'], key='hasThermicPanels')
114
+ with col10:
115
  has_air_conditioning = st.selectbox("Has Air Conditioning", ['Yes', 'No'], key='hasAirConditioning')
116
  has_armored_door = st.selectbox("Has Armored Door", ['Yes', 'No'], key='hasArmoredDoor')
117
  has_visiophone = st.selectbox("Has Visiophone", ['Yes', 'No'], key='hasVisiophone')
 
 
 
118
  has_fireplace = st.selectbox("Has Fireplace", ['Yes', 'No'], key='hasFireplace')
 
 
 
119
  accessible_disabled_people = st.selectbox("Accessible Disabled People", ['True', 'False'], key='accessibleDisabledPeople')
 
120
 
121
  # Create a button to trigger DataFrame creation
122
+ if st.button("Predict"):
123
  # Create the DataFrame
124
  data = {
125
  'type': property_type,
 
172
  'accessibleDisabledPeople': accessible_disabled_people == 'True',
173
  'epcScore': epc_score
174
  }
175
+ df = pd.DataFrame(data, index=[0])
 
 
176
  pipeline = joblib.load('saved/pipeline.pkl')
177
  model = joblib.load('saved/model.pkl')
178
  expected_columns = joblib.load('saved/columns.pkl')
 
184
  df_test = df_test[expected_columns]
185
  preds = model.predict(df_test)
186
  st.subheader("Price prediction")
187
+ st.markdown(f"<h1 style='text-align: center; color: red;'>{preds[0]:.2f} €</h1>", unsafe_allow_html=True)
188
+ return df
189
 
190
  if __name__ == "__main__":
191
  create_dataframe_from_user_input()