fernandobriann commited on
Commit
83db939
Β·
verified Β·
1 Parent(s): fe997e8

sidebar fix

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