Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,66 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import numpy as np
|
| 3 |
-
import joblib
|
| 4 |
-
import streamlit as st
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
cosine_sim=joblib.load('model_movie_recomadation_sigmoid.joblib')
|
| 8 |
-
|
| 9 |
-
indices_df=pd.read_csv('indices.csv')
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
html_temp = """
|
| 13 |
-
<div style="background-color:tomato;padding:10px">
|
| 14 |
-
<h2 style="color:white;text-align:center;">Movie Recomandation APP</h2>
|
| 15 |
-
</div>
|
| 16 |
-
"""
|
| 17 |
-
st.markdown(html_temp, unsafe_allow_html=True)
|
| 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 |
st.dataframe(indices_df.iloc[val])
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import joblib
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
cosine_sim=joblib.load('model_movie_recomadation_sigmoid.joblib')
|
| 8 |
+
|
| 9 |
+
indices_df=pd.read_csv('indices.csv')
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
html_temp = """
|
| 13 |
+
<div style="background-color:tomato;padding:10px">
|
| 14 |
+
<h2 style="color:white;text-align:center;">Movie Recomandation APP</h2>
|
| 15 |
+
</div>
|
| 16 |
+
"""
|
| 17 |
+
st.markdown(html_temp, unsafe_allow_html=True)
|
| 18 |
+
image_url="https://tse1.mm.bing.net/th?id=OIP.T1nYWZh17oT5wuISslNzdwHaEK&pid=Api&P=0&h=180"
|
| 19 |
+
|
| 20 |
+
st.image(image_url, use_container_width=True)
|
| 21 |
+
st.markdown(f"""
|
| 22 |
+
<style>
|
| 23 |
+
/* Set the background image for the entire app */
|
| 24 |
+
.stApp {{
|
| 25 |
+
background-color:#6793AC;
|
| 26 |
+
background-size: 100px;
|
| 27 |
+
background-repeat:no;
|
| 28 |
+
background-attachment: auto;
|
| 29 |
+
background-position:full;
|
| 30 |
+
}}
|
| 31 |
+
</style>
|
| 32 |
+
""", unsafe_allow_html=True)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def get_recommendations(title, cosine_sim=cosine_sim):
|
| 38 |
+
# Get the index of the movie that matches the title
|
| 39 |
+
|
| 40 |
+
filtered_df = indices_df[indices_df.apply(lambda row: row.astype(str).str.contains(movie, case=False).any(), axis=1)].index
|
| 41 |
+
|
| 42 |
+
sim_scores = list(enumerate(cosine_sim[filtered_df]))
|
| 43 |
+
|
| 44 |
+
index, values = sim_scores[0]
|
| 45 |
+
result = list(zip(range(len(values)), values))
|
| 46 |
+
# Sort the movies based on the similarity scores
|
| 47 |
+
result_sorted = sorted(result, key=lambda x: x[1], reverse=True)
|
| 48 |
+
|
| 49 |
+
# Get the scores of the 10 most similar movies
|
| 50 |
+
sim_scores = result_sorted[1:11]
|
| 51 |
+
|
| 52 |
+
# Get the movie indices
|
| 53 |
+
##global movie_indices
|
| 54 |
+
movie_indices = [i[0] for i in sim_scores]
|
| 55 |
+
|
| 56 |
+
#Return the top 10 most similar movies
|
| 57 |
+
return movie_indices
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
movie=st.text_input("Enter the Movie Tittle")
|
| 61 |
+
|
| 62 |
+
if st.button("Search"):
|
| 63 |
+
|
| 64 |
+
val=get_recommendations(movie)
|
| 65 |
+
|
| 66 |
st.dataframe(indices_df.iloc[val])
|