Skip to content

Commit 59ca3db

Browse files
authored
Merge pull request #232 from LifeHashed/temp
Fixed self call and made dataframe start from 1
2 parents 1209bef + 26530f5 commit 59ca3db

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Web_app/pages/2_Movie_Recommendation.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,35 @@ def fetch_trailer(movie_name):
2323

2424
def recommend(movies, input_movie):
2525
movie_index = movies[movies['title'] == input_movie].index[0]
26-
distances = similarity[movie_index]
27-
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
28-
26+
distances = similarity[movie_index] # type: ignore
27+
28+
# List to hold movie recommendations
29+
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])
30+
31+
# Filter out the input movie and get top 5 recommendations
2932
recommended_movies = []
3033
recommended_movies_link = []
3134
recommended_movies_trailer_link = []
3235
for x in movies_list:
3336
movie_title = movies.iloc[x[0]].title
34-
recommended_movies.append(movie_title)
35-
recommended_movies_link.append(fetch_link(movie_title))
36-
recommended_movies_trailer_link.append(fetch_trailer(movie_title))
37+
if movie_title != input_movie: # Skip the input movie
38+
recommended_movies.append(movie_title)
39+
recommended_movies_link.append(fetch_link(movie_title))
40+
recommended_movies_trailer_link.append(fetch_trailer(movie_title))
41+
if len(recommended_movies) == 5: # Limit to top 5 recommendations
42+
break
43+
3744
return recommended_movies, recommended_movies_link, recommended_movies_trailer_link
3845

46+
3947
# Define paths to your files
40-
similarity_path = r'Web_app/pages/similarity.pkl'
41-
movies_csv_path = r'Web_app/movies.csv'
48+
similarity_path = r'./pages/similarity.pkl'
49+
movies_csv_path = r'./movies.csv'
50+
4251

4352
# Check if the similarity file exists
4453
if os.path.exists(similarity_path):
54+
#print("File opened successfully")
4555
with open(similarity_path, 'rb') as file:
4656
similarity = pickle.load(file)
4757
else:
@@ -72,6 +82,8 @@ def recommend(movies, input_movie):
7282
}
7383
)
7484

85+
data_df.index = data_df.index + 1 #Increasing index
86+
7587
st.data_editor(
7688
data_df,
7789
column_config={

0 commit comments

Comments
 (0)