HEMANTH
commited on
Commit
·
9715f6d
1
Parent(s):
a92823f
added all files from existing github repo
Browse files- app.py +74 -0
- movie_names.pkl +3 -0
- requirements.txt +6 -0
- similarity.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import streamlit as st
|
3 |
+
import requests
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
def fetch_poster(movie_id):
|
7 |
+
# url = "https://api.themoviedb.org/3/movie/{}?api_key=8fe6f2aa0e5d863d7fd4dc7994cfbce9&language=en-US".format(movie_id)
|
8 |
+
# data = requests.get(url)
|
9 |
+
#st.write(movie_id)
|
10 |
+
url = "https://api.themoviedb.org/3/movie/{}?language=en-US".format(movie_id)
|
11 |
+
headers = {
|
12 |
+
"accept": "application/json",
|
13 |
+
"Authorization": "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4ZmU2ZjJhYTBlNWQ4NjNkN2ZkNGRjNzk5NGNmYmNlOSIsIm5iZiI6MTcyMDk0MzA0MC41MTQyMDgsInN1YiI6IjY2OGY3NzQ2OGUzOWM5YzlmMjEwZWQxOSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.zYIfFcNM8Y_Z33JOczRQO8PBoU-RlkoFQeFyAiqkLpw"
|
14 |
+
}
|
15 |
+
|
16 |
+
data = response = requests.get(url, headers=headers)
|
17 |
+
#st.write(data)
|
18 |
+
data = data.json()
|
19 |
+
#st.write(data)
|
20 |
+
poster_path = data['poster_path']
|
21 |
+
# print(response.text)
|
22 |
+
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
23 |
+
return full_path
|
24 |
+
|
25 |
+
def recommend(movie):
|
26 |
+
index = movies[movies['title'] == movie].index[0]
|
27 |
+
# index = 385
|
28 |
+
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
29 |
+
recommended_movie_names = []
|
30 |
+
recommended_movie_posters = []
|
31 |
+
for i in distances[1:6]:
|
32 |
+
# fetch the movie poster
|
33 |
+
movie_id = movies.iloc[i[0]].id
|
34 |
+
recommended_movie_posters.append(fetch_poster(movie_id))
|
35 |
+
recommended_movie_names.append(movies.iloc[i[0]].title)
|
36 |
+
|
37 |
+
return recommended_movie_names,recommended_movie_posters
|
38 |
+
|
39 |
+
|
40 |
+
st.header('Movie Recommender System')
|
41 |
+
movies = pickle.load(open('movie_names.pkl','rb'))
|
42 |
+
movies = pd.DataFrame(movies)
|
43 |
+
similarity = pickle.load(open('similarity.pkl','rb'))
|
44 |
+
|
45 |
+
movie_list = movies['title'].values
|
46 |
+
selected_movie = st.selectbox(
|
47 |
+
"Type or select a movie from the dropdown",
|
48 |
+
movie_list
|
49 |
+
)
|
50 |
+
print(selected_movie)
|
51 |
+
if st.button('Show Recommendation'):
|
52 |
+
recommended_movie_names,recommended_movie_posters = recommend(selected_movie)
|
53 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
54 |
+
with col1:
|
55 |
+
st.text(recommended_movie_names[0])
|
56 |
+
st.image(recommended_movie_posters[0])
|
57 |
+
with col2:
|
58 |
+
st.text(recommended_movie_names[1])
|
59 |
+
st.image(recommended_movie_posters[1])
|
60 |
+
|
61 |
+
with col3:
|
62 |
+
st.text(recommended_movie_names[2])
|
63 |
+
st.image(recommended_movie_posters[2])
|
64 |
+
with col4:
|
65 |
+
st.text(recommended_movie_names[3])
|
66 |
+
st.image(recommended_movie_posters[3])
|
67 |
+
with col5:
|
68 |
+
st.text(recommended_movie_names[4])
|
69 |
+
st.image(recommended_movie_posters[4])
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
movie_names.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fa45385b2529ad9a788b2749bf1404c63bfa982e84a4b474dda229160265e282
|
3 |
+
size 5033528
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
numpy
|
3 |
+
pickleshare
|
4 |
+
requests
|
5 |
+
pandas
|
6 |
+
protobuf==3.19.1
|
similarity.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2d207507ed609ded5ddc22b24ef51a51efbe728517b3ad2d78e4b75b976e9905
|
3 |
+
size 184781251
|