Spaces:
Sleeping
Sleeping
Commit
·
98edc51
1
Parent(s):
91d8bb4
app.py
Browse files
app.py
CHANGED
@@ -375,16 +375,19 @@ def recommend(movie, similarity_df, movies_df, ratings_df, links_df, k=5):
|
|
375 |
try:
|
376 |
index = movies_df[movies_df['title'] == movie].index[0]
|
377 |
|
378 |
-
|
379 |
-
|
380 |
distances = sorted(list(enumerate(similarity_df.iloc[index])), reverse=True, key=lambda x: x[1])
|
381 |
|
382 |
recommended_movies = []
|
383 |
-
for i in distances[1:
|
384 |
movie_id = movies_df.iloc[i[0]]['movieId']
|
385 |
-
|
386 |
-
|
387 |
-
|
|
|
|
|
|
|
|
|
|
|
388 |
return recommended_movies
|
389 |
except Exception as e:
|
390 |
st.error(f"Error generating recommendations: {e}")
|
@@ -462,8 +465,8 @@ def main():
|
|
462 |
if button:
|
463 |
st.write("The rating bar here is token from our dataset and it's between 0 and 5.")
|
464 |
if selected_movie:
|
465 |
-
recommendations = get_recommendation_item(DB_df, similarity_df, selected_movie , k)
|
466 |
-
|
467 |
if recommendations:
|
468 |
st.write(f"Similar movies to '{selected_movie}':")
|
469 |
num_cols = 2
|
|
|
375 |
try:
|
376 |
index = movies_df[movies_df['title'] == movie].index[0]
|
377 |
|
|
|
|
|
378 |
distances = sorted(list(enumerate(similarity_df.iloc[index])), reverse=True, key=lambda x: x[1])
|
379 |
|
380 |
recommended_movies = []
|
381 |
+
for i in distances[1:]:
|
382 |
movie_id = movies_df.iloc[i[0]]['movieId']
|
383 |
+
num_ratings = ratings_df[ratings_df['movieId'] == movie_id].shape[0]
|
384 |
+
|
385 |
+
if num_ratings > 100:
|
386 |
+
movie_details = get_movie_details(movie_id, movies_df, ratings_df, links_df)
|
387 |
+
if movie_details:
|
388 |
+
recommended_movies.append(movie_details)
|
389 |
+
if len(recommended_movies) == k:
|
390 |
+
break
|
391 |
return recommended_movies
|
392 |
except Exception as e:
|
393 |
st.error(f"Error generating recommendations: {e}")
|
|
|
465 |
if button:
|
466 |
st.write("The rating bar here is token from our dataset and it's between 0 and 5.")
|
467 |
if selected_movie:
|
468 |
+
# recommendations = get_recommendation_item(DB_df, similarity_df, selected_movie , k)
|
469 |
+
recommendations = recommend(selected_movie, similarity_df, movies_df, ratings_df, links_df, k)
|
470 |
if recommendations:
|
471 |
st.write(f"Similar movies to '{selected_movie}':")
|
472 |
num_cols = 2
|