Spaces:
Sleeping
Sleeping
Commit
Browse files- Pages/About.py +28 -0
- Pages/Recommender App.py +151 -0
- animes.jpg +0 -0
- app.py +72 -0
- ninja.png +0 -0
- rec_data.csv +0 -0
- similarity.pkl +3 -0
Pages/About.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
|
4 |
+
# About page
|
5 |
+
def about_page():
|
6 |
+
style_for_page = """
|
7 |
+
<style>
|
8 |
+
div.css-nahz7x.e16nr0p34>p {
|
9 |
+
font-family: Poppins, sans-serif;
|
10 |
+
font-size: 1.07rem;
|
11 |
+
}
|
12 |
+
</style>
|
13 |
+
"""
|
14 |
+
st.markdown(style_for_page, unsafe_allow_html=True)
|
15 |
+
st.title("About")
|
16 |
+
st.divider()
|
17 |
+
st.subheader(
|
18 |
+
"This is a content based recommender system that recommends animes similar to the animes you like."
|
19 |
+
)
|
20 |
+
st.write("\n")
|
21 |
+
st.write("\n")
|
22 |
+
st.write(
|
23 |
+
"This Anime Recommender App is made by [Harshit Singh](https://Harsh502s.github.io/). :ninja:"
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
about_page()
|
Pages/Recommender App.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
|
6 |
+
# Importing the dataset
|
7 |
+
@st.cache_data
|
8 |
+
def load_data():
|
9 |
+
try:
|
10 |
+
anime_data = pd.read_csv(r"rec_data.csv")
|
11 |
+
except:
|
12 |
+
st.error("Dataset Not Found")
|
13 |
+
return anime_data
|
14 |
+
|
15 |
+
|
16 |
+
anime_data = load_data()
|
17 |
+
|
18 |
+
|
19 |
+
# Uncomment this if you want to load the model
|
20 |
+
@st.cache_resource
|
21 |
+
def load_model():
|
22 |
+
try:
|
23 |
+
similarity = pickle.load(open(r"similarity.pkl", "rb"))
|
24 |
+
except:
|
25 |
+
st.error("Model Not Found")
|
26 |
+
return similarity
|
27 |
+
|
28 |
+
|
29 |
+
similarity = load_model()
|
30 |
+
|
31 |
+
|
32 |
+
# Fetching the poster and url of the anime
|
33 |
+
def fetch_anime_url(anime_id):
|
34 |
+
url = anime_data[anime_data["anime_id"] == anime_id].urls.values[0]
|
35 |
+
return url
|
36 |
+
|
37 |
+
|
38 |
+
def fetch_poster(anime_id):
|
39 |
+
poster = anime_data[anime_data["anime_id"] == anime_id].poster.values[0]
|
40 |
+
return poster
|
41 |
+
|
42 |
+
|
43 |
+
# Recommender System
|
44 |
+
def recommend(anime):
|
45 |
+
index = anime_data[anime_data["title"] == anime].index[0]
|
46 |
+
distances = sorted(
|
47 |
+
list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1]
|
48 |
+
)
|
49 |
+
recommended_anime_names = []
|
50 |
+
recommended_anime_posters = []
|
51 |
+
recommended_anime_urls = []
|
52 |
+
|
53 |
+
for i in distances[1:9]:
|
54 |
+
# fetch the anime poster
|
55 |
+
anime_id = anime_data.iloc[i[0]].anime_id
|
56 |
+
recommended_anime_posters.append(fetch_poster(anime_id))
|
57 |
+
recommended_anime_names.append(anime_data.iloc[i[0]].title)
|
58 |
+
recommended_anime_urls.append(fetch_anime_url(anime_id))
|
59 |
+
|
60 |
+
return recommended_anime_names, recommended_anime_posters, recommended_anime_urls
|
61 |
+
|
62 |
+
|
63 |
+
# Recommender Page
|
64 |
+
def recommender_page():
|
65 |
+
style_for_page = """
|
66 |
+
<style>
|
67 |
+
div.css-1v0mbdj.etr89bj1>img {
|
68 |
+
width: 100%;
|
69 |
+
height: 100%;
|
70 |
+
overflow: hidden;
|
71 |
+
box-shadow: 0 0 0 1px rgba(0,0,0,.1);
|
72 |
+
border-radius: 1rem;
|
73 |
+
}
|
74 |
+
</style>
|
75 |
+
"""
|
76 |
+
st.markdown(style_for_page, unsafe_allow_html=True)
|
77 |
+
|
78 |
+
st.title("Anime Recommendation System")
|
79 |
+
|
80 |
+
anime_list = anime_data["title"].tolist()
|
81 |
+
anime_list.sort()
|
82 |
+
anime_list.insert(0, "Top 8 Animes")
|
83 |
+
anime_select = st.selectbox("Select an Anime", anime_list)
|
84 |
+
|
85 |
+
if st.button("Recommendation"):
|
86 |
+
if anime_select == "Top 8 Animes":
|
87 |
+
top8 = anime_data.sort_values("score", ascending=False).head(8)
|
88 |
+
col1, col2, col3, col4 = st.columns(4)
|
89 |
+
with col1:
|
90 |
+
st.write(f"[{top8.iloc[0].title}]({top8.iloc[0].anime_url})")
|
91 |
+
st.image(top8.iloc[0].poster)
|
92 |
+
with col2:
|
93 |
+
st.write(f"[{top8.iloc[1].title}]({top8.iloc[1].anime_url})")
|
94 |
+
st.image(top8.iloc[1].poster)
|
95 |
+
with col3:
|
96 |
+
st.write(f"[{top8.iloc[2].title}]({top8.iloc[2].anime_url})")
|
97 |
+
st.image(top8.iloc[2].poster)
|
98 |
+
with col4:
|
99 |
+
st.write(f"[{top8.iloc[3].title}]({top8.iloc[3].anime_url})")
|
100 |
+
st.image(top8.iloc[3].poster)
|
101 |
+
|
102 |
+
col5, col6, col7, col8 = st.columns(4)
|
103 |
+
with col5:
|
104 |
+
st.write(f"[{top8.iloc[4].title}]({top8.iloc[4].anime_url})")
|
105 |
+
st.image(top8.iloc[4].poster)
|
106 |
+
with col6:
|
107 |
+
st.write(f"[{top8.iloc[5].title}]({top8.iloc[5].anime_url})")
|
108 |
+
st.image(top8.iloc[5].poster)
|
109 |
+
with col7:
|
110 |
+
st.write(f"[{top8.iloc[6].title}]({top8.iloc[6].anime_url})")
|
111 |
+
st.image(top8.iloc[6].poster)
|
112 |
+
with col8:
|
113 |
+
st.write(f"[{top8.iloc[7].title}]({top8.iloc[7].anime_url})")
|
114 |
+
st.image(top8.iloc[7].poster)
|
115 |
+
else:
|
116 |
+
(
|
117 |
+
recommended_anime_names,
|
118 |
+
recommended_anime_posters,
|
119 |
+
recommended_anime_urls,
|
120 |
+
) = recommend(anime_select)
|
121 |
+
col1, col2, col3, col4 = st.columns(4)
|
122 |
+
with col1:
|
123 |
+
st.write(f"[{recommended_anime_names[0]}]({recommended_anime_urls[0]})")
|
124 |
+
st.image(recommended_anime_posters[0])
|
125 |
+
with col2:
|
126 |
+
st.write(f"[{recommended_anime_names[1]}]({recommended_anime_urls[1]})")
|
127 |
+
st.image(recommended_anime_posters[1])
|
128 |
+
with col3:
|
129 |
+
st.write(f"[{recommended_anime_names[2]}]({recommended_anime_urls[2]})")
|
130 |
+
st.image(recommended_anime_posters[2])
|
131 |
+
with col4:
|
132 |
+
st.write(f"[{recommended_anime_names[3]}]({recommended_anime_urls[3]})")
|
133 |
+
st.image(recommended_anime_posters[3])
|
134 |
+
|
135 |
+
col5, col6, col7, col8 = st.columns(4)
|
136 |
+
with col5:
|
137 |
+
st.write(f"[{recommended_anime_names[4]}]({recommended_anime_urls[4]})")
|
138 |
+
st.image(recommended_anime_posters[4])
|
139 |
+
with col6:
|
140 |
+
st.write(f"[{recommended_anime_names[5]}]({recommended_anime_urls[5]})")
|
141 |
+
st.image(recommended_anime_posters[5])
|
142 |
+
with col7:
|
143 |
+
st.write(f"[{recommended_anime_names[6]}]({recommended_anime_urls[6]})")
|
144 |
+
st.image(recommended_anime_posters[6])
|
145 |
+
with col8:
|
146 |
+
st.write(f"[{recommended_anime_names[7]}]({recommended_anime_urls[7]})")
|
147 |
+
st.image(recommended_anime_posters[7])
|
148 |
+
|
149 |
+
|
150 |
+
if __name__ == "__main__":
|
151 |
+
recommender_page()
|
animes.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from st_pages import Page, show_pages
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# Configuring Pages
|
6 |
+
|
7 |
+
show_pages(
|
8 |
+
[
|
9 |
+
Page(r"app.py", "Homepage", "π "),
|
10 |
+
Page(r"Pages/Recommender App.py", "Anime Recommender", "πΊ"),
|
11 |
+
Page(r"Pages/About.py", "About", "π"),
|
12 |
+
]
|
13 |
+
)
|
14 |
+
|
15 |
+
|
16 |
+
# Make the page full width
|
17 |
+
im = Image.open(r"ninja.png")
|
18 |
+
st.set_page_config(
|
19 |
+
page_title="Anime Recommender App",
|
20 |
+
page_icon=im,
|
21 |
+
layout="wide",
|
22 |
+
initial_sidebar_state="expanded",
|
23 |
+
menu_items={"About": "This Anime Recommender App is made by Harshit Singh."},
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
# Home Page
|
28 |
+
def home_page():
|
29 |
+
style_for_page = """
|
30 |
+
<style>
|
31 |
+
div.css-1v0mbdj.etr89bj1>img {
|
32 |
+
width: 100%;
|
33 |
+
height: 100%;
|
34 |
+
box-shadow: 0 0 0 1px rgba(0,0,0,.1);
|
35 |
+
border-radius: 5rem;
|
36 |
+
padding: 4rem;
|
37 |
+
justify-content: left;}
|
38 |
+
|
39 |
+
div.css-k7vsyb.e16nr0p31>h1 {
|
40 |
+
font-family: Poppins, sans-serif;
|
41 |
+
}
|
42 |
+
|
43 |
+
div.css-14xtw13.e8zbici0 {
|
44 |
+
margin-right: 2rem;
|
45 |
+
scale: 1.15;
|
46 |
+
}
|
47 |
+
|
48 |
+
div.css-nahz7x.e16nr0p34>p {
|
49 |
+
font-family: Poppins, sans-serif;
|
50 |
+
font-size: 1.05rem;
|
51 |
+
}
|
52 |
+
</style>
|
53 |
+
"""
|
54 |
+
st.markdown(style_for_page, unsafe_allow_html=True)
|
55 |
+
|
56 |
+
st.title("Welcome to Anime Recommender! :ninja:")
|
57 |
+
st.subheader("Discover Your Next Favorite Anime")
|
58 |
+
|
59 |
+
# Add unique content to the home page
|
60 |
+
st.write(
|
61 |
+
"Explore a world of anime and find personalized recommendations based on your anime preferences."
|
62 |
+
)
|
63 |
+
img = Image.open(r"animes.jpg")
|
64 |
+
st.image(img, use_column_width=True, caption="Anime Characters")
|
65 |
+
st.write(
|
66 |
+
"Get started by selecting your favorite anime and let the recommendation system do the rest!"
|
67 |
+
)
|
68 |
+
|
69 |
+
|
70 |
+
# Web Application
|
71 |
+
if __name__ == "__main__":
|
72 |
+
home_page()
|
ninja.png
ADDED
rec_data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
similarity.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe2a6562734859d7b4cd2faa02b48cc75b30f08466bcdeedcf43f0cb41ea0428
|
3 |
+
size 328397355
|