File size: 1,876 Bytes
815fbfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pandas as pd
import streamlit as st
import pickle
import requests

def fetch_image(movie_id):
    response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US'.format(movie_id))

    data = response.json()

    return "https://image.tmdb.org/t/p/w500/" + data['poster_path']

def recommand(movie):
    movie_index = movies[movies['title'] == movie].index[0]
    distences = similarity[movie_index]
    movies_list = sorted(list(enumerate(distences)),reverse=True,key = lambda x : x[1])[1:6]

    recommanded_movie = []
    recommaned_poster=[]
    for i in movies_list:
        movie_id = movies.iloc[i[0]].movie_id

        recommanded_movie.append(movies.iloc[i[0]].title)
        recommaned_poster.append(fetch_image(movie_id)) # Fetch poster from API
    return recommanded_movie,recommaned_poster

movies_dict = pickle.load(open('movie_dict.pkl','rb'))
movies = pd.DataFrame(movies_dict)

similarity = pickle.load(open('similarity.pkl','rb'))

st.title('Movie Recommender System')

selected_movie = st.selectbox(
    'What is your taste in movie ? ',
    movies['title'].values)
st.write('You selected:', selected_movie)


if st.button('Recommend movie'):
    name,poster =recommand(selected_movie)

    col1, col2, col3, col4, col5 = st.columns(5)
    with col1:
        st.text(name[0])
        st.image(poster[0])
    with col2:
        st.text(name[1])
        st.image(poster[1])
    with col3:
        st.text(name[2])
        st.image(poster[2])
    with col4:
        st.text(name[3])
        st.image(poster[3])
    with col5:
        st.text(name[4])
        st.image(poster[4])

st.header('', divider='rainbow')
st.markdown('''
    Developed by KARTAVYA MASTER :8ball:
''')

link='PORTFOLIO : [CLICK ME](https://mydawjbhdas.my.canva.site/aiwithkartavya)'
st.markdown(link,unsafe_allow_html=True)