-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
300 lines (278 loc) · 10.5 KB
/
index.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Anime Recommendation</title>
<link
href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
rel="stylesheet"
/>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<style>
body {
font-family: "Inter", sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
.card {
background-color: var(--card-bg);
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05);
border-radius: 10px;
padding: 24px;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
transform: translateY(-3px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}
.input-field,
.select-field,
.textarea-field {
background-color: var(--input-bg);
border: 1px solid var(--border-color);
color: var(--text-color);
transition: background-color 0.2s ease, border-color 0.2s ease;
}
.input-field:focus,
.select-field:focus,
.textarea-field:focus {
background-color: var(--input-focus-bg);
border-color: #6366f1;
outline: none;
}
.button {
background-color: #6366f1;
color: #fff;
transition: background-color 0.2s ease;
}
.button:hover {
background-color: #4f46e5;
}
.recommendation-card {
background-color: var(--card-bg-alt);
border-radius: 8px;
padding: 14px;
margin-top: 12px;
}
:root {
--background-color: #fdfdfd;
--text-color: #2d2d2d;
--card-bg: #ffffff;
--input-bg: #f0f0f0;
--input-focus-bg: #ffffff;
--border-color: #ddd;
--card-bg-alt: #fafafa;
}
[data-theme="dark"] {
--background-color: #181818;
--text-color: #e4e4e4;
--card-bg: #242424;
--input-bg: #333333;
--input-focus-bg: #3a3a3a;
--border-color: #555;
--card-bg-alt: #2f2f2f;
}
</style>
</head>
<body class="bg-gray-100 text-gray-800" data-theme="light">
<div class="py-8">
<h1 class="text-4xl font-bold text-center mb-4">
Anime Recommendation System
</h1>
<p class="text-center max-w-2xl mx-auto text-gray-500">
This project is an Anime Recommendation System that uses a combination
of content-based filtering and collaborative filtering to suggest anime
based on user preferences.
</p>
</div>
<div class="min-h-screen flex flex-col items-center justify-center px-4">
<div class="w-full max-w-md mb-8">
<div class="card space-y-6">
<h2 class="text-2xl font-semibold text-center">
Get Your Anime Recommendations
</h2>
<div class="space-y-4">
<label for="userType" class="block text-sm font-medium"
>User Type</label
>
<select
id="userType"
class="select-field mt-1 block w-full rounded-md p-2 focus:ring focus:ring-indigo-500"
>
<option value="existing">Existing User</option>
<option value="new">New User</option>
</select>
</div>
<div id="existingUserForm" class="space-y-4">
<label for="watchHistory" class="block text-sm font-medium"
>Watch History (Anime:Rating)</label
>
<textarea
id="watchHistory"
rows="4"
class="textarea-field mt-1 block w-full rounded-md p-2 focus:ring focus:ring-indigo-500"
placeholder="e.g., Naruto:5,Attack on Titan:4"
></textarea>
</div>
<div id="newUserForm" class="space-y-4 hidden">
<label for="preferredGenres" class="block text-sm font-medium"
>Preferred Genres</label
>
<input
id="preferredGenres"
type="text"
class="input-field mt-1 block w-full rounded-md p-2 focus:ring focus:ring-indigo-500"
placeholder="e.g., Action, Adventure"
/>
<label for="likedAnimeTitles" class="block text-sm font-medium"
>Liked Anime Titles</label
>
<input
id="likedAnimeTitles"
type="text"
class="input-field mt-1 block w-full rounded-md p-2 focus:ring focus:ring-indigo-500"
placeholder="e.g., Naruto, One Piece"
/>
</div>
<button
id="submitBtn"
class="button w-full rounded-md py-2 mt-4 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
Get Recommendations
</button>
<div id="recommendations" class="mt-6 text-center"></div>
</div>
</div>
<div class="w-full max-w-2xl text-center mb-12">
<h2 class="text-2xl font-semibold">How It Works</h2>
<p class="text-gray-500 mt-4">
The system uses a combination of content-based filtering and
collaborative filtering methods to provide anime suggestions based on
user input. Simply provide your preferred genres or liked anime
titles, and get personalized recommendations!
</p>
</div>
</div>
<footer class="w-full bg-gray-900 text-white py-4">
<div class="max-w-4xl mx-auto flex justify-between items-center px-4">
<p>
© 2024 Harshit
<span class="text-italic text-xs">(https://leoncyriac.me)</span>
</p>
<button id="toggleTheme" class="px-4 py-2 bg-gray-700 rounded">
Toggle Theme
</button>
</div>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function () {
const savedTheme = localStorage.getItem("theme") || getCookie("theme");
if (savedTheme) {
document.body.setAttribute("data-theme", savedTheme);
document.body.style.backgroundColor = `var(--background-color)`;
document.body.style.color = `var(--text-color)`;
}
});
document
.getElementById("userType")
.addEventListener("change", function () {
const userType = this.value;
document
.getElementById("existingUserForm")
.classList.toggle("hidden", userType !== "existing");
document
.getElementById("newUserForm")
.classList.toggle("hidden", userType !== "new");
});
document
.getElementById("submitBtn")
.addEventListener("click", function () {
const userType = document.getElementById("userType").value;
const recommendationsDiv = document.getElementById("recommendations");
recommendationsDiv.innerHTML = "";
if (userType === "existing") {
const watchHistory = document
.getElementById("watchHistory")
.value.split(",")
.reduce((acc, curr) => {
const [anime, rating] = curr.split(":");
if (anime && rating)
acc[anime.trim()] = parseInt(rating.trim());
return acc;
}, {});
axios
.post("http://127.0.0.1:5000/recommend/existing", {
watch_history: watchHistory,
})
.then((response) => {
displayRecommendations(response.data.recommendations);
})
.catch((error) => {
recommendationsDiv.innerHTML = `<p class="text-red-500">Error: ${error.response.data.error}</p>`;
});
} else {
const preferredGenres = document
.getElementById("preferredGenres")
.value.split(",")
.map((g) => g.trim());
const likedAnimeTitles = document
.getElementById("likedAnimeTitles")
.value.split(",")
.map((a) => a.trim());
axios
.post("http://127.0.0.1:5000/recommend/new", {
preferred_genres: preferredGenres,
liked_anime_titles: likedAnimeTitles,
})
.then((response) => {
displayRecommendations(response.data.recommendations);
})
.catch((error) => {
recommendationsDiv.innerHTML = `<p class="text-red-500">Error: ${error.response.data.error}</p>`;
});
}
});
function displayRecommendations(recommendations) {
const recommendationsDiv = document.getElementById("recommendations");
recommendationsDiv.innerHTML = `<h2 class="text-lg font-semibold text-gray-800">Recommendations:</h2>`;
recommendations.forEach((anime) => {
const animeCard = document.createElement("div");
animeCard.classList.add("recommendation-card");
animeCard.innerHTML = `<p class="text-md font-medium">${anime}</p>`;
recommendationsDiv.appendChild(animeCard);
});
}
document
.getElementById("toggleTheme")
.addEventListener("click", function () {
const currentTheme = document.body.getAttribute("data-theme");
const newTheme = currentTheme === "light" ? "dark" : "light";
document.body.setAttribute("data-theme", newTheme);
document.body.style.backgroundColor = `var(--background-color)`;
document.body.style.color = `var(--text-color)`;
localStorage.setItem("theme", newTheme);
setCookie("theme", newTheme, 365);
});
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = "expires=" + date.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
function getCookie(name) {
const cname = name + "=";
const decodedCookie = decodeURIComponent(document.cookie);
const cookieArr = decodedCookie.split(";");
for (let i = 0; i < cookieArr.length; i++) {
let c = cookieArr[i].trim();
if (c.indexOf(cname) == 0) return c.substring(cname.length, c.length);
}
return "";
}
</script>
</body>
</html>