├── requirement.txt ├── movies.pkl ├── movies.to_dict() ├── Screenshot 2024-08-17 210425.png ├── README.md └── app.py /requirement.txt: -------------------------------------------------------------------------------- 1 | streamlit~=1.37.1 2 | numpy>=1.26.0 3 | requests 4 | pandas 5 | -------------------------------------------------------------------------------- /movies.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishantsingha13/movie-recommendation/HEAD/movies.pkl -------------------------------------------------------------------------------- /movies.to_dict(): -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishantsingha13/movie-recommendation/HEAD/movies.to_dict() -------------------------------------------------------------------------------- /Screenshot 2024-08-17 210425.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishantsingha13/movie-recommendation/HEAD/Screenshot 2024-08-17 210425.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # movie-recommendation System 2 | ### Deployed Project Link: https://q6o6eqmcaitsaxgakcuvxz.streamlit.app/ 3 | 4 | ## Overview: 5 | This system recommends movies similar to the ones a user likes based on content 6 | features like genre, runtime, and rating. 7 | 8 | ## How It Works: 9 | - **Movie Details:** 10 | - The details of the movies (title, genre, runtime, rating, poster, etc.) are fetched using the TMDB API via the IMDB ID. 11 | - API documentation link: TMDB API Documentation. 12 | - **Manual Movie Selection:** 13 | - If the movie you’re searching for is not auto-suggested, you can manually type the name and press "Enter" to find it. 14 | - **Cosine Similarity:** 15 | ![image](https://github.com/nishantsingha13/movie-recommendation/assets/103675762/091aa3a6-26af-4c4d-8d57-1f8c1f767cbb) 16 | 17 | - Cosine Distance is a metric used to measure how similar movies are, irrespective of their size or other properties. 18 | - It measures the cosine of the angle between two vectors projected in a multi-dimensional space. 19 | - The smaller the angle between the vectors, the higher the cosine similarity, indicating a stronger relationship between the movies. 20 | - Advantage: 21 | - Even if two movies are distant by Euclidean distance (due to different sizes or ratings), they can still be closely related by cosine similarity. 22 | 23 | ![image](https://github.com/user-attachments/assets/d8e4c12f-06da-448c-9663-3dbcefa14a8e) 24 | 25 | ## User Interface: 26 | - For a better user experience, the project uses **Streamlit**, which provides an intuitive and simple interface. 27 | 28 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import streamlit as st 3 | import pandas as pd 4 | import requests 5 | 6 | def fetch_poster(movie_id): 7 | url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id) 8 | data = requests.get(url) 9 | data = data.json() 10 | poster_path = data['poster_path'] 11 | full_path = "https://image.tmdb.org/t/p/w500/" + poster_path 12 | return full_path 13 | 14 | def recommend(movie): 15 | index = movies[movies['title'] == movie].index[0] 16 | distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1]) 17 | recommended_movie_names = [] 18 | recommended_movie_posters = [] 19 | for i in distances[1:6]: 20 | # fetch the movie poster 21 | movie_id = movies.iloc[i[0]].movie_id 22 | recommended_movie_posters.append(fetch_poster(movie_id)) 23 | recommended_movie_names.append(movies.iloc[i[0]].title) 24 | 25 | return recommended_movie_names,recommended_movie_posters 26 | 27 | import pickle 28 | import pandas as pd 29 | import streamlit as st 30 | import requests 31 | 32 | def fetch_poster(movie_id): 33 | response=requests.get("https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id)) 34 | data=response.json() 35 | full_path = "https://image.tmdb.org/t/p/w500/" + data["poster_path"] 36 | return full_path 37 | 38 | def recommend(movie): 39 | movie_index=movies[movies['title']==movie].index[0] 40 | distances=similarity[movie_index] 41 | movies_list=sorted(list(enumerate(distances)),reverse=True,key=lambda x:x[1])[1:6] 42 | recommended_movies=[] 43 | recommended_poster=[] 44 | for i in movies_list: 45 | movie_id=movies.iloc[i[0]].movie_id#index 46 | 47 | recommended_movies.append(movies.iloc[i[0]].title) 48 | recommended_poster.append(fetch_poster(movie_id))#fetch poster from API 49 | return recommended_movies,recommended_poster 50 | 51 | 52 | 53 | movies_dicts=pickle.load(open("movies.to_dict()","rb")) 54 | 55 | 56 | movies=pd.DataFrame(movies_dicts) 57 | 58 | similarity=pickle.load(open("similarity.pkl","rb")) 59 | st.title("MOVIE RECOMMENDER SYSTEM") 60 | selected_movie_name=st.selectbox("Recommended movies",(movies["title"].values)) 61 | 62 | if st.button('SHOW RECOMMENDATION'): 63 | names,posters=recommend(selected_movie_name) 64 | col1, col2, col3, col4, col5 = st.columns(5)#this code is for generate poster 65 | with col1: 66 | st.text(names[0]) 67 | st.image(posters[0]) 68 | with col2: 69 | st.text(names[1]) 70 | st.image(posters[1]) 71 | 72 | with col3: 73 | st.text(names[2]) 74 | st.image(posters[2]) 75 | with col4: 76 | st.text(names[3]) 77 | st.image(posters[3]) 78 | with col5: 79 | st.text(names[4]) 80 | st.image(posters[4]) --------------------------------------------------------------------------------