Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +55 -0
- movie_list.pkl +3 -0
- requirements.txt +2 -0
- similarity.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import streamlit as st
|
3 |
+
import requests
|
4 |
+
st.set_page_config('LEWOPO_APP')
|
5 |
+
def fetch_poster(movie_id):
|
6 |
+
url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id)
|
7 |
+
data = requests.get(url)
|
8 |
+
data = data.json()
|
9 |
+
poster_path = data['poster_path']
|
10 |
+
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
|
11 |
+
return full_path
|
12 |
+
|
13 |
+
def recommend(movie):
|
14 |
+
index = movies[movies['title'] == movie].index[0]
|
15 |
+
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
|
16 |
+
recommended_movie_names = []
|
17 |
+
recommended_movie_posters = []
|
18 |
+
for i in distances[1:6]:
|
19 |
+
# fetch the movie poster
|
20 |
+
movie_id = movies.iloc[i[0]].movie_id
|
21 |
+
recommended_movie_posters.append(fetch_poster(movie_id))
|
22 |
+
recommended_movie_names.append(movies.iloc[i[0]].title)
|
23 |
+
|
24 |
+
return recommended_movie_names,recommended_movie_posters
|
25 |
+
|
26 |
+
|
27 |
+
st.header('APP POUR RECOMMENDATION DES FILMS')
|
28 |
+
movies = pickle.load(open('movie_list.pkl','rb'))
|
29 |
+
similarity = pickle.load(open('similarity.pkl','rb'))
|
30 |
+
|
31 |
+
movie_list = movies['title'].values
|
32 |
+
selected_movie = st.selectbox(
|
33 |
+
"Entrez ou sélectionnez un film dans la liste déroulante",
|
34 |
+
movie_list
|
35 |
+
)
|
36 |
+
|
37 |
+
if st.button('Validez'):
|
38 |
+
recommended_movie_names,recommended_movie_posters = recommend(selected_movie)
|
39 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
40 |
+
with col1:
|
41 |
+
st.text(recommended_movie_names[0])
|
42 |
+
st.image(recommended_movie_posters[0])
|
43 |
+
with col2:
|
44 |
+
st.text(recommended_movie_names[1])
|
45 |
+
st.image(recommended_movie_posters[1])
|
46 |
+
|
47 |
+
with col3:
|
48 |
+
st.text(recommended_movie_names[2])
|
49 |
+
st.image(recommended_movie_posters[2])
|
50 |
+
with col4:
|
51 |
+
st.text(recommended_movie_names[3])
|
52 |
+
st.image(recommended_movie_posters[3])
|
53 |
+
with col5:
|
54 |
+
st.text(recommended_movie_names[4])
|
55 |
+
st.image(recommended_movie_posters[4])
|
movie_list.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0465afd83e7b82c8753b750147a9de4ec0feb2289408784f74f2270acaf05d88
|
3 |
+
size 2396340
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Requests==2.31.0
|
2 |
+
streamlit==1.32.2
|
similarity.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:68067b69939937d822dc88f29ebd7d08240541a875b652b19c7e0bc050a433a8
|
3 |
+
size 184781251
|