import streamlit as st import pickle import numpy as np # Set page configuration st.set_page_config( page_title="Laptop Price Predictor", page_icon="💻", layout="wide", initial_sidebar_state="expanded" ) # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Load models try: pipe = pickle.load(open('pipe.pkl','rb')) df = pickle.load(open('df.pkl','rb')) except FileNotFoundError: st.error("⚠️ Model files not found! Please ensure 'pipe.pkl' and 'df.pkl' are in the same directory.") st.stop() # Header st.markdown('

💻 Laptop Price Predictor

', unsafe_allow_html=True) st.markdown('

Get instant price predictions for your ideal laptop configuration

', unsafe_allow_html=True) # Create columns for better layout col1, col2 = st.columns([1, 1]) with col1: st.markdown('

🏷️ Basic Specifications

', unsafe_allow_html=True) # Brand company = st.selectbox( '🏢 Brand', df['Company'].unique(), help="Select the laptop manufacturer" ) # Type of laptop type = st.selectbox( '💼 Type', df['TypeName'].unique(), help="Choose the laptop category" ) # RAM ram = st.selectbox( '🧠 RAM (GB)', [2,4,6,8,12,16,24,32,64], index=3, # Default to 8GB help="Select the amount of RAM" ) # Weight weight = st.number_input( '⚖️ Weight (kg)', min_value=0.5, max_value=5.0, value=2.0, step=0.1, help="Enter the laptop weight in kilograms" ) # OS os = st.selectbox( '💿 Operating System', df['os'].unique(), help="Select the operating system" ) with col2: st.markdown('

🖥️ Display & Hardware

', unsafe_allow_html=True) # Screen size screen_size = st.slider( '📏 Screen Size (inches)', 10.0, 18.0, 13.0, step=0.1, help="Adjust the screen size" ) # Resolution resolution = st.selectbox( '🖼️ Screen Resolution', ['1920x1080','1366x768','1600x900','3840x2160','3200x1800','2880x1800','2560x1600','2560x1440','2304x1440'], index=0, # Default to 1920x1080 help="Select the display resolution" ) # Touchscreen touchscreen = st.selectbox( '👆 Touchscreen', ['No','Yes'], help="Does the laptop have a touchscreen?" ) # IPS ips = st.selectbox( '🎨 IPS Display', ['No','Yes'], help="Does the laptop have an IPS display?" ) # Storage and Processing section st.markdown('

💾 Storage & Processing

', unsafe_allow_html=True) col3, col4, col5 = st.columns(3) with col3: # HDD hdd = st.selectbox( '💽 HDD Storage (GB)', [0,128,256,512,1024,2048], index=0, # Default to 0 help="Select HDD storage capacity" ) with col4: # SSD ssd = st.selectbox( '⚡ SSD Storage (GB)', [0,8,128,256,512,1024], index=3, # Default to 256GB help="Select SSD storage capacity" ) with col5: # CPU cpu = st.selectbox( '🔧 CPU Brand', df['Cpu brand'].unique(), help="Select the processor brand" ) # GPU section st.markdown('

🎮 Graphics

', unsafe_allow_html=True) gpu = st.selectbox( '🖥️ GPU Brand', df['Gpu brand'].unique(), help="Select the graphics card brand" ) # Prediction section st.markdown('

🔮 Price Prediction

', unsafe_allow_html=True) # Add some spacing st.markdown("
", unsafe_allow_html=True) # Center the predict button col_btn1, col_btn2, col_btn3 = st.columns([1, 2, 1]) with col_btn2: predict_button = st.button('🎯 Predict Price', use_container_width=True) if predict_button: with st.spinner('🔄 Calculating price...'): # Query processing (original logic preserved) ppi = None if touchscreen == 'Yes': touchscreen = 1 else: touchscreen = 0 if ips == 'Yes': ips = 1 else: ips = 0 X_res = int(resolution.split('x')[0]) Y_res = int(resolution.split('x')[1]) ppi = ((X_res**2) + (Y_res**2))**0.5/screen_size query = np.array([company,type,ram,weight,touchscreen,ips,ppi,cpu,hdd,ssd,gpu,os],dtype=object) query = query.reshape(1,12) predicted_price = int(np.exp(pipe.predict(query)[0])) # Display result with enhanced styling st.markdown(f'''
💰 Predicted Price: ${predicted_price:,}
''', unsafe_allow_html=True) # Additional info st.success(f"✅ Price prediction completed successfully!") # Display configuration summary with st.expander("📋 Configuration Summary"): st.write(f"**Brand:** {company}") st.write(f"**Type:** {type}") st.write(f"**RAM:** {ram} GB") st.write(f"**Weight:** {weight} kg") st.write(f"**Screen:** {screen_size}\" {resolution} {'with Touchscreen' if touchscreen == 1 else ''}") st.write(f"**Display:** {'IPS' if ips == 1 else 'Standard'}") st.write(f"**Storage:** {f'{hdd}GB HDD + ' if hdd > 0 else ''}{ssd}GB SSD") st.write(f"**CPU:** {cpu}") st.write(f"**GPU:** {gpu}") st.write(f"**OS:** {os}") # Footer st.markdown("---") st.markdown( '

Built with ❤️ using Streamlit | Laptop Price Prediction System

', unsafe_allow_html=True )