-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
246 lines (225 loc) · 8.15 KB
/
index.html
File metadata and controls
246 lines (225 loc) · 8.15 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hotel Recommender System</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="container">
<h1>Hotel Recommender System</h1>
<form id="recommendationForm">
<div class="form-group">
<label for="city">Select City:</label>
<input type="text" id="city" name="city" required />
</div>
<h3>Select Your Preferred Features:</h3>
<div class="feature-grid">
<!-- These features match the selected_features from vertopal.com_recommender_model.md -->
<div class="feature-item">
<input
type="checkbox"
id="breakfast"
name="features"
value="Free breakfast"
/>
<label for="breakfast">Free Breakfast</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="wifi"
name="features"
value="Free Wi-Fi"
/>
<label for="wifi">Free Wi-Fi</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="ac"
name="features"
value="Air conditioning"
/>
<label for="ac">Air Conditioning</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="restaurant"
name="features"
value="Restaurant"
/>
<label for="restaurant">Restaurant</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="parking"
name="features"
value="Free parking"
/>
<label for="parking">Free Parking</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="roomservice"
name="features"
value="Room service"
/>
<label for="roomservice">Room Service</label>
</div>
<div class="feature-item">
<input type="checkbox" id="pool" name="features" value="Pool" />
<label for="pool">Pool</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="laundry"
name="features"
value="Full-service laundry"
/>
<label for="laundry">Full-service Laundry</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="fitness"
name="features"
value="Fitness centre"
/>
<label for="fitness">Fitness Centre</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="kitchen"
name="features"
value="Kitchen"
/>
<label for="kitchen">Kitchen</label>
</div>
<div class="feature-item">
<input
type="checkbox"
id="shuttle"
name="features"
value="Airport shuttle"
/>
<label for="shuttle">Airport Shuttle</label>
</div>
<div class="feature-item">
<input type="checkbox" id="spa" name="features" value="Spa" />
<label for="spa">Spa</label>
</div>
</div>
<!-- Add these sliders after the feature grid in the form -->
<div class="weight-controls">
<div class="form-group">
<label for="priceWeight">Price Importance: (Cost Effectiveness)</label>
<input type="range" id="priceWeight" name="price_weight" min="0" max="1" step="0.1" value="0.3">
<span id="priceWeightValue">0.3</span>
</div>
<div class="form-group">
<label for="ratingWeight">Rating Importance:</label>
<input type="range" id="ratingWeight" name="rating_weight" min="0" max="1" step="0.1" value="0.2">
<span id="ratingWeightValue">0.2</span>
</div>
</div>
<button type="submit" class="submit-btn">Get Recommendations</button>
</form>
<div id="results"></div>
</div>
<script>
document.getElementById("recommendationForm").addEventListener("submit", async (e) => {
e.preventDefault();
// Clear previous results
const resultsDiv = document.getElementById("results");
resultsDiv.innerHTML = `
<div class="progress-container">
<div class="progress-bar" id="progressBar"></div>
</div>
<p class="loading">Loading recommendations...</p>
`;
const progressBar = document.getElementById("progressBar");
// Simulate progress
let progress = 0;
const interval = setInterval(() => {
if (progress < 100) {
progress += 2.0;
progressBar.style.width = progress + '%';
} else {
clearInterval(interval);
}
}, 1500);
const formData = new FormData(e.target);
const selectedFeatures = formData.getAll("features");
// Convert selected features to binary array
const featureList = [
"Free breakfast", "Free Wi-Fi", "Air conditioning", "Restaurant",
"Free parking", "Room service", "Pool", "Full-service laundry",
"Fitness centre", "Kitchen", "Airport shuttle", "Spa"
];
const binaryFeatures = featureList.map(feature =>
selectedFeatures.includes(feature) ? 1 : 0
);
const requestData = {
city: formData.get("city"),
features: binaryFeatures,
price_weight: parseFloat(formData.get("price_weight")),
rating_weight: parseFloat(formData.get("rating_weight"))
};
try {
const response = await fetch("/recommend", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestData),
});
const data = await response.json();
if (response.ok) {
// Create results HTML with metrics
let resultsHTML = `
<h2>Recommended Hotels</h2>
<div class="metrics">
<p>Total Hotels Found: ${data.metrics.total_hotels}</p>
<p>Processed Hotels: ${data.metrics.processed_hotels}</p>
</div>
<div class="hotel-list">
`;
data.recommendations.forEach((hotel) => {
resultsHTML += `
<div class="hotel-card">
<h3>${hotel.Hotel_Name}</h3>
<p>City: ${hotel.City}</p>
<p>Rating: ${hotel.Hotel_Rating}/5</p>
<p>Price: ₹${hotel.Hotel_Price}</p>
<p>Score: ${(hotel.Score * 100).toFixed(2)}%</p>
<a href="${hotel.URL}" target="_blank" class="book-link">Book Now</a>
</div>
`;
});
resultsHTML += "</div>";
resultsDiv.innerHTML = resultsHTML;
} else {
resultsDiv.innerHTML = `<p class="error">Error: ${data.error}</p>`;
}
} catch (error) {
resultsDiv.innerHTML = `<p class="error">Error connecting to server: ${error.message}</p>`;
}
});
// Add event listeners for the range inputs
document.getElementById("priceWeight").addEventListener("input", (e) => {
document.getElementById("priceWeightValue").textContent = e.target.value;
});
document.getElementById("ratingWeight").addEventListener("input", (e) => {
document.getElementById("ratingWeightValue").textContent = e.target.value;
});
</script>
</body>
</html>