import streamlit as st import pandas as pd import pickle import json from utils import create_new_features, normalize, bucketize, init_new_pred st.set_page_config(layout="wide") # Load model and files with open('./trained_model.pkl', 'rb') as file: model = pickle.load(file) with open("./min_dict.json", "r") as f: min_dict = json.load(f) with open("./max_dict.json", "r") as f: max_dict = json.load(f) with open("./cities_geo.json", "r") as f: cities_geo = json.load(f) # Custom CSS to adjust the slider width st.markdown(""" """, unsafe_allow_html=True) # Create two columns: one for the city and one for the map col1, col2 = st.columns([1, 2]) # Adjust the width ratios as needed with col1: st.subheader('Features') with st.container(height=800, border=False): city = st.selectbox('City', list(cities_geo.keys())) # Display city dropdown in the first column waterfront = st.checkbox('Waterfront', value=False) st.markdown('
', unsafe_allow_html=True) st.markdown('', unsafe_allow_html=True) new_pred = init_new_pred() new_pred['bedrooms'] = bedrooms new_pred['bathrooms'] = bathrooms new_pred['sqft_living'] = sqft_living new_pred['sqft_lot'] = sqft_lot new_pred['floors'] = floors new_pred['waterfront'] = int(waterfront) new_pred['view'] = view new_pred['condition'] = condition new_pred['sqft_above'] = sqft_above new_pred['sqft_basement'] = sqft_basement new_pred['yr_built'] = yr_built new_pred['yr_renovated'] = yr_renovated new_pred[f'city_{city}'] = 1 # Process the prediction new_pred = pd.DataFrame([new_pred]) new_pred = create_new_features(new_pred) new_pred = bucketize(new_pred) new_pred = normalize(new_pred) # Predict the price predicted_price = model.predict(new_pred) with col2: # Placeholder for displaying the predicted price at the top price_placeholder = st.empty() price_placeholder.markdown( f"