CoolFace
Modelpublic

coder003/Movie_recommendation_system

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
app.py64 linesDownload Raw Back to root
1import streamlit as st2import pickle3import pandas as pd4import requests5 6 7def fetch_poster(movie_id):8    url = "https://api.themoviedb.org/3/movie/{}?api_key=fe34a557846e9a676a98fd362f059b28&language=en-US".format(9        movie_id)10    response = requests.get(url)11    data = response.json()12    poster_path = data['poster_path']13    full_path = "https://image.tmdb.org/t/p/w500/" + poster_path14    return full_path15 16 17def recommend(movie):18    movie_index = movies[movies['title'] == movie].index[0]19    distances = similarity[movie_index]20    movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]21 22    recommended_movies = []23    recommended_movies_posters = []24    for i in movies_list:25        movie_id = movies.iloc[i[0]].movie_id26 27        recommended_movies.append(movies.iloc[i[0]].title)28        # using movie_id fetch poster from API29        recommended_movies_posters.append(fetch_poster(movie_id))30    return recommended_movies,recommended_movies_posters31 32 33st.title('Movie Recommender System')34st.text('๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป by Vividh Pandey')35movies_dict = pickle.load(open('movie_dict.pkl', 'rb'))36movies = pd.DataFrame(movies_dict)37 38similarity = pickle.load(open('similarity.pkl', 'rb'))39 40movie_list = movies['title'].values41selected_movie_name = st.selectbox(42    "Type or select a movie from the dropdown",43    movies['title'].values44)45 46if st.button('Show Recommendation'):47    names,posters = recommend(selected_movie_name)48    col1, col2, col3, col4, col5 = st.columns(5)49    with col1:50        st.text(names[0])51        st.image(posters[0])52    with col2:53        st.text(names[1])54        st.image(posters[1])55    with col3:56        st.text(names[2])57        st.image(posters[2])58    with col4:59        st.text(names[3])60        st.image(posters[3])61    with col5:62        st.text(names[4])63        st.image(posters[4])64