CoolFace
Apppublic

anz19/Movie-Recommended-System

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
app.py47 linesDownload Raw Back to root
1import streamlit as st2import pickle3import pandas as pd4import requests5 6def fetch_poster(movie_id):7    response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=48f2501f21cb491138d801b1d75f1d05&language=en-US'.format(movie_id))8    data = response.json()9 10    if 'poster_path' in data and data['poster_path'] is not None:11        return "https://image.tmdb.org/t/p/w500/"+data['poster_path']12    else:13        return "https://via.placeholder.com/500x750?text=No+Image"14 15def recommend(movie):16    movie_index = movies[movies['title'] == movie].index[0]17    distances = similarity[movie_index]18    movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]19 20    recommended_movies = []21    recommended_movies_posters = []22    for i in movies_list:23        movie_id = movies.iloc[i[0]].movie_id24        recommended_movies.append(movies.iloc[i[0]].title)25        # fetch poster from API26        recommended_movies_posters.append(fetch_poster(movie_id))27    return recommended_movies, recommended_movies_posters28 29movies_dict = pickle.load(open('movie_dict.pkl', 'rb'))30movies = pd.DataFrame(movies_dict)31 32similarity = pickle.load(open('similarity.pkl', 'rb'))33 34st.title('Movie Recommender System')35 36selected_movie_name = st.selectbox(37    'How would you like to be contacted?',38    movies['title'].values)39 40if st.button('Recommend'):41    names,posters = recommend(selected_movie_name)42    cols = st.columns(5)43 44    for i in range(5):45        with cols[i]:46            st.image(posters[i], use_container_width=True)47            st.caption(names[i])