Skip to content

Commit 82a1a01

Browse files
authored
Merge pull request #184 from Harshitmishra001/main
Fixing File Not Found Error indicating that the file similarity.pkl could not be found
2 parents 18f26c5 + 61414b1 commit 82a1a01

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed
Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import streamlit as st
22
import pandas as pd
33
import pickle
4-
from streamlit import session_state as session
54
import requests
6-
import numpy as np
5+
import os
76

87
def fetch_link(movie_name):
9-
movie_name='-'.join(movie_name.split())
10-
movie_link=f"https://www.justwatch.com/in/movie/{movie_name}"
8+
movie_name = '-'.join(movie_name.split())
9+
movie_link = f"https://www.justwatch.com/in/movie/{movie_name}"
1110
response = requests.get(movie_link)
1211
if response.status_code == 200:
1312
return movie_link
1413
else:
15-
tv_link=f"https://www.justwatch.com/in/tv-show/{movie_name}"
14+
tv_link = f"https://www.justwatch.com/in/tv-show/{movie_name}"
1615
response = requests.get(tv_link)
1716
if response.status_code == 200:
1817
return tv_link
1918

20-
return f"https://en.wikipedia.org/wiki/{'_'.join(movie_name.split())}"
19+
return f"https://en.wikipedia.org/wiki/{'_'.join(movie_name.split())}"
2120

2221
def fetch_trailer(movie_name):
2322
return f"https://www.youtube.com/results?search_query={movie_name}+trailer"
2423

25-
26-
def recommend(movies,input_movie):
24+
def recommend(movies, input_movie):
2725
movie_index = movies[movies['title'] == input_movie].index[0]
2826
distances = similarity[movie_index]
2927
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
@@ -36,49 +34,60 @@ def recommend(movies,input_movie):
3634
recommended_movies.append(movie_title)
3735
recommended_movies_link.append(fetch_link(movie_title))
3836
recommended_movies_trailer_link.append(fetch_trailer(movie_title))
39-
return recommended_movies, recommended_movies_link,recommended_movies_trailer_link
37+
return recommended_movies, recommended_movies_link, recommended_movies_trailer_link
38+
39+
# Define paths to your files
40+
similarity_path = r'Web_app/pages/similarity.pkl'
41+
movies_csv_path = r'Web_app/movies.csv'
4042

41-
similarity = pickle.load(open('similarity.pkl', 'rb'))
42-
movie_data=pd.read_csv("movies.csv") #you can either generate from scraper.py or can copy paste your own movies data
43+
# Check if the similarity file exists
44+
if os.path.exists(similarity_path):
45+
with open(similarity_path, 'rb') as file:
46+
similarity = pickle.load(file)
47+
else:
48+
st.error(f"File not found: {similarity_path}")
49+
similarity = None
4350

51+
# Check if the movies CSV file exists
52+
if os.path.exists(movies_csv_path):
53+
movie_data = pd.read_csv(movies_csv_path)
54+
else:
55+
st.error(f"File not found: {movies_csv_path}")
56+
movie_data = pd.DataFrame(columns=['title']) # Empty DataFrame to avoid errors
4457

4558
st.title("What to binge?")
4659
st.subheader('Movie recommendation :film_projector:', divider='rainbow')
4760
st.write("")
48-
recent_movie=st.selectbox("Which movie/tv show you just watched :sunglasses:!!!",movie_data['title']) # input movie name
49-
recommend_movies={"Name":[],"Link":[]}
50-
result = pd.DataFrame.from_dict(recommend_movies)
51-
52-
if st.button('Recommend'):
53-
names, links, trailers = recommend(movie_data,recent_movie)
54-
55-
data_df = pd.DataFrame(
56-
{
57-
"Name": names,
58-
"Link": links,
59-
"Trailer": trailers
60-
}
61-
)
62-
63-
st.data_editor(
64-
data_df,
65-
column_config={
66-
"Name": st.column_config.TextColumn(
67-
"Top Recommended Movies",
68-
help="The top recommended movies"
69-
),
70-
"Link": st.column_config.LinkColumn(
71-
"(watch/description) Links",
72-
help="Links of recommended movies"
73-
),
74-
"Trailer": st.column_config.LinkColumn(
75-
"Trailer Links",
76-
help="Youtuber trailer links of recommended movies"
77-
),
78-
}
79-
)
80-
81-
61+
recent_movie = st.selectbox("Which movie/tv show you just watched :sunglasses:!!!", movie_data['title'])
8262

63+
if st.button('Recommend'):
64+
if similarity is not None and not movie_data.empty:
65+
names, links, trailers = recommend(movie_data, recent_movie)
66+
67+
data_df = pd.DataFrame(
68+
{
69+
"Name": names,
70+
"Link": links,
71+
"Trailer": trailers
72+
}
73+
)
8374

84-
75+
st.data_editor(
76+
data_df,
77+
column_config={
78+
"Name": st.column_config.TextColumn(
79+
"Top Recommended Movies",
80+
help="The top recommended movies"
81+
),
82+
"Link": st.column_config.LinkColumn(
83+
"(watch/description) Links",
84+
help="Links of recommended movies"
85+
),
86+
"Trailer": st.column_config.LinkColumn(
87+
"Trailer Links",
88+
help="YouTube trailer links of recommended movies"
89+
),
90+
}
91+
)
92+
else:
93+
st.error("Recommendation system cannot run because required files are missing.")

Web_app/pages/similarity.pkl

376 KB
Binary file not shown.

0 commit comments

Comments
 (0)