Skip to content

Commit

Permalink
Merge pull request #184 from Harshitmishra001/main
Browse files Browse the repository at this point in the history
Fixing File Not Found Error indicating that the file similarity.pkl could not be found
  • Loading branch information
sanjay-kv authored Jun 10, 2024
2 parents 18f26c5 + 61414b1 commit 82a1a01
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
101 changes: 55 additions & 46 deletions Web_app/pages/2_Movie_Recommendation.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import streamlit as st
import pandas as pd
import pickle
from streamlit import session_state as session
import requests
import numpy as np
import os

def fetch_link(movie_name):
movie_name='-'.join(movie_name.split())
movie_link=f"https://www.justwatch.com/in/movie/{movie_name}"
movie_name = '-'.join(movie_name.split())
movie_link = f"https://www.justwatch.com/in/movie/{movie_name}"
response = requests.get(movie_link)
if response.status_code == 200:
return movie_link
else:
tv_link=f"https://www.justwatch.com/in/tv-show/{movie_name}"
tv_link = f"https://www.justwatch.com/in/tv-show/{movie_name}"
response = requests.get(tv_link)
if response.status_code == 200:
return tv_link

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

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


def recommend(movies,input_movie):
def recommend(movies, input_movie):
movie_index = movies[movies['title'] == input_movie].index[0]
distances = similarity[movie_index]
movies_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]
Expand All @@ -36,49 +34,60 @@ def recommend(movies,input_movie):
recommended_movies.append(movie_title)
recommended_movies_link.append(fetch_link(movie_title))
recommended_movies_trailer_link.append(fetch_trailer(movie_title))
return recommended_movies, recommended_movies_link,recommended_movies_trailer_link
return recommended_movies, recommended_movies_link, recommended_movies_trailer_link

# Define paths to your files
similarity_path = r'Web_app/pages/similarity.pkl'
movies_csv_path = r'Web_app/movies.csv'

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

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

st.title("What to binge?")
st.subheader('Movie recommendation :film_projector:', divider='rainbow')
st.write("")
recent_movie=st.selectbox("Which movie/tv show you just watched :sunglasses:!!!",movie_data['title']) # input movie name
recommend_movies={"Name":[],"Link":[]}
result = pd.DataFrame.from_dict(recommend_movies)

if st.button('Recommend'):
names, links, trailers = recommend(movie_data,recent_movie)

data_df = pd.DataFrame(
{
"Name": names,
"Link": links,
"Trailer": trailers
}
)

st.data_editor(
data_df,
column_config={
"Name": st.column_config.TextColumn(
"Top Recommended Movies",
help="The top recommended movies"
),
"Link": st.column_config.LinkColumn(
"(watch/description) Links",
help="Links of recommended movies"
),
"Trailer": st.column_config.LinkColumn(
"Trailer Links",
help="Youtuber trailer links of recommended movies"
),
}
)


recent_movie = st.selectbox("Which movie/tv show you just watched :sunglasses:!!!", movie_data['title'])

if st.button('Recommend'):
if similarity is not None and not movie_data.empty:
names, links, trailers = recommend(movie_data, recent_movie)

data_df = pd.DataFrame(
{
"Name": names,
"Link": links,
"Trailer": trailers
}
)


st.data_editor(
data_df,
column_config={
"Name": st.column_config.TextColumn(
"Top Recommended Movies",
help="The top recommended movies"
),
"Link": st.column_config.LinkColumn(
"(watch/description) Links",
help="Links of recommended movies"
),
"Trailer": st.column_config.LinkColumn(
"Trailer Links",
help="YouTube trailer links of recommended movies"
),
}
)
else:
st.error("Recommendation system cannot run because required files are missing.")
Binary file added Web_app/pages/similarity.pkl
Binary file not shown.

0 comments on commit 82a1a01

Please sign in to comment.