Bardi-ya commited on
Commit
bd8be20
·
verified ·
1 Parent(s): 40104a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -13,7 +13,6 @@ with open(os.path.join(MODEL_DIR, "recommender_svd_mf.pkl"), "rb") as f:
13
 
14
  # Load movie metadata
15
  movies_df = pd.read_csv(MOVIE_DATA_PATH, low_memory=False)
16
- movies_df["movieId"] = movies_df["movieId"].astype(str)
17
 
18
  def recommend(user_id, top_k=5):
19
  """Generate top-k recommendations using SVD model."""
@@ -33,13 +32,9 @@ def recommend(user_id, top_k=5):
33
  # Build output
34
  results = []
35
  for mid, score in top_movies:
36
- movie_rows = movies_df[movies_df["movieId"] == str(mid)]
37
- if not movie_rows.empty:
38
- row = movie_rows.iloc[0]
39
- explanation = f"Because you liked movies with {row.get('actors', 'similar style')}."
40
- results.append((row.get("title", "Unknown"), row.get("poster_url", None), explanation))
41
- else:
42
- results.append(("Unknown", None, "No explanation available."))
43
 
44
  return results
45
 
 
13
 
14
  # Load movie metadata
15
  movies_df = pd.read_csv(MOVIE_DATA_PATH, low_memory=False)
 
16
 
17
  def recommend(user_id, top_k=5):
18
  """Generate top-k recommendations using SVD model."""
 
32
  # Build output
33
  results = []
34
  for mid, score in top_movies:
35
+ row = movies_df[movies_df["movieId"] == mid].iloc[0]
36
+ explanation = f"Because you liked movies with {row.get('actors', 'similar style')}."
37
+ results.append((row["title"], row.get("poster_url", None), explanation))
 
 
 
 
38
 
39
  return results
40