YAMITEK's picture
Update app.py
56a868d verified
import pandas as pd
import numpy as np
import joblib
import streamlit as st
cosine_sim=joblib.load('model_movie_recomadation_sigmoid.joblib')
indices_df=pd.read_csv('indices.csv')
html_temp = """
<div style="background-color:tomato;padding:10px">
<h2 style="color:white;text-align:center;">Movie Recomandation APP</h2>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
image_url="https://tse1.mm.bing.net/th?id=OIP.T1nYWZh17oT5wuISslNzdwHaEK&pid=Api&P=0&h=180"
st.image(image_url, use_container_width=True)
st.markdown(f"""
<style>
/* Set the background image for the entire app */
.stApp {{
background-color:#6793AC;
background-size: 100px;
background-repeat:no;
background-attachment: auto;
background-position:full;
}}
</style>
""", unsafe_allow_html=True)
def get_recommendations(title, cosine_sim=cosine_sim):
# Get the index of the movie that matches the title
filtered_df = indices_df[indices_df.apply(lambda row: row.astype(str).str.contains(movie, case=False).any(), axis=1)].index
sim_scores = list(enumerate(cosine_sim[filtered_df]))
index, values = sim_scores[0]
result = list(zip(range(len(values)), values))
# Sort the movies based on the similarity scores
result_sorted = sorted(result, key=lambda x: x[1], reverse=True)
# Get the scores of the 10 most similar movies
sim_scores = result_sorted[1:11]
# Get the movie indices
##global movie_indices
movie_indices = [i[0] for i in sim_scores]
#Return the top 10 most similar movies
return movie_indices
movie=st.text_input("Enter the Movie Tittle")
if st.button("Search"):
val=get_recommendations(movie)
st.dataframe(indices_df.iloc[val])