sidebar fix
Browse files
app.py
CHANGED
|
@@ -1,415 +1,419 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
|
| 3 |
-
import streamlit as st
|
| 4 |
-
import pandas as pd
|
| 5 |
-
|
| 6 |
-
from prediction import recommend_phones
|
| 7 |
-
from eda import render_eda, get_dataset_info
|
| 8 |
-
|
| 9 |
-
# =========================================================
|
| 10 |
-
# PAGE CONFIG
|
| 11 |
-
# =========================================================
|
| 12 |
-
|
| 13 |
-
st.set_page_config(
|
| 14 |
-
page_title="PhoneFinder",
|
| 15 |
-
page_icon="π±",
|
| 16 |
-
layout="wide",
|
| 17 |
-
initial_sidebar_state="expanded"
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
# =========================================================
|
| 21 |
-
# CSS
|
| 22 |
-
# =========================================================
|
| 23 |
-
|
| 24 |
-
st.markdown("""
|
| 25 |
-
<style>
|
| 26 |
-
|
| 27 |
-
/* Hide Streamlit header */
|
| 28 |
-
header {visibility: hidden;}
|
| 29 |
-
|
| 30 |
-
/*
|
| 31 |
-
[data-testid="
|
| 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 |
-
text-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
font-size: 1.
|
| 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 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
""
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
<
|
| 397 |
-
|
| 398 |
-
<
|
| 399 |
-
|
| 400 |
-
<
|
| 401 |
-
|
| 402 |
-
</
|
| 403 |
-
|
| 404 |
-
<div class="tag">
|
| 405 |
-
{int(row['
|
| 406 |
-
</div>
|
| 407 |
-
|
| 408 |
-
<div class="tag">
|
| 409 |
-
{int(row['
|
| 410 |
-
</div>
|
| 411 |
-
|
| 412 |
-
<
|
| 413 |
-
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
st.progress(int(score))
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
from prediction import recommend_phones
|
| 7 |
+
from eda import render_eda, get_dataset_info
|
| 8 |
+
|
| 9 |
+
# =========================================================
|
| 10 |
+
# PAGE CONFIG
|
| 11 |
+
# =========================================================
|
| 12 |
+
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="PhoneFinder",
|
| 15 |
+
page_icon="π±",
|
| 16 |
+
layout="wide",
|
| 17 |
+
initial_sidebar_state="expanded"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# =========================================================
|
| 21 |
+
# CSS
|
| 22 |
+
# =========================================================
|
| 23 |
+
|
| 24 |
+
st.markdown("""
|
| 25 |
+
<style>
|
| 26 |
+
|
| 27 |
+
/* Hide Streamlit header */
|
| 28 |
+
header {visibility: hidden;}
|
| 29 |
+
|
| 30 |
+
/* Always show sidebar toggle button */
|
| 31 |
+
[data-testid="collapsedControl"] {
|
| 32 |
+
display: flex !important;
|
| 33 |
+
visibility: visible !important;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* Background */
|
| 37 |
+
[data-testid="stAppViewContainer"] {
|
| 38 |
+
background:
|
| 39 |
+
radial-gradient(circle at top,
|
| 40 |
+
#111827 0%,
|
| 41 |
+
#020617 45%,
|
| 42 |
+
#000000 100%);
|
| 43 |
+
color: white;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Main container */
|
| 47 |
+
.block-container {
|
| 48 |
+
max-width: 1150px;
|
| 49 |
+
padding-top: 1rem;
|
| 50 |
+
padding-bottom: 2rem;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* Sidebar */
|
| 54 |
+
[data-testid="stSidebar"] {
|
| 55 |
+
background: #020617;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Hero Title */
|
| 59 |
+
.hero-title {
|
| 60 |
+
text-align: center;
|
| 61 |
+
font-size: 4rem;
|
| 62 |
+
font-weight: 800;
|
| 63 |
+
background: linear-gradient(90deg, #60a5fa, #8b5cf6);
|
| 64 |
+
-webkit-background-clip: text;
|
| 65 |
+
-webkit-text-fill-color: transparent;
|
| 66 |
+
margin-bottom: 0.5rem;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
/* Subtitle */
|
| 70 |
+
.subtitle {
|
| 71 |
+
text-align: center;
|
| 72 |
+
color: #94a3b8;
|
| 73 |
+
font-size: 1.15rem;
|
| 74 |
+
margin-bottom: 2rem;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/* Section Title */
|
| 78 |
+
.section-title {
|
| 79 |
+
font-size: 1.8rem;
|
| 80 |
+
font-weight: 700;
|
| 81 |
+
margin-bottom: 10px;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* Feature Card */
|
| 85 |
+
.feature-card {
|
| 86 |
+
background: rgba(255,255,255,0.04);
|
| 87 |
+
border-radius: 22px;
|
| 88 |
+
padding: 24px;
|
| 89 |
+
border: 1px solid rgba(255,255,255,0.05);
|
| 90 |
+
text-align: center;
|
| 91 |
+
backdrop-filter: blur(10px);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/* Result Card */
|
| 95 |
+
.result-card {
|
| 96 |
+
background: rgba(255,255,255,0.05);
|
| 97 |
+
border-radius: 22px;
|
| 98 |
+
padding: 24px;
|
| 99 |
+
border: 1px solid rgba(255,255,255,0.06);
|
| 100 |
+
margin-bottom: 18px;
|
| 101 |
+
backdrop-filter: blur(12px);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
/* Tags */
|
| 105 |
+
.tag {
|
| 106 |
+
display: inline-block;
|
| 107 |
+
padding: 6px 12px;
|
| 108 |
+
border-radius: 999px;
|
| 109 |
+
background: rgba(99,102,241,0.18);
|
| 110 |
+
color: #c7d2fe;
|
| 111 |
+
font-size: 0.82rem;
|
| 112 |
+
margin-right: 8px;
|
| 113 |
+
margin-top: 8px;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
/* Button */
|
| 117 |
+
.stButton > button {
|
| 118 |
+
width: 100%;
|
| 119 |
+
height: 52px;
|
| 120 |
+
border-radius: 18px;
|
| 121 |
+
border: none;
|
| 122 |
+
font-weight: 700;
|
| 123 |
+
color: white;
|
| 124 |
+
background: linear-gradient(to right, #6366f1, #8b5cf6);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.stButton > button:hover {
|
| 128 |
+
transform: scale(1.02);
|
| 129 |
+
box-shadow: 0 0 25px rgba(139,92,246,0.45);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
/* Segment Badge */
|
| 133 |
+
.segment-badge {
|
| 134 |
+
display:inline-block;
|
| 135 |
+
padding:8px 16px;
|
| 136 |
+
border-radius:999px;
|
| 137 |
+
color:white;
|
| 138 |
+
font-weight:600;
|
| 139 |
+
font-size:0.9rem;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
</style>
|
| 143 |
+
""", unsafe_allow_html=True)
|
| 144 |
+
|
| 145 |
+
# =========================================================
|
| 146 |
+
# SIDEBAR
|
| 147 |
+
# =========================================================
|
| 148 |
+
|
| 149 |
+
with st.sidebar:
|
| 150 |
+
|
| 151 |
+
st.image(
|
| 152 |
+
"FTDS-053-RMT-GROUP1-LOGO.png",
|
| 153 |
+
width=180
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
st.markdown("## π± Navigation")
|
| 157 |
+
|
| 158 |
+
page = st.radio(
|
| 159 |
+
"",
|
| 160 |
+
[
|
| 161 |
+
"π Home",
|
| 162 |
+
"π EDA",
|
| 163 |
+
"π Recommendation"
|
| 164 |
+
]
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
# =========================================================
|
| 168 |
+
# HOME PAGE
|
| 169 |
+
# =========================================================
|
| 170 |
+
|
| 171 |
+
if page == "π Home":
|
| 172 |
+
|
| 173 |
+
col1, col2, col3 = st.columns([1,2,1])
|
| 174 |
+
|
| 175 |
+
with col2:
|
| 176 |
+
st.image(
|
| 177 |
+
"FTDS-053-RMT-GROUP1-LOGO.png",
|
| 178 |
+
width=320
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
st.markdown(
|
| 182 |
+
'<div class="hero-title">PhoneFinder</div>',
|
| 183 |
+
unsafe_allow_html=True
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
st.markdown(
|
| 187 |
+
'<div class="subtitle">AI-Powered Smartphone Recommendation System</div>',
|
| 188 |
+
unsafe_allow_html=True
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 192 |
+
|
| 193 |
+
# =====================================================
|
| 194 |
+
# PROBLEM
|
| 195 |
+
# =====================================================
|
| 196 |
+
|
| 197 |
+
st.markdown(
|
| 198 |
+
'<div class="section-title">β The Problem</div>',
|
| 199 |
+
unsafe_allow_html=True
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
st.write("""
|
| 203 |
+
With hundreds of smartphone options available across different price ranges,
|
| 204 |
+
users often struggle to find devices that truly match their needs and budget.
|
| 205 |
+
|
| 206 |
+
Many people purchase smartphones based only on trends or brand popularity,
|
| 207 |
+
instead of choosing devices optimized for their actual use case.
|
| 208 |
+
""")
|
| 209 |
+
|
| 210 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 211 |
+
|
| 212 |
+
# =====================================================
|
| 213 |
+
# SOLUTION
|
| 214 |
+
# =====================================================
|
| 215 |
+
|
| 216 |
+
st.markdown(
|
| 217 |
+
'<div class="section-title">π‘ Our Solution</div>',
|
| 218 |
+
unsafe_allow_html=True
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
st.write("""
|
| 222 |
+
PhoneFinder provides smartphone recommendations based on broad user priorities such as:
|
| 223 |
+
|
| 224 |
+
- Balanced
|
| 225 |
+
- Gaming / Performance
|
| 226 |
+
- Camera-Focused
|
| 227 |
+
- Battery-Focused
|
| 228 |
+
|
| 229 |
+
The system combines clustering and similarity-based recommendation techniques
|
| 230 |
+
to recommend smartphones that best match the user's budget and preferences.
|
| 231 |
+
""")
|
| 232 |
+
|
| 233 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 234 |
+
|
| 235 |
+
# =====================================================
|
| 236 |
+
# DATASET INFO
|
| 237 |
+
# =====================================================
|
| 238 |
+
|
| 239 |
+
info = get_dataset_info()
|
| 240 |
+
|
| 241 |
+
col1, col2, col3 = st.columns(3)
|
| 242 |
+
|
| 243 |
+
with col1:
|
| 244 |
+
st.markdown(f"""
|
| 245 |
+
<div class="feature-card">
|
| 246 |
+
π±<br><br>
|
| 247 |
+
<h2>{info['total_phones']}</h2>
|
| 248 |
+
Smartphones
|
| 249 |
+
</div>
|
| 250 |
+
""", unsafe_allow_html=True)
|
| 251 |
+
|
| 252 |
+
with col2:
|
| 253 |
+
st.markdown(f"""
|
| 254 |
+
<div class="feature-card">
|
| 255 |
+
π°<br><br>
|
| 256 |
+
<h2>${info['avg_price']}</h2>
|
| 257 |
+
Average Price
|
| 258 |
+
</div>
|
| 259 |
+
""", unsafe_allow_html=True)
|
| 260 |
+
|
| 261 |
+
with col3:
|
| 262 |
+
st.markdown("""
|
| 263 |
+
<div class="feature-card">
|
| 264 |
+
π―<br><br>
|
| 265 |
+
<h2>4</h2>
|
| 266 |
+
Recommendation Types
|
| 267 |
+
</div>
|
| 268 |
+
""", unsafe_allow_html=True)
|
| 269 |
+
|
| 270 |
+
# =========================================================
|
| 271 |
+
# EDA PAGE
|
| 272 |
+
# =========================================================
|
| 273 |
+
|
| 274 |
+
elif page == "π EDA":
|
| 275 |
+
|
| 276 |
+
st.markdown(
|
| 277 |
+
'<div class="hero-title">Exploratory Data Analysis</div>',
|
| 278 |
+
unsafe_allow_html=True
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
st.markdown(
|
| 282 |
+
'<div class="subtitle">Understanding smartphone market patterns and specifications</div>',
|
| 283 |
+
unsafe_allow_html=True
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 287 |
+
|
| 288 |
+
render_eda()
|
| 289 |
+
|
| 290 |
+
# =========================================================
|
| 291 |
+
# RECOMMENDATION PAGE
|
| 292 |
+
# =========================================================
|
| 293 |
+
|
| 294 |
+
elif page == "π Recommendation":
|
| 295 |
+
|
| 296 |
+
st.markdown(
|
| 297 |
+
'<div class="hero-title">Find Your Smartphone</div>',
|
| 298 |
+
unsafe_allow_html=True
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
st.markdown(
|
| 302 |
+
'<div class="subtitle">AI-powered smartphone recommendation engine</div>',
|
| 303 |
+
unsafe_allow_html=True
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 307 |
+
|
| 308 |
+
col1, col2 = st.columns(2)
|
| 309 |
+
|
| 310 |
+
with col1:
|
| 311 |
+
|
| 312 |
+
budget = st.slider(
|
| 313 |
+
"Budget (USD)",
|
| 314 |
+
min_value=50,
|
| 315 |
+
max_value=2000,
|
| 316 |
+
value=500,
|
| 317 |
+
step=50
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
top_n = st.slider(
|
| 321 |
+
"Top N Results",
|
| 322 |
+
min_value=1,
|
| 323 |
+
max_value=10,
|
| 324 |
+
value=5
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
with col2:
|
| 328 |
+
|
| 329 |
+
priority = st.selectbox(
|
| 330 |
+
"Priority",
|
| 331 |
+
[
|
| 332 |
+
"balanced",
|
| 333 |
+
"gaming",
|
| 334 |
+
"camera",
|
| 335 |
+
"battery"
|
| 336 |
+
]
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 340 |
+
|
| 341 |
+
search = st.button("π Find Phones")
|
| 342 |
+
|
| 343 |
+
# =====================================================
|
| 344 |
+
# RESULTS
|
| 345 |
+
# =====================================================
|
| 346 |
+
|
| 347 |
+
if search:
|
| 348 |
+
|
| 349 |
+
with st.spinner("Finding best smartphone matches..."):
|
| 350 |
+
|
| 351 |
+
results, seg_name = recommend_phones(
|
| 352 |
+
budget_usd=budget,
|
| 353 |
+
priority=priority,
|
| 354 |
+
top_n=top_n
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 358 |
+
|
| 359 |
+
SEG_COLORS = {
|
| 360 |
+
'Budget': '#534AB7',
|
| 361 |
+
'Camera-focused': '#993C1D',
|
| 362 |
+
'Gaming / Performance': '#0F6E56',
|
| 363 |
+
'Flagship': '#854F0B',
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
color = SEG_COLORS.get(
|
| 367 |
+
seg_name.split(' (')[0],
|
| 368 |
+
'#534AB7'
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
st.markdown(
|
| 372 |
+
f"""
|
| 373 |
+
<div class="segment-badge"
|
| 374 |
+
style="background:{color}">
|
| 375 |
+
Matched Segment: {seg_name}
|
| 376 |
+
</div>
|
| 377 |
+
""",
|
| 378 |
+
unsafe_allow_html=True
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 382 |
+
|
| 383 |
+
for rank, row in results.iterrows():
|
| 384 |
+
|
| 385 |
+
name = f"{row.get('brand','')} {row.get('model','')}".strip()
|
| 386 |
+
|
| 387 |
+
price = (
|
| 388 |
+
f"${row['price']:.0f}"
|
| 389 |
+
if pd.notna(row.get('price'))
|
| 390 |
+
else 'N/A'
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
score = row.get('Match Score (%)', 0)
|
| 394 |
+
|
| 395 |
+
st.markdown(f"""
|
| 396 |
+
<div class="result-card">
|
| 397 |
+
|
| 398 |
+
<h2>#{rank} {name}</h2>
|
| 399 |
+
|
| 400 |
+
<h3>{price}</h3>
|
| 401 |
+
|
| 402 |
+
<p><b>Match Score:</b> {score:.1f}%</p>
|
| 403 |
+
|
| 404 |
+
<div class="tag">
|
| 405 |
+
{int(row['ram'])} GB RAM
|
| 406 |
+
</div>
|
| 407 |
+
|
| 408 |
+
<div class="tag">
|
| 409 |
+
{int(row['battery_capacity'])} mAh
|
| 410 |
+
</div>
|
| 411 |
+
|
| 412 |
+
<div class="tag">
|
| 413 |
+
{int(row['main_camera_mp'])} MP Camera
|
| 414 |
+
</div>
|
| 415 |
+
|
| 416 |
+
</div>
|
| 417 |
+
""", unsafe_allow_html=True)
|
| 418 |
+
|
| 419 |
st.progress(int(score))
|