-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
57 lines (57 loc) · 1.99 KB
/
index.html
File metadata and controls
57 lines (57 loc) · 1.99 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie Recommendation System</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div class="container">
<h1>Movie Recommendation System</h1>
<form id="movieForm">
<label for="movie">Select a Movie:</label>
<select id="movie" name="movie">
<option value="">--Choose a Movie--</option>
{% for movie in movies %}
<option value="{{ movie }}">{{ movie }}</option>
{% endfor %}
</select>
<button type="submit">Get Recommendations</button>
</form>
<div id="result">
<h2>Recommended Movies:</h2>
<ul id="recommendations"></ul>
</div>
</div>
<script>
document.getElementById('movieForm').addEventListener('submit', async function (e) {
e.preventDefault();
const movie = document.getElementById('movie').value;
if (!movie) {
alert('Please select a movie');
return;
}
const response = await fetch('/recommend', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `movie=${encodeURIComponent(movie)}`
});
const data = await response.json();
const recommendations = document.getElementById('recommendations');
recommendations.innerHTML = '';
if (data.status === 'success') {
data.movies.forEach(m => {
const li = document.createElement('li');
li.textContent = m;
recommendations.appendChild(li);
});
} else {
alert(data.message);
}
});
</script>
</body>
</html>