File size: 7,799 Bytes
dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 dff9999 9aa5184 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | 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("""
<style>
.main-header {
text-align: center;
color: #2E86AB;
font-size: 3rem;
font-weight: bold;
margin-bottom: 2rem;
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}
.sub-header {
text-align: center;
color: #666;
font-size: 1.2rem;
margin-bottom: 3rem;
}
.section-header {
color: #2E86AB;
font-size: 1.5rem;
font-weight: bold;
margin-top: 2rem;
margin-bottom: 1rem;
border-bottom: 2px solid #2E86AB;
padding-bottom: 0.5rem;
}
.price-result {
background: linear-gradient(45deg, #2E86AB, #A23B72);
color: white;
padding: 2rem;
border-radius: 15px;
text-align: center;
font-size: 2rem;
font-weight: bold;
margin: 2rem 0;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.02); }
100% { transform: scale(1); }
}
.stButton > button {
background: linear-gradient(45deg, #2E86AB, #A23B72);
color: white;
border: none;
padding: 0.75rem 2rem;
font-size: 1.2rem;
font-weight: bold;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
width: 100%;
}
.stButton > button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}
.feature-card {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 10px;
border-left: 4px solid #2E86AB;
margin-bottom: 1rem;
}
.stSelectbox > div > div {
border-radius: 8px;
}
.stSlider > div > div {
color: #2E86AB;
}
</style>
""", 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('<h1 class="main-header">๐ป Laptop Price Predictor</h1>', unsafe_allow_html=True)
st.markdown('<p class="sub-header">Get instant price predictions for your ideal laptop configuration</p>', unsafe_allow_html=True)
# Create columns for better layout
col1, col2 = st.columns([1, 1])
with col1:
st.markdown('<h3 class="section-header">๐ท๏ธ Basic Specifications</h3>', 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('<h3 class="section-header">๐ฅ๏ธ Display & Hardware</h3>', 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('<h3 class="section-header">๐พ Storage & Processing</h3>', 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('<h3 class="section-header">๐ฎ Graphics</h3>', unsafe_allow_html=True)
gpu = st.selectbox(
'๐ฅ๏ธ GPU Brand',
df['Gpu brand'].unique(),
help="Select the graphics card brand"
)
# Prediction section
st.markdown('<h3 class="section-header">๐ฎ Price Prediction</h3>', unsafe_allow_html=True)
# Add some spacing
st.markdown("<br>", 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'''
<div class="price-result">
๐ฐ Predicted Price: ${predicted_price:,}
</div>
''', 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(
'<p style="text-align: center; color: #666; margin-top: 2rem;">Built with โค๏ธ using Streamlit | Laptop Price Prediction System</p>',
unsafe_allow_html=True
) |