shreyasiv's picture
Upload 5 files
dcaabff
raw
history blame
4.06 kB
import pickle
import streamlit as st
import requests
# Set page title and sidebar properties
st.set_page_config(page_title="Insightly")
st.markdown(
"""
<style>
.image-container {
margin-bottom: 60px;
}
.sidebar-link {
display: flex;
justify-content: left;
font-size: 28px;
margin-top: 10px; /* Adjust margin-top value to control space on the top */
margin-left: 20px; /* Adjust margin-left value to add space from the left */
}
.vertical-space {
height: 20px;
}
.movie-title {
font-size: 18px;
font-weight: bold;
}
.row-padding {
padding-bottom: 40px;
}
</style>
""",
unsafe_allow_html=True,
)
# Sidebar contents
with st.sidebar:
st.image("https://i.ibb.co/bX6GdqG/insightly-wbg.png", use_column_width=True)
st.markdown("<p class='sidebar-link'>πŸ“ˆ <a href='https://insightly-csv-bot.hf.space/'> CSV Bot</a></p>", unsafe_allow_html=True)
st.markdown("<p class='sidebar-link'>πŸ“š <a href='https://chandrakalagowda-demo2.hf.space/'> PDF Bot </a></p>", unsafe_allow_html=True)
st.markdown("<p class='sidebar-link'>πŸ“Έ <a href='https://insightly-frame-capturer.hf.space/'> Frame Capturer</a></p>", unsafe_allow_html=True)
st.markdown("<p class='sidebar-link'>πŸ–ΌοΈ <a href='https://insightly-image-reader.hf.space/'> Image Reader</a></p>", unsafe_allow_html=True)
st.markdown("<div class='vertical-space'></div>", unsafe_allow_html=True)
def fetch_poster(movie_id):
url = "https://api.themoviedb.org/3/movie/{}?api_key=8265bd1679663a7ea12ac168da84d2e8&language=en-US".format(movie_id)
data = requests.get(url)
data = data.json()
poster_path = data['poster_path']
full_path = "https://image.tmdb.org/t/p/w500/" + poster_path
return full_path
def recommend(movie):
index = movies[movies['title'] == movie].index[0]
distances = sorted(list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1])
recommended_movie_names = []
recommended_movie_posters = []
for i in distances[1:6]:
# fetch the movie poster
movie_id = movies.iloc[i[0]].movie_id
recommended_movie_posters.append(fetch_poster(movie_id))
recommended_movie_names.append(movies.iloc[i[0]].title)
return recommended_movie_names,recommended_movie_posters
st.title('Movie Recommender 🎬')
# Provide the correct absolute paths to the pickled data
movie_list_path = "/home/oem/Desktop/TRUEINFO LABS/movie-recommender-system-tmdb-dataset/movie_list.pkl"
similarity_path = "/home/oem/Desktop/TRUEINFO LABS/movie-recommender-system-tmdb-dataset/similarity.pkl"
movies = pickle.load(open(movie_list_path, 'rb'))
similarity = pickle.load(open(similarity_path, 'rb'))
movies = pickle.load(open(movie_list_path, 'rb'))
similarity = pickle.load(open(similarity_path, 'rb'))
movie_list = movies['title'].values
selected_movie = st.selectbox(
"Type or select a movie from the dropdown",
movie_list
)
if st.button('Show Recommendation'):
recommended_movie_names, recommended_movie_posters = recommend(selected_movie)
# Create columns based on the number of recommended movies
num_recommendations = len(recommended_movie_names)
num_columns = 3
num_rows = (num_recommendations + num_columns - 1) // num_columns # Calculate the number of rows required
# Create a list of columns
cols = [st.columns(num_columns) for _ in range(num_rows)]
# Loop through recommended movies and posters and display them in the columns
for i, movie_name in enumerate(recommended_movie_names):
col_index = i // num_columns
row_index = i % num_columns
cols[col_index][row_index].markdown(f"<span class='movie-title'>{movie_name}</span>", unsafe_allow_html=True)
cols[col_index][row_index].image(recommended_movie_posters[i])
# Add padding between the rows
st.markdown("<br>", unsafe_allow_html=True)
st.write('<div class="row-padding"></div>', unsafe_allow_html=True)