import requests def fetch_poster(movie_id): url = f"https://api.themoviedb.org/3/movie/{movie_id}?api_key=f99f126bfd58ba9b4aa8a3e6db301b6e&language=en-US" data = requests.get(url).json() poster_path = data['poster_path'] full_path = f"https://image.tmdb.org/t/p/w500/{poster_path}" return full_path def recommend(movie, movies, similarity): index = movies[movies['title'] == movie].index[0] distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1]) recommended_movies = [] recommended_posters = [] for i in distances[1:8]: # Get top 5 recommendations movie_id = movies.iloc[i[0]].id recommended_movies.append(movies.iloc[i[0]].title) recommended_posters.append(fetch_poster(movie_id)) return recommended_movies, recommended_posters