lenawilli commited on
Commit
009b5e5
Β·
verified Β·
1 Parent(s): 04a80dc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +69 -28
src/streamlit_app.py CHANGED
@@ -299,10 +299,33 @@ elif page:
299
  st.session_state["just_submitted"] = True
300
  st.rerun()
301
 
 
 
302
  elif search_query:
303
  st.title(f"Search Results for '{search_query}'")
304
- filtered = movie_df[movie_df["clean_title"].str.contains(search_query, case=False, na=False)]
305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  if filtered.empty:
307
  st.warning("No movies found.")
308
  else:
@@ -313,52 +336,70 @@ elif search_query:
313
  padding: 15px;
314
  border-radius: 10px;
315
  margin-bottom: 15px;
316
- transition: all 0.3s ease-in-out;
 
 
317
  }
318
  .movie-box:hover {
319
  background-color: #262626;
320
  }
321
- .movie-box.expanded {
322
- border-left: 6px solid #b32d2e;
323
- background-color: #2a2a2a;
 
 
 
 
 
 
 
324
  }
325
  .movie-title {
326
- font-size: 18px;
327
  font-weight: bold;
328
  color: #e63946;
 
329
  }
330
  .movie-details {
331
- margin-top: 10px;
 
 
 
 
 
 
 
 
 
332
  }
333
  </style>
334
  """, unsafe_allow_html=True)
335
 
336
  for _, movie in filtered.iterrows():
337
- with st.expander(f"🎬 {movie['clean_title']}", expanded=False):
338
- container = st.container()
339
- with container:
340
- st.markdown(f"""
341
- <div class="movie-box expanded">
 
 
 
 
 
 
 
 
 
342
  <div class="movie-details">
343
  <p><strong>Genres:</strong> {movie['genres']}</p>
344
  <p><strong>Year:</strong> {movie['year']}</p>
345
- <a href="/?movie_id={movie['movieId']}" style="color:#b32d2e;">πŸ” Details</a>
346
- </div>
347
- </div>
348
- """, unsafe_allow_html=True)
349
- # Show image even when collapsed
350
- poster_url, _ = get_tmdb_data(movie["clean_title"], movie["year"])
351
- with st.container():
352
- col1, col2 = st.columns([1, 4])
353
- with col1:
354
- if poster_url and "placeholder.com" not in poster_url:
355
- st.image(poster_url, width=100)
356
- else:
357
- st.markdown("""
358
- <div style='width:100px;border:2px dashed gray;height:150px;display:flex;align-items:center;justify-content:center;color:gray;'>
359
- No Image
360
  </div>
361
- """, unsafe_allow_html=True)
 
 
 
 
362
 
363
  else:
364
  st.title("Welcome to Movie Recommender")
 
299
  st.session_state["just_submitted"] = True
300
  st.rerun()
301
 
302
+ import difflib
303
+
304
  elif search_query:
305
  st.title(f"Search Results for '{search_query}'")
 
306
 
307
+ search_clean = search_query.strip().lower()
308
+
309
+ def title_match_score(title):
310
+ title_lower = title.lower()
311
+ if title_lower == search_clean:
312
+ return 3
313
+ elif title_lower.startswith(search_clean):
314
+ return 2
315
+ elif search_clean in title_lower:
316
+ return 1
317
+ else:
318
+ return 0
319
+
320
+ movie_df["match_score"] = movie_df["clean_title"].apply(title_match_score)
321
+ strong_matches = movie_df[movie_df["match_score"] > 0].sort_values("match_score", ascending=False)
322
+
323
+ if strong_matches.empty:
324
+ close_titles = difflib.get_close_matches(search_query, movie_df["clean_title"], n=10, cutoff=0.5)
325
+ filtered = movie_df[movie_df["clean_title"].isin(close_titles)]
326
+ else:
327
+ filtered = strong_matches
328
+
329
  if filtered.empty:
330
  st.warning("No movies found.")
331
  else:
 
336
  padding: 15px;
337
  border-radius: 10px;
338
  margin-bottom: 15px;
339
+ display: flex;
340
+ align-items: flex-start;
341
+ gap: 20px;
342
  }
343
  .movie-box:hover {
344
  background-color: #262626;
345
  }
346
+ .poster {
347
+ width: 100px;
348
+ height: 150px;
349
+ flex-shrink: 0;
350
+ border-radius: 4px;
351
+ object-fit: cover;
352
+ background: #333;
353
+ }
354
+ .movie-content {
355
+ flex-grow: 1;
356
  }
357
  .movie-title {
358
+ font-size: 20px;
359
  font-weight: bold;
360
  color: #e63946;
361
+ margin-bottom: 0.5rem;
362
  }
363
  .movie-details {
364
+ color: #ccc;
365
+ font-size: 15px;
366
+ margin-bottom: 0.5rem;
367
+ }
368
+ a.movie-link {
369
+ color: #b32d2e;
370
+ text-decoration: none;
371
+ }
372
+ a.movie-link:hover {
373
+ text-decoration: underline;
374
  }
375
  </style>
376
  """, unsafe_allow_html=True)
377
 
378
  for _, movie in filtered.iterrows():
379
+ poster_url, _ = get_tmdb_data(movie["clean_title"], movie["year"])
380
+ if not poster_url or "placeholder.com" in poster_url:
381
+ poster_html = """
382
+ <div style='width:100px;height:150px;border:2px dashed gray;display:flex;align-items:center;justify-content:center;color:gray;font-size:12px;'>No<br>Image</div>
383
+ """
384
+ else:
385
+ poster_html = f"<img src='{poster_url}' class='poster'>"
386
+
387
+ st.markdown(f"""
388
+ <div class="movie-box">
389
+ {poster_html}
390
+ <div class="movie-content">
391
+ <details>
392
+ <summary class="movie-title">🎬 {movie['clean_title']}</summary>
393
  <div class="movie-details">
394
  <p><strong>Genres:</strong> {movie['genres']}</p>
395
  <p><strong>Year:</strong> {movie['year']}</p>
396
+ <a class="movie-link" href='/?movie_id={movie["movieId"]}'>πŸ” Details</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  </div>
398
+ </details>
399
+ </div>
400
+ </div>
401
+ """, unsafe_allow_html=True)
402
+
403
 
404
  else:
405
  st.title("Welcome to Movie Recommender")