lenawilli commited on
Commit
1898fe7
Β·
verified Β·
1 Parent(s): 70dfbbc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +52 -55
src/streamlit_app.py CHANGED
@@ -331,69 +331,66 @@ else:
331
  def make_clickable_title(row):
332
  return f"<a href='/?movie_id={row['movieId']}' target='_self'>{row['clean_title']}</a>"
333
 
334
- def show_table(dataframe, label, checkbox_key):
335
- show_all = st.checkbox(f"Show all in {label}", key=checkbox_key)
336
- st.subheader(label)
337
- display_df = dataframe.copy()
338
- if not show_all:
339
- display_df = display_df.head(5)
340
-
341
- if display_df.empty:
342
- st.caption("No entries.")
343
- return
344
-
345
- df_display = display_df[["movieId", "clean_title", "rating", "genres", "year", "timestamp"]].copy()
346
- df_display["Title"] = df_display.apply(
347
- lambda row: f"<a href='/?movie_id={row['movieId']}' target='_self' style='color:#e63946;text-decoration:none;'>{row['clean_title']}</a>",
348
- axis=1
349
- )
350
- df_display["Rated"] = df_display["rating"].apply(render_star_rating)
351
- df_display["Date"] = df_display["timestamp"].dt.strftime("%Y-%m-%d")
352
-
353
- df_display = df_display[["Title", "Rated", "genres", "year", "Date"]]
354
-
355
- st.markdown("""
356
- <style>
357
- .styled-table {
358
- width: 100%;
359
- border-collapse: collapse;
360
- font-size: 16px;
361
- font-family: 'Segoe UI', sans-serif;
362
- background-color: #1a1a1a;
363
- color: #f0f0f0;
364
- border-radius: 8px;
365
- overflow: hidden;
366
- margin-bottom: 2em;
367
- }
368
- .styled-table thead tr {
369
- background-color: #5c1a1b;
370
- text-align: left;
371
- }
372
- .styled-table th, .styled-table td {
373
- padding: 12px 15px;
374
- }
375
- .styled-table tbody tr {
376
- border-bottom: 1px solid #333;
377
- }
378
- .styled-table tbody tr:hover {
379
- background-color: #2a2a2a;
380
- }
381
- </style>
382
- """, unsafe_allow_html=True)
383
-
384
- html_table = df_display.to_html(classes='styled-table', escape=False, index=False)
385
- st.markdown(html_table, unsafe_allow_html=True)
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
 
388
- # Recently Rated
389
  recent = merged.sort_values("timestamp", ascending=False)
390
  show_table(recent, "πŸ•“ Recently Rated", checkbox_key="recently_rated")
391
 
392
- # Top Rated
393
  top = merged[merged["rating"] >= 4].sort_values(["rating", "timestamp"], ascending=[False, False])
394
  show_table(top, "🌟 Top Rated", checkbox_key="top_rated")
395
 
396
- # Worst Rated
397
  worst = merged[merged["rating"] <= 2].sort_values(["rating", "timestamp"], ascending=[True, False])
398
  show_table(worst, "😞 Worst Rated", checkbox_key="worst_rated")
399
 
 
 
331
  def make_clickable_title(row):
332
  return f"<a href='/?movie_id={row['movieId']}' target='_self'>{row['clean_title']}</a>"
333
 
334
+ def show_table(dataframe, label, checkbox_key):
335
+ show_all = st.checkbox(f"Show all in {label}", key=checkbox_key)
336
+ st.subheader(label)
337
+ display_df = dataframe.copy()
338
+ if not show_all:
339
+ display_df = display_df.head(5)
340
+
341
+ if display_df.empty:
342
+ st.caption("No entries.")
343
+ return
344
+
345
+ df_display = display_df[["movieId", "clean_title", "rating", "genres", "year", "timestamp"]].copy()
346
+ df_display["Title"] = df_display.apply(
347
+ lambda row: f"<a href='/?movie_id={row['movieId']}' target='_self' style='color:#e63946;text-decoration:none;'>{row['clean_title']}</a>",
348
+ axis=1
349
+ )
350
+ df_display["Rated"] = df_display["rating"].apply(render_star_rating)
351
+ df_display["Date"] = df_display["timestamp"].dt.strftime("%Y-%m-%d")
352
+ df_display = df_display[["Title", "Rated", "genres", "year", "Date"]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
+ st.markdown("""
355
+ <style>
356
+ .styled-table {
357
+ width: 100%;
358
+ border-collapse: collapse;
359
+ font-size: 16px;
360
+ font-family: 'Segoe UI', sans-serif;
361
+ background-color: #1a1a1a;
362
+ color: #f0f0f0;
363
+ border-radius: 8px;
364
+ overflow: hidden;
365
+ margin-bottom: 2em;
366
+ }
367
+ .styled-table thead tr {
368
+ background-color: #5c1a1b;
369
+ text-align: left;
370
+ }
371
+ .styled-table th, .styled-table td {
372
+ padding: 12px 15px;
373
+ }
374
+ .styled-table tbody tr {
375
+ border-bottom: 1px solid #333;
376
+ }
377
+ .styled-table tbody tr:hover {
378
+ background-color: #2a2a2a;
379
+ }
380
+ </style>
381
+ """, unsafe_allow_html=True)
382
+
383
+ html_table = df_display.to_html(classes='styled-table', escape=False, index=False)
384
+ st.markdown(html_table, unsafe_allow_html=True)
385
 
386
+ # Show all tables
387
  recent = merged.sort_values("timestamp", ascending=False)
388
  show_table(recent, "πŸ•“ Recently Rated", checkbox_key="recently_rated")
389
 
 
390
  top = merged[merged["rating"] >= 4].sort_values(["rating", "timestamp"], ascending=[False, False])
391
  show_table(top, "🌟 Top Rated", checkbox_key="top_rated")
392
 
 
393
  worst = merged[merged["rating"] <= 2].sort_values(["rating", "timestamp"], ascending=[True, False])
394
  show_table(worst, "😞 Worst Rated", checkbox_key="worst_rated")
395
 
396
+