Spaces:
Sleeping
Sleeping
File size: 4,061 Bytes
dcaabff f0239ea dcaabff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
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 = "https://drive.google.com/file/d/1OmueIayrvczEQKRWIOfEkKH5zLWGxCn1/view?usp=drive_link"
similarity_path = "https://drive.google.com/file/d/1RI6XgtbaNxlBqZM0cznOZXN88tQWo98a/view?usp=drive_link"
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)
|