Harsh502s commited on
Commit
1378b49
·
1 Parent(s): 9f6bda5
Files changed (2) hide show
  1. Pages/Recommender App.py +32 -168
  2. Recommender App Dev Copy.py +491 -0
Pages/Recommender App.py CHANGED
@@ -113,32 +113,16 @@ def top_animes():
113
  with st.container():
114
  col0, col1, col2, col3 = st.columns(4)
115
  with col0:
116
- st.link_button(
117
- f"{top8.iloc[0].title}",
118
- f"{top8.iloc[0].anime_url}",
119
- use_container_width=True,
120
- )
121
  st.image(top8.iloc[0].poster, use_column_width=True)
122
  with col1:
123
- st.link_button(
124
- f"{top8.iloc[1].title}",
125
- f"{top8.iloc[1].anime_url}",
126
- use_container_width=True,
127
- )
128
  st.image(top8.iloc[1].poster, use_column_width=True)
129
  with col2:
130
- st.link_button(
131
- f"{top8.iloc[2].title}",
132
- f"{top8.iloc[2].anime_url}",
133
- use_container_width=True,
134
- )
135
  st.image(top8.iloc[2].poster, use_column_width=True)
136
  with col3:
137
- st.link_button(
138
- f"{top8.iloc[3].title}",
139
- f"{top8.iloc[3].anime_url}",
140
- use_container_width=True,
141
- )
142
  st.image(top8.iloc[3].poster, use_column_width=True)
143
 
144
  st.divider()
@@ -146,32 +130,16 @@ def top_animes():
146
  with st.container():
147
  col4, col5, col6, col7 = st.columns(4)
148
  with col4:
149
- st.link_button(
150
- f"{top8.iloc[4].title}",
151
- f"{top8.iloc[4].anime_url}",
152
- use_container_width=True,
153
- )
154
  st.image(top8.iloc[4].poster, use_column_width=True)
155
  with col5:
156
- st.link_button(
157
- f"{top8.iloc[5].title}",
158
- f"{top8.iloc[5].anime_url}",
159
- use_container_width=True,
160
- )
161
  st.image(top8.iloc[5].poster, use_column_width=True)
162
  with col6:
163
- st.link_button(
164
- f"{top8.iloc[6].title}",
165
- f"{top8.iloc[6].anime_url}",
166
- use_container_width=True,
167
- )
168
  st.image(top8.iloc[6].poster, use_column_width=True)
169
  with col7:
170
- st.link_button(
171
- f"{top8.iloc[7].title}",
172
- f"{top8.iloc[7].anime_url}",
173
- use_container_width=True,
174
- )
175
  st.image(top8.iloc[7].poster, use_column_width=True)
176
 
177
 
@@ -202,65 +170,25 @@ def top_animes_genres(genre_select):
202
  ].sort_values("score", ascending=False)[:8]
203
  col0, col1, col2, col3 = st.columns(4)
204
  with col0:
205
- st.link_button(
206
- f"{top_8_genre.iloc[0].title}",
207
- f"{top_8_genre.iloc[0].anime_url}",
208
- use_container_width=True,
209
- )
210
- st.image(top_8_genre.iloc[0].poster, use_column_width=True)
211
  with col1:
212
- st.link_button(
213
- f"{top_8_genre.iloc[1].title}",
214
- f"{top_8_genre.iloc[1].anime_url}",
215
- use_container_width=True,
216
- )
217
- st.image(top_8_genre.iloc[1].poster, use_column_width=True)
218
  with col2:
219
- st.link_button(
220
- f"{top_8_genre.iloc[2].title}",
221
- f"{top_8_genre.iloc[2].anime_url}",
222
- use_container_width=True,
223
- )
224
- st.image(top_8_genre.iloc[2].poster, use_column_width=True)
225
  with col3:
226
- st.link_button(
227
- f"{top_8_genre.iloc[3].title}",
228
- f"{top_8_genre.iloc[3].anime_url}",
229
- use_container_width=True,
230
- )
231
- st.image(top_8_genre.iloc[3].poster, use_column_width=True)
232
 
233
  st.divider()
234
 
235
  col4, col5, col6, col7 = st.columns(4)
236
  with col4:
237
- st.link_button(
238
- f"{top_8_genre.iloc[4].title}",
239
- f"{top_8_genre.iloc[4].anime_url}",
240
- use_container_width=True,
241
- )
242
- st.image(top_8_genre.iloc[4].poster, use_column_width=True)
243
  with col5:
244
- st.link_button(
245
- f"{top_8_genre.iloc[5].title}",
246
- f"{top_8_genre.iloc[5].anime_url}",
247
- use_container_width=True,
248
- )
249
- st.image(top_8_genre.iloc[5].poster, use_column_width=True)
250
  with col6:
251
- st.link_button(
252
- f"{top_8_genre.iloc[6].title}",
253
- f"{top_8_genre.iloc[6].anime_url}",
254
- use_container_width=True,
255
- )
256
- st.image(top_8_genre.iloc[6].poster, use_column_width=True)
257
  with col7:
258
- st.link_button(
259
- f"{top_8_genre.iloc[7].title}",
260
- f"{top_8_genre.iloc[7].anime_url}",
261
- use_container_width=True,
262
- )
263
- st.image(top_8_genre.iloc[7].poster, use_column_width=True)
264
 
265
 
266
  # Function to display the top 8 animes with user given anime name for all genres
@@ -293,32 +221,16 @@ def top_animes_custom(anime_select):
293
  with st.container():
294
  col0, col1, col2, col3 = st.columns(4)
295
  with col0:
296
- st.link_button(
297
- f"{recommended_anime_names[0]}",
298
- f"{recommended_anime_urls[0]}",
299
- use_container_width=True,
300
- )
301
  st.image(recommended_anime_posters[0], use_column_width=True)
302
  with col1:
303
- st.link_button(
304
- f"{recommended_anime_names[1]}",
305
- f"{recommended_anime_urls[1]}",
306
- use_container_width=True,
307
- )
308
  st.image(recommended_anime_posters[1], use_column_width=True)
309
  with col2:
310
- st.link_button(
311
- f"{recommended_anime_names[2]}",
312
- f"{recommended_anime_urls[2]}",
313
- use_container_width=True,
314
- )
315
  st.image(recommended_anime_posters[2], use_column_width=True)
316
  with col3:
317
- st.link_button(
318
- f"{recommended_anime_names[3]}",
319
- f"{recommended_anime_urls[3]}",
320
- use_container_width=True,
321
- )
322
  st.image(recommended_anime_posters[3], use_column_width=True)
323
 
324
  st.divider()
@@ -326,32 +238,16 @@ def top_animes_custom(anime_select):
326
  with st.container():
327
  col4, col5, col6, col7 = st.columns(4)
328
  with col4:
329
- st.link_button(
330
- f"{recommended_anime_names[4]}",
331
- f"{recommended_anime_urls[4]}",
332
- use_container_width=True,
333
- )
334
  st.image(recommended_anime_posters[4], use_column_width=True)
335
  with col5:
336
- st.link_button(
337
- f"{recommended_anime_names[5]}",
338
- f"{recommended_anime_urls[5]}",
339
- use_container_width=True,
340
- )
341
  st.image(recommended_anime_posters[5], use_column_width=True)
342
  with col6:
343
- st.link_button(
344
- f"{recommended_anime_names[6]}",
345
- f"{recommended_anime_urls[6]}",
346
- use_container_width=True,
347
- )
348
  st.image(recommended_anime_posters[6], use_column_width=True)
349
  with col7:
350
- st.link_button(
351
- f"{recommended_anime_names[7]}",
352
- f"{recommended_anime_urls[7]}",
353
- use_container_width=True,
354
- )
355
  st.image(recommended_anime_posters[7], use_column_width=True)
356
 
357
 
@@ -385,32 +281,16 @@ def top_animes_custom_genres(anime_select, genre_select):
385
  with st.container():
386
  col0, col1, col2, col3 = st.columns(4)
387
  with col0:
388
- st.link_button(
389
- f"{recommended_anime_names[0]}",
390
- f"{recommended_anime_urls[0]}",
391
- use_container_width=True,
392
- )
393
  st.image(recommended_anime_posters[0], use_column_width=True)
394
  with col1:
395
- st.link_button(
396
- f"{recommended_anime_names[1]}",
397
- f"{recommended_anime_urls[1]}",
398
- use_container_width=True,
399
- )
400
  st.image(recommended_anime_posters[1], use_column_width=True)
401
  with col2:
402
- st.link_button(
403
- f"{recommended_anime_names[2]}",
404
- f"{recommended_anime_urls[2]}",
405
- use_container_width=True,
406
- )
407
  st.image(recommended_anime_posters[2], use_column_width=True)
408
  with col3:
409
- st.link_button(
410
- f"{recommended_anime_names[3]}",
411
- f"{recommended_anime_urls[3]}",
412
- use_container_width=True,
413
- )
414
  st.image(recommended_anime_posters[3], use_column_width=True)
415
 
416
  st.divider()
@@ -418,32 +298,16 @@ def top_animes_custom_genres(anime_select, genre_select):
418
  with st.container():
419
  col4, col5, col6, col7 = st.columns(4)
420
  with col4:
421
- st.link_button(
422
- f"{recommended_anime_names[4]}",
423
- f"{recommended_anime_urls[4]}",
424
- use_container_width=True,
425
- )
426
  st.image(recommended_anime_posters[4], use_column_width=True)
427
  with col5:
428
- st.link_button(
429
- f"{recommended_anime_names[5]}",
430
- f"{recommended_anime_urls[5]}",
431
- use_container_width=True,
432
- )
433
  st.image(recommended_anime_posters[5], use_column_width=True)
434
  with col6:
435
- st.link_button(
436
- f"{recommended_anime_names[6]}",
437
- f"{recommended_anime_urls[6]}",
438
- use_container_width=True,
439
- )
440
  st.image(recommended_anime_posters[6], use_column_width=True)
441
  with col7:
442
- st.link_button(
443
- f"{recommended_anime_names[7]}",
444
- f"{recommended_anime_urls[7]}",
445
- use_container_width=True,
446
- )
447
  st.image(recommended_anime_posters[7], use_column_width=True)
448
 
449
 
 
113
  with st.container():
114
  col0, col1, col2, col3 = st.columns(4)
115
  with col0:
116
+ st.write("[top8.iloc[0].title](top8.iloc[0].url)")
 
 
 
 
117
  st.image(top8.iloc[0].poster, use_column_width=True)
118
  with col1:
119
+ st.write("")
 
 
 
 
120
  st.image(top8.iloc[1].poster, use_column_width=True)
121
  with col2:
122
+ st.write("")
 
 
 
 
123
  st.image(top8.iloc[2].poster, use_column_width=True)
124
  with col3:
125
+ st.write("")
 
 
 
 
126
  st.image(top8.iloc[3].poster, use_column_width=True)
127
 
128
  st.divider()
 
130
  with st.container():
131
  col4, col5, col6, col7 = st.columns(4)
132
  with col4:
133
+ st.write("")
 
 
 
 
134
  st.image(top8.iloc[4].poster, use_column_width=True)
135
  with col5:
136
+ st.write("")
 
 
 
 
137
  st.image(top8.iloc[5].poster, use_column_width=True)
138
  with col6:
139
+ st.write("")
 
 
 
 
140
  st.image(top8.iloc[6].poster, use_column_width=True)
141
  with col7:
142
+ st.write("")
 
 
 
 
143
  st.image(top8.iloc[7].poster, use_column_width=True)
144
 
145
 
 
170
  ].sort_values("score", ascending=False)[:8]
171
  col0, col1, col2, col3 = st.columns(4)
172
  with col0:
173
+ st.write("") st.image(top_8_genre.iloc[0].poster, use_column_width=True)
 
 
 
 
 
174
  with col1:
175
+ st.write("") st.image(top_8_genre.iloc[1].poster, use_column_width=True)
 
 
 
 
 
176
  with col2:
177
+ st.write("") st.image(top_8_genre.iloc[2].poster, use_column_width=True)
 
 
 
 
 
178
  with col3:
179
+ st.write("") st.image(top_8_genre.iloc[3].poster, use_column_width=True)
 
 
 
 
 
180
 
181
  st.divider()
182
 
183
  col4, col5, col6, col7 = st.columns(4)
184
  with col4:
185
+ st.write("") st.image(top_8_genre.iloc[4].poster, use_column_width=True)
 
 
 
 
 
186
  with col5:
187
+ st.write("") st.image(top_8_genre.iloc[5].poster, use_column_width=True)
 
 
 
 
 
188
  with col6:
189
+ st.write("") st.image(top_8_genre.iloc[6].poster, use_column_width=True)
 
 
 
 
 
190
  with col7:
191
+ st.write("") st.image(top_8_genre.iloc[7].poster, use_column_width=True)
 
 
 
 
 
192
 
193
 
194
  # Function to display the top 8 animes with user given anime name for all genres
 
221
  with st.container():
222
  col0, col1, col2, col3 = st.columns(4)
223
  with col0:
224
+ st.write("") )
 
 
 
 
225
  st.image(recommended_anime_posters[0], use_column_width=True)
226
  with col1:
227
+ st.write("") )
 
 
 
 
228
  st.image(recommended_anime_posters[1], use_column_width=True)
229
  with col2:
230
+ st.write("") )
 
 
 
 
231
  st.image(recommended_anime_posters[2], use_column_width=True)
232
  with col3:
233
+ st.write("") )
 
 
 
 
234
  st.image(recommended_anime_posters[3], use_column_width=True)
235
 
236
  st.divider()
 
238
  with st.container():
239
  col4, col5, col6, col7 = st.columns(4)
240
  with col4:
241
+ st.write("") )
 
 
 
 
242
  st.image(recommended_anime_posters[4], use_column_width=True)
243
  with col5:
244
+ st.write("") )
 
 
 
 
245
  st.image(recommended_anime_posters[5], use_column_width=True)
246
  with col6:
247
+ st.write("") )
 
 
 
 
248
  st.image(recommended_anime_posters[6], use_column_width=True)
249
  with col7:
250
+ st.write("") )
 
 
 
 
251
  st.image(recommended_anime_posters[7], use_column_width=True)
252
 
253
 
 
281
  with st.container():
282
  col0, col1, col2, col3 = st.columns(4)
283
  with col0:
284
+ st.write("") )
 
 
 
 
285
  st.image(recommended_anime_posters[0], use_column_width=True)
286
  with col1:
287
+ st.write("") )
 
 
 
 
288
  st.image(recommended_anime_posters[1], use_column_width=True)
289
  with col2:
290
+ st.write("") )
 
 
 
 
291
  st.image(recommended_anime_posters[2], use_column_width=True)
292
  with col3:
293
+ st.write("") )
 
 
 
 
294
  st.image(recommended_anime_posters[3], use_column_width=True)
295
 
296
  st.divider()
 
298
  with st.container():
299
  col4, col5, col6, col7 = st.columns(4)
300
  with col4:
301
+ st.write("") )
 
 
 
 
302
  st.image(recommended_anime_posters[4], use_column_width=True)
303
  with col5:
304
+ st.write("") )
 
 
 
 
305
  st.image(recommended_anime_posters[5], use_column_width=True)
306
  with col6:
307
+ st.write("") )
 
 
 
 
308
  st.image(recommended_anime_posters[6], use_column_width=True)
309
  with col7:
310
+ st.write("") )
 
 
 
 
311
  st.image(recommended_anime_posters[7], use_column_width=True)
312
 
313
 
Recommender App Dev Copy.py ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pickle
4
+ from ast import literal_eval
5
+
6
+
7
+ # Importing the dataset
8
+ @st.cache_data
9
+ def load_data():
10
+ try:
11
+ anime_data = pd.read_csv(r"rec_data.csv")
12
+ except:
13
+ st.error("Dataset Not Found")
14
+ return anime_data
15
+
16
+
17
+ anime_data = load_data()
18
+
19
+
20
+ def get_genres():
21
+ genres = sorted(
22
+ list(set([j for i in anime_data["genres"] for j in literal_eval(i)]))
23
+ )
24
+ genres.insert(0, "All Genres")
25
+ genres.remove("NA")
26
+ return genres
27
+
28
+
29
+ # Uncomment this if you want to load the model
30
+ @st.cache_resource
31
+ def load_model():
32
+ try:
33
+ similarity = pickle.load(open(r"similarity.pkl", "rb"))
34
+ except:
35
+ st.error("Model Not Found")
36
+ return similarity
37
+
38
+
39
+ similarity = load_model()
40
+
41
+
42
+ # Fetching the poster and url of the anime
43
+ def fetch_anime_url(anime_id):
44
+ url = anime_data[anime_data["anime_id"] == anime_id].anime_url.values[0]
45
+ return url
46
+
47
+
48
+ def fetch_poster(anime_id):
49
+ poster = anime_data[anime_data["anime_id"] == anime_id].poster.values[0]
50
+ return poster
51
+
52
+
53
+ # Recommender System
54
+ def recommend(anime, genre=None):
55
+ if genre == None:
56
+ index = (
57
+ anime_data[anime_data["title"] == anime]
58
+ .sort_values("score", ascending=False)
59
+ .index[0]
60
+ )
61
+ elif genre != None:
62
+ index = (
63
+ anime_data[
64
+ (anime_data["title"] == anime)
65
+ | (anime_data["genres"].str.contains(genre))
66
+ ]
67
+ .sort_values("score", ascending=False)
68
+ .index[0]
69
+ )
70
+ # index = anime_data[anime_data["title"] == anime].index[0]
71
+ distances = sorted(
72
+ list(enumerate(similarity[index])), reverse=True, key=lambda x: x[1]
73
+ )
74
+
75
+ recommended_anime_names = []
76
+ recommended_anime_posters = []
77
+ recommended_anime_urls = []
78
+
79
+ for i in distances[1:9]:
80
+ # fetch the anime poster
81
+ anime_id = anime_data.iloc[i[0]].anime_id
82
+ recommended_anime_posters.append(fetch_poster(anime_id))
83
+ recommended_anime_names.append(anime_data.iloc[i[0]].title)
84
+ recommended_anime_urls.append(fetch_anime_url(anime_id))
85
+
86
+ return recommended_anime_names, recommended_anime_posters, recommended_anime_urls
87
+
88
+
89
+ # Function to display the top 8 animes with the highest rating
90
+ def top_animes():
91
+ style_for_page = """
92
+ <style>
93
+ div.st-emotion-cache-1v0mbdj.e115fcil1>img {
94
+ border-radius: 10px;
95
+ }
96
+ a.st-emotion-cache-1lbx6hs.e16zdaao0 {
97
+ border-radius: 15px;
98
+ text-align: center;
99
+ }
100
+ a.st-emotion-cache-1lbx6hs.e16zdaao0>div>p {
101
+ font-weight: 600;
102
+ }
103
+ a.st-emotion-cache-1lbx6hs.e16zdaao0:hover {
104
+ scale: 1.05;
105
+ transition-duration: 0.3s;
106
+ }
107
+ </style>
108
+ """
109
+ st.markdown(style_for_page, unsafe_allow_html=True)
110
+
111
+ top8 = anime_data.sort_values("score", ascending=False).head(8)
112
+
113
+ with st.container():
114
+ col0, col1, col2, col3 = st.columns(4)
115
+ with col0:
116
+ st.link_button(
117
+ f"{top8.iloc[0].title}",
118
+ f"{top8.iloc[0].anime_url}",
119
+ use_container_width=True,
120
+ )
121
+ st.image(top8.iloc[0].poster, use_column_width=True)
122
+ with col1:
123
+ st.link_button(
124
+ f"{top8.iloc[1].title}",
125
+ f"{top8.iloc[1].anime_url}",
126
+ use_container_width=True,
127
+ )
128
+ st.image(top8.iloc[1].poster, use_column_width=True)
129
+ with col2:
130
+ st.link_button(
131
+ f"{top8.iloc[2].title}",
132
+ f"{top8.iloc[2].anime_url}",
133
+ use_container_width=True,
134
+ )
135
+ st.image(top8.iloc[2].poster, use_column_width=True)
136
+ with col3:
137
+ st.link_button(
138
+ f"{top8.iloc[3].title}",
139
+ f"{top8.iloc[3].anime_url}",
140
+ use_container_width=True,
141
+ )
142
+ st.image(top8.iloc[3].poster, use_column_width=True)
143
+
144
+ st.divider()
145
+
146
+ with st.container():
147
+ col4, col5, col6, col7 = st.columns(4)
148
+ with col4:
149
+ st.link_button(
150
+ f"{top8.iloc[4].title}",
151
+ f"{top8.iloc[4].anime_url}",
152
+ use_container_width=True,
153
+ )
154
+ st.image(top8.iloc[4].poster, use_column_width=True)
155
+ with col5:
156
+ st.link_button(
157
+ f"{top8.iloc[5].title}",
158
+ f"{top8.iloc[5].anime_url}",
159
+ use_container_width=True,
160
+ )
161
+ st.image(top8.iloc[5].poster, use_column_width=True)
162
+ with col6:
163
+ st.link_button(
164
+ f"{top8.iloc[6].title}",
165
+ f"{top8.iloc[6].anime_url}",
166
+ use_container_width=True,
167
+ )
168
+ st.image(top8.iloc[6].poster, use_column_width=True)
169
+ with col7:
170
+ st.link_button(
171
+ f"{top8.iloc[7].title}",
172
+ f"{top8.iloc[7].anime_url}",
173
+ use_container_width=True,
174
+ )
175
+ st.image(top8.iloc[7].poster, use_column_width=True)
176
+
177
+
178
+ # Function to display the top 8 animes for user given genre
179
+ def top_animes_genres(genre_select):
180
+ style_for_page = """
181
+ <style>
182
+ div.st-emotion-cache-1v0mbdj.e115fcil1>img {
183
+ border-radius: 10px;
184
+ }
185
+ a.st-emotion-cache-1lbx6hs.e16zdaao0 {
186
+ border-radius: 15px;
187
+ text-align: center;
188
+ }
189
+ a.st-emotion-cache-1lbx6hs.e16zdaao0>div>p {
190
+ font-weight: 600;
191
+ }
192
+ a.st-emotion-cache-1lbx6hs.e16zdaao0:hover {
193
+ scale: 1.05;
194
+ transition-duration: 0.3s;
195
+ }
196
+ </style>
197
+ """
198
+ st.markdown(style_for_page, unsafe_allow_html=True)
199
+
200
+ top_8_genre = anime_data[
201
+ anime_data["genres"].str.contains(genre_select)
202
+ ].sort_values("score", ascending=False)[:8]
203
+ col0, col1, col2, col3 = st.columns(4)
204
+ with col0:
205
+ st.link_button(
206
+ f"{top_8_genre.iloc[0].title}",
207
+ f"{top_8_genre.iloc[0].anime_url}",
208
+ use_container_width=True,
209
+ )
210
+ st.image(top_8_genre.iloc[0].poster, use_column_width=True)
211
+ with col1:
212
+ st.link_button(
213
+ f"{top_8_genre.iloc[1].title}",
214
+ f"{top_8_genre.iloc[1].anime_url}",
215
+ use_container_width=True,
216
+ )
217
+ st.image(top_8_genre.iloc[1].poster, use_column_width=True)
218
+ with col2:
219
+ st.link_button(
220
+ f"{top_8_genre.iloc[2].title}",
221
+ f"{top_8_genre.iloc[2].anime_url}",
222
+ use_container_width=True,
223
+ )
224
+ st.image(top_8_genre.iloc[2].poster, use_column_width=True)
225
+ with col3:
226
+ st.link_button(
227
+ f"{top_8_genre.iloc[3].title}",
228
+ f"{top_8_genre.iloc[3].anime_url}",
229
+ use_container_width=True,
230
+ )
231
+ st.image(top_8_genre.iloc[3].poster, use_column_width=True)
232
+
233
+ st.divider()
234
+
235
+ col4, col5, col6, col7 = st.columns(4)
236
+ with col4:
237
+ st.link_button(
238
+ f"{top_8_genre.iloc[4].title}",
239
+ f"{top_8_genre.iloc[4].anime_url}",
240
+ use_container_width=True,
241
+ )
242
+ st.image(top_8_genre.iloc[4].poster, use_column_width=True)
243
+ with col5:
244
+ st.link_button(
245
+ f"{top_8_genre.iloc[5].title}",
246
+ f"{top_8_genre.iloc[5].anime_url}",
247
+ use_container_width=True,
248
+ )
249
+ st.image(top_8_genre.iloc[5].poster, use_column_width=True)
250
+ with col6:
251
+ st.link_button(
252
+ f"{top_8_genre.iloc[6].title}",
253
+ f"{top_8_genre.iloc[6].anime_url}",
254
+ use_container_width=True,
255
+ )
256
+ st.image(top_8_genre.iloc[6].poster, use_column_width=True)
257
+ with col7:
258
+ st.link_button(
259
+ f"{top_8_genre.iloc[7].title}",
260
+ f"{top_8_genre.iloc[7].anime_url}",
261
+ use_container_width=True,
262
+ )
263
+ st.image(top_8_genre.iloc[7].poster, use_column_width=True)
264
+
265
+
266
+ # Function to display the top 8 animes with user given anime name for all genres
267
+ def top_animes_custom(anime_select):
268
+ style_for_page = """
269
+ <style>
270
+ div.st-emotion-cache-1v0mbdj.e115fcil1>img {
271
+ border-radius: 10px;
272
+ }
273
+ a.st-emotion-cache-1lbx6hs.e16zdaao0 {
274
+ border-radius: 15px;
275
+ text-align: center;
276
+ }
277
+ a.st-emotion-cache-1lbx6hs.e16zdaao0>div>p {
278
+ font-weight: 600;
279
+ }
280
+ a.st-emotion-cache-1lbx6hs.e16zdaao0:hover {
281
+ scale: 1.05;
282
+ transition-duration: 0.3s;
283
+ }
284
+ </style>
285
+ """
286
+ st.markdown(style_for_page, unsafe_allow_html=True)
287
+
288
+ (
289
+ recommended_anime_names,
290
+ recommended_anime_posters,
291
+ recommended_anime_urls,
292
+ ) = recommend(anime_select)
293
+ with st.container():
294
+ col0, col1, col2, col3 = st.columns(4)
295
+ with col0:
296
+ st.link_button(
297
+ f"{recommended_anime_names[0]}",
298
+ f"{recommended_anime_urls[0]}",
299
+ use_container_width=True,
300
+ )
301
+ st.image(recommended_anime_posters[0], use_column_width=True)
302
+ with col1:
303
+ st.link_button(
304
+ f"{recommended_anime_names[1]}",
305
+ f"{recommended_anime_urls[1]}",
306
+ use_container_width=True,
307
+ )
308
+ st.image(recommended_anime_posters[1], use_column_width=True)
309
+ with col2:
310
+ st.link_button(
311
+ f"{recommended_anime_names[2]}",
312
+ f"{recommended_anime_urls[2]}",
313
+ use_container_width=True,
314
+ )
315
+ st.image(recommended_anime_posters[2], use_column_width=True)
316
+ with col3:
317
+ st.link_button(
318
+ f"{recommended_anime_names[3]}",
319
+ f"{recommended_anime_urls[3]}",
320
+ use_container_width=True,
321
+ )
322
+ st.image(recommended_anime_posters[3], use_column_width=True)
323
+
324
+ st.divider()
325
+
326
+ with st.container():
327
+ col4, col5, col6, col7 = st.columns(4)
328
+ with col4:
329
+ st.link_button(
330
+ f"{recommended_anime_names[4]}",
331
+ f"{recommended_anime_urls[4]}",
332
+ use_container_width=True,
333
+ )
334
+ st.image(recommended_anime_posters[4], use_column_width=True)
335
+ with col5:
336
+ st.link_button(
337
+ f"{recommended_anime_names[5]}",
338
+ f"{recommended_anime_urls[5]}",
339
+ use_container_width=True,
340
+ )
341
+ st.image(recommended_anime_posters[5], use_column_width=True)
342
+ with col6:
343
+ st.link_button(
344
+ f"{recommended_anime_names[6]}",
345
+ f"{recommended_anime_urls[6]}",
346
+ use_container_width=True,
347
+ )
348
+ st.image(recommended_anime_posters[6], use_column_width=True)
349
+ with col7:
350
+ st.link_button(
351
+ f"{recommended_anime_names[7]}",
352
+ f"{recommended_anime_urls[7]}",
353
+ use_container_width=True,
354
+ )
355
+ st.image(recommended_anime_posters[7], use_column_width=True)
356
+
357
+
358
+ # Function to display the top 8 animes with user given anime name and genre
359
+ def top_animes_custom_genres(anime_select, genre_select):
360
+ style_for_page = """
361
+ <style>
362
+ div.st-emotion-cache-1v0mbdj.e115fcil1>img {
363
+ border-radius: 10px;
364
+ }
365
+ a.st-emotion-cache-1lbx6hs.e16zdaao0 {
366
+ border-radius: 15px;
367
+ text-align: center;
368
+ }
369
+ a.st-emotion-cache-1lbx6hs.e16zdaao0>div>p {
370
+ font-weight: 600;
371
+ }
372
+ a.st-emotion-cache-1lbx6hs.e16zdaao0:hover {
373
+ scale: 1.05;
374
+ transition-duration: 0.3s;
375
+ }
376
+ </style>
377
+ """
378
+ st.markdown(style_for_page, unsafe_allow_html=True)
379
+
380
+ (
381
+ recommended_anime_names,
382
+ recommended_anime_posters,
383
+ recommended_anime_urls,
384
+ ) = recommend(anime_select, genre_select)
385
+ with st.container():
386
+ col0, col1, col2, col3 = st.columns(4)
387
+ with col0:
388
+ st.link_button(
389
+ f"{recommended_anime_names[0]}",
390
+ f"{recommended_anime_urls[0]}",
391
+ use_container_width=True,
392
+ )
393
+ st.image(recommended_anime_posters[0], use_column_width=True)
394
+ with col1:
395
+ st.link_button(
396
+ f"{recommended_anime_names[1]}",
397
+ f"{recommended_anime_urls[1]}",
398
+ use_container_width=True,
399
+ )
400
+ st.image(recommended_anime_posters[1], use_column_width=True)
401
+ with col2:
402
+ st.link_button(
403
+ f"{recommended_anime_names[2]}",
404
+ f"{recommended_anime_urls[2]}",
405
+ use_container_width=True,
406
+ )
407
+ st.image(recommended_anime_posters[2], use_column_width=True)
408
+ with col3:
409
+ st.link_button(
410
+ f"{recommended_anime_names[3]}",
411
+ f"{recommended_anime_urls[3]}",
412
+ use_container_width=True,
413
+ )
414
+ st.image(recommended_anime_posters[3], use_column_width=True)
415
+
416
+ st.divider()
417
+
418
+ with st.container():
419
+ col4, col5, col6, col7 = st.columns(4)
420
+ with col4:
421
+ st.link_button(
422
+ f"{recommended_anime_names[4]}",
423
+ f"{recommended_anime_urls[4]}",
424
+ use_container_width=True,
425
+ )
426
+ st.image(recommended_anime_posters[4], use_column_width=True)
427
+ with col5:
428
+ st.link_button(
429
+ f"{recommended_anime_names[5]}",
430
+ f"{recommended_anime_urls[5]}",
431
+ use_container_width=True,
432
+ )
433
+ st.image(recommended_anime_posters[5], use_column_width=True)
434
+ with col6:
435
+ st.link_button(
436
+ f"{recommended_anime_names[6]}",
437
+ f"{recommended_anime_urls[6]}",
438
+ use_container_width=True,
439
+ )
440
+ st.image(recommended_anime_posters[6], use_column_width=True)
441
+ with col7:
442
+ st.link_button(
443
+ f"{recommended_anime_names[7]}",
444
+ f"{recommended_anime_urls[7]}",
445
+ use_container_width=True,
446
+ )
447
+ st.image(recommended_anime_posters[7], use_column_width=True)
448
+
449
+
450
+ # Recommender Page
451
+ def recommender_page():
452
+ style_for_page = """
453
+ <style>
454
+ button.st-emotion-cache-c766yy.ef3psqc11 {
455
+ border-radius: 10px;
456
+ }
457
+
458
+ button.st-emotion-cache-c766yy.ef3psqc11:hover {
459
+ scale: 1.05;
460
+ transition-duration: 0.3s;
461
+ }
462
+ </style>
463
+ """
464
+ st.markdown(style_for_page, unsafe_allow_html=True)
465
+
466
+ st.title("Anime Recommendation System :ninja:")
467
+
468
+ anime_list = anime_data["title"].tolist()
469
+ anime_list.sort()
470
+ anime_list.insert(0, "Top 8 Animes")
471
+ anime_select = st.selectbox("Select an Anime", anime_list, key="anime_select")
472
+ genre_select = st.selectbox("Select a Genre", get_genres(), key="genre_select")
473
+
474
+ if st.button("Recommendation"):
475
+ st.divider()
476
+ if anime_select == "Top 8 Animes" and genre_select == "All Genres":
477
+ top_animes()
478
+ st.divider()
479
+ elif anime_select == "Top 8 Animes" and genre_select != "All Genres":
480
+ top_animes_genres(genre_select)
481
+ st.divider()
482
+ elif anime_select != "Top 8 Animes" and genre_select == "All Genres":
483
+ top_animes_custom(anime_select)
484
+ st.divider()
485
+ elif anime_select != "Top 8 Animes" and genre_select != "All Genres":
486
+ top_animes_custom_genres(anime_select, genre_select)
487
+ st.divider()
488
+
489
+
490
+ if __name__ == "__main__":
491
+ recommender_page()