Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bilalakram #34803

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions content/bilalakram
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import streamlit as st
import pickle
import pandas as pd
import requests

def fetch_movie_id(movie_title):
response = requests.get("https://api.themoviedb.org/3/search/movie?api_key=2eec5cadfef931cf08e9b0805fe12e88&query={}".format(movie_title))
data = response.json()
if data['results']:
return data['results'][0]['id']
else:
return None

def fetch_poster(movie_id):
response = requests.get("https://api.themoviedb.org/3/movie/{}?api_key=2eec5cadfef931cf08e9b0805fe12e88".format(movie_id))
data = response.json()
print(data) # Add this line to print the API response
if 'poster_path' in data and data['poster_path'] is not None:
return "https://image.tmdb.org/t/p/w185/" + data['poster_path']
else:
print("Poster not available for movie ID:", movie_id)
return "https://via.placeholder.com/185x278" # Use a default image URL

def recommend(movie):
if not movie:
return []
if movie not in movies_lists:
return []
movie_index = movies_lists.tolist().index(movie)
distance = similarity[movie_index]
movie_list = sorted(list(enumerate(similarity[movie_index])), reverse=True, key=lambda x:x[1])[1:6]
recommended_movies = [movies_lists[i[0]] for i in movie_list]
recommended_movies_poster = []
for movie in recommended_movies:
movie_id = fetch_movie_id(movie)
if movie_id:
poster = fetch_poster(movie_id)
print(movie_id) # Add this line to print the movie ID
recommended_movies_poster.append(poster)
else:
recommended_movies_poster.append("https://via.placeholder.com/185x278") # Use a default image URL
return recommended_movies, recommended_movies_poster

movies_lists = pickle.load(open('movies.pkl','rb'))
movies_lists = movies_lists["title"].values
similarity = pickle.load(open('similarity.pkl','rb'))

st.title('Movie Recommender System')
Selected_Movie_Name = st.selectbox('How would you like to be connected ?', movies_lists)

if st.button('Recommend'):
names, poster = recommend(Selected_Movie_Name)
row = st.container()
with row:
cols = st.columns(5)
for i in range(5):
with cols[i]:
st.write(f"<h5 style='text-align: center; width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>{names[i]}</h5>", unsafe_allow_html=True)
st.image(poster[i])
Loading