kartavya17 commited on
Commit
815fbfb
1 Parent(s): b7aca05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -58
app.py CHANGED
@@ -1,58 +1,66 @@
1
- import pandas as pd
2
- import streamlit as st
3
- import pickle
4
- import requests
5
-
6
- def fetch_image(movie_id):
7
- response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US'.format(movie_id))
8
-
9
- data = response.json()
10
-
11
- return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
12
-
13
- def recommand(movie):
14
- movie_index = movies[movies['title'] == movie].index[0]
15
- distences = similarity[movie_index]
16
- movies_list = sorted(list(enumerate(distences)),reverse=True,key = lambda x : x[1])[1:6]
17
-
18
- recommanded_movie = []
19
- recommaned_poster=[]
20
- for i in movies_list:
21
- movie_id = movies.iloc[i[0]].movie_id
22
-
23
- recommanded_movie.append(movies.iloc[i[0]].title)
24
- recommaned_poster.append(fetch_image(movie_id)) # Fetch poster from API
25
- return recommanded_movie,recommaned_poster
26
-
27
- movies_dict = pickle.load(open('movie_dict.pkl','rb'))
28
- movies = pd.DataFrame(movies_dict)
29
-
30
- similarity = pickle.load(open('similarity.pkl','rb'))
31
-
32
- st.title('Movie Recommender System')
33
-
34
- selected_movie = st.selectbox(
35
- 'What is your taste in movie ? ',
36
- movies['title'].values)
37
- st.write('You selected:', selected_movie)
38
-
39
-
40
- if st.button('Recommend movie'):
41
- name,poster =recommand(selected_movie)
42
-
43
- col1, col2, col3, col4, col5 = st.columns(5)
44
- with col1:
45
- st.text(name[0])
46
- st.image(poster[0])
47
- with col2:
48
- st.text(name[1])
49
- st.image(poster[1])
50
- with col3:
51
- st.text(name[2])
52
- st.image(poster[2])
53
- with col4:
54
- st.text(name[3])
55
- st.image(poster[3])
56
- with col5:
57
- st.text(name[4])
58
- st.image(poster[4])
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import pickle
4
+ import requests
5
+
6
+ def fetch_image(movie_id):
7
+ response = requests.get('https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US'.format(movie_id))
8
+
9
+ data = response.json()
10
+
11
+ return "https://image.tmdb.org/t/p/w500/" + data['poster_path']
12
+
13
+ def recommand(movie):
14
+ movie_index = movies[movies['title'] == movie].index[0]
15
+ distences = similarity[movie_index]
16
+ movies_list = sorted(list(enumerate(distences)),reverse=True,key = lambda x : x[1])[1:6]
17
+
18
+ recommanded_movie = []
19
+ recommaned_poster=[]
20
+ for i in movies_list:
21
+ movie_id = movies.iloc[i[0]].movie_id
22
+
23
+ recommanded_movie.append(movies.iloc[i[0]].title)
24
+ recommaned_poster.append(fetch_image(movie_id)) # Fetch poster from API
25
+ return recommanded_movie,recommaned_poster
26
+
27
+ movies_dict = pickle.load(open('movie_dict.pkl','rb'))
28
+ movies = pd.DataFrame(movies_dict)
29
+
30
+ similarity = pickle.load(open('similarity.pkl','rb'))
31
+
32
+ st.title('Movie Recommender System')
33
+
34
+ selected_movie = st.selectbox(
35
+ 'What is your taste in movie ? ',
36
+ movies['title'].values)
37
+ st.write('You selected:', selected_movie)
38
+
39
+
40
+ if st.button('Recommend movie'):
41
+ name,poster =recommand(selected_movie)
42
+
43
+ col1, col2, col3, col4, col5 = st.columns(5)
44
+ with col1:
45
+ st.text(name[0])
46
+ st.image(poster[0])
47
+ with col2:
48
+ st.text(name[1])
49
+ st.image(poster[1])
50
+ with col3:
51
+ st.text(name[2])
52
+ st.image(poster[2])
53
+ with col4:
54
+ st.text(name[3])
55
+ st.image(poster[3])
56
+ with col5:
57
+ st.text(name[4])
58
+ st.image(poster[4])
59
+
60
+ st.header('', divider='rainbow')
61
+ st.markdown('''
62
+ Developed by KARTAVYA MASTER :8ball:
63
+ ''')
64
+
65
+ link='PORTFOLIO : [CLICK ME](https://mydawjbhdas.my.canva.site/aiwithkartavya)'
66
+ st.markdown(link,unsafe_allow_html=True)