Ajay07pandey commited on
Commit
2b35bb8
1 Parent(s): d34ee43
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -8,19 +8,41 @@ st.image("Netflix.png")
8
  movies_list = pickle.load(open("content_dict.pkl",'br'))
9
  movies = pd.DataFrame(movies_list)
10
 
11
- def recommend(movie):
12
- index = movies[movies['title'] == movie].index[0]
13
- distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
14
- recommended_movie_names = []
15
- for i in distances[1:6]:
16
- recommended_movie_names.append(movies.iloc[i[0]].title)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- return recommended_movie_names
19
 
20
  # Displaying title
21
  st.title(" Movie Recommender System ")
22
 
23
- similarity = pickle.load(open('cosine_similarity.pkl','rb'))
24
 
25
  movie_list = movies['title'].values
26
  selected_movie = st.selectbox(
 
8
  movies_list = pickle.load(open("content_dict.pkl",'br'))
9
  movies = pd.DataFrame(movies_list)
10
 
11
+ similarity= pickle.load(open('cosine_similarity.pkl','rb'))
12
+
13
+ def recommend(title, cosine_sim=similarity, data=movies):
14
+ recommended_content=[]
15
+ # Get the index of the input title in the programme_list
16
+ programme_list = data['title'].to_list()
17
+ index = programme_list.index(title)
18
+
19
+
20
+ # Create a list of tuples containing the similarity score and index
21
+ # between the input title and all other programs in the dataset
22
+ sim_scores = list(enumerate(cosine_sim[index]))
23
+
24
+
25
+ # Sort the list of tuples by similarity score in descending order
26
+ sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)[1:11]
27
+
28
+
29
+ # Get the recommended movie titles and their similarity scores
30
+ recommend_index = [i[0] for i in sim_scores]
31
+ rec_movie = data['title'].iloc[recommend_index]
32
+ rec_score = [round(i[1], 4) for i in sim_scores]
33
+
34
+
35
+ # Create a pandas DataFrame to display the recommendations
36
+ rec_table = pd.DataFrame(list(zip(rec_movie, rec_score)), columns=['Recommendation', 'Similarity_score(0-1)'])
37
+ # recommended_content.append(rec_table['Recommendation'].values)
38
+
39
+
40
+ return rec_table['Recommendation'].values
41
 
 
42
 
43
  # Displaying title
44
  st.title(" Movie Recommender System ")
45
 
 
46
 
47
  movie_list = movies['title'].values
48
  selected_movie = st.selectbox(