Coots commited on
Commit
82bdc34
·
verified ·
1 Parent(s): 3f00d1c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +4 -207
index.html CHANGED
@@ -45,14 +45,7 @@
45
 
46
  <!-- Chat Area -->
47
  <div class="chat-container p-4 overflow-y-auto" id="chat-area">
48
- <div class="bot-message bg-gray-100 rounded-lg p-4 max-w-xs mb-3">
49
- <p>Hello! 👋 I'm your Tile Calculator Assistant. Let's estimate how many tiles you need.</p>
50
- <p class="mt-2">Are you looking for <span class="font-semibold">floor</span> or <span class="font-semibold">wall</span> tiles?</p>
51
- <div class="flex gap-2 mt-3">
52
- <button onclick="selectTileType('floor')" class="quick-reply bg-white text-indigo-600 border border-indigo-600 px-4 py-2 rounded-full font-medium hover:bg-indigo-50">Floor</button>
53
- <button onclick="selectTileType('wall')" class="quick-reply bg-white text-indigo-600 border border-indigo-600 px-4 py-2 rounded-full font-medium hover:bg-indigo-50">Wall</button>
54
- </div>
55
- </div>
56
  </div>
57
 
58
  <!-- Input Area -->
@@ -67,7 +60,7 @@
67
  </div>
68
  </div>
69
 
70
- <!-- Recommendations Section -->
71
  <div class="bg-gray-50 p-4 border-t">
72
  <h3 class="font-semibold text-gray-800 mb-3">Recommended Products</h3>
73
  <div class="grid grid-cols-2 md:grid-cols-4 gap-4" id="recommendations"></div>
@@ -75,203 +68,7 @@
75
  </div>
76
  </div>
77
 
78
- <!-- Main chatbot script -->
79
- <script>
80
- const state = {
81
- step: 'tileType',
82
- tileType: null,
83
- area: null,
84
- tileLength: null,
85
- tileWidth: null
86
- };
87
-
88
- const chatArea = document.getElementById('chat-area');
89
- const userInput = document.getElementById('user-input');
90
- const recommendations = document.getElementById('recommendations');
91
- const resetBtn = document.getElementById('reset-btn');
92
-
93
- resetBtn.addEventListener('click', resetConversation);
94
- userInput.addEventListener('keypress', (e) => {
95
- if (e.key === 'Enter') sendMessage();
96
- });
97
-
98
- function resetConversation() {
99
- state.step = 'tileType';
100
- state.tileType = null;
101
- state.area = null;
102
- state.tileLength = null;
103
- state.tileWidth = null;
104
-
105
- chatArea.innerHTML = `
106
- <div class="bot-message bg-gray-100 rounded-lg p-4 max-w-xs mb-3">
107
- <p>Hello! 👋 I'm your Tile Calculator Assistant. Let's estimate how many tiles you need.</p>
108
- <p class="mt-2">Are you looking for <span class="font-semibold">floor</span> or <span class="font-semibold">wall</span> tiles?</p>
109
- <div class="flex gap-2 mt-3">
110
- <button onclick="selectTileType('floor')" class="quick-reply bg-white text-indigo-600 border border-indigo-600 px-4 py-2 rounded-full font-medium hover:bg-indigo-50">Floor</button>
111
- <button onclick="selectTileType('wall')" class="quick-reply bg-white text-indigo-600 border border-indigo-600 px-4 py-2 rounded-full font-medium hover:bg-indigo-50">Wall</button>
112
- </div>
113
- </div>
114
- `;
115
- recommendations.innerHTML = '';
116
- }
117
-
118
- function selectTileType(type) {
119
- state.tileType = type;
120
- state.step = 'area';
121
-
122
- addMessage('user', type === 'floor' ? 'Floor tiles' : 'Wall tiles');
123
- showTyping();
124
-
125
- setTimeout(() => {
126
- hideTyping();
127
- addMessage('bot', `Great choice for ${type} tiles! What's the total area you need to cover (in sq.ft)?`);
128
- }, 1000);
129
- }
130
-
131
- function sendMessage() {
132
- const message = userInput.value.trim();
133
- if (!message) return;
134
-
135
- addMessage('user', message);
136
- userInput.value = '';
137
-
138
- processUser Message(message);
139
- }
140
-
141
- function processUser Message(message) {
142
- showTyping();
143
-
144
- setTimeout(() => {
145
- hideTyping();
146
-
147
- if (state.step === 'area') {
148
- const area = parseFloat(message);
149
- if (isNaN(area)) {
150
- addMessage('bot', 'Please enter a valid number for the area (e.g. 120).');
151
- return;
152
- }
153
-
154
- state.area = area;
155
- state.step = 'tileLength';
156
- addMessage('bot', 'Now, please enter the tile length (in feet):');
157
-
158
- } else if (state.step === 'tileLength') {
159
- const length = parseFloat(message);
160
- if (isNaN(length) || length <= 0) {
161
- addMessage('bot', 'Please enter a valid positive number for the tile length.');
162
- return;
163
- }
164
-
165
- state.tileLength = length;
166
- state.step = 'tileWidth';
167
- addMessage('bot', 'Now, please enter the tile width (in feet):');
168
-
169
- } else if (state.step === 'tileWidth') {
170
- const width = parseFloat(message);
171
- if (isNaN(width) || width <= 0) {
172
- addMessage('bot', 'Please enter a valid positive number for the tile width.');
173
- return;
174
- }
175
-
176
- state.tileWidth = width;
177
- calculateTiles();
178
- }
179
- }, 1000);
180
- }
181
-
182
- function calculateTiles() {
183
- const tileArea = state.tileLength * state.tileWidth; // Calculate tile area
184
- const numTiles = Math.ceil((state.area / tileArea) * 1.1); // 10% buffer
185
- const numBoxes = Math.ceil(numTiles / 10); // Assuming 10 tiles per box
186
-
187
- chatArea.insertAdjacentHTML('beforeend', `
188
- <div class="bot-message bg-gray-100 rounded-lg p-4 mb-3">
189
- <p class="font-semibold">Calculation Results:</p>
190
- <p>🧱 Tile Type: ${state.tileType}</p>
191
- <p>📐 Area to Cover: ${state.area} sq.ft</p>
192
- <p>🧮 Tile Size: ${state.tileLength} ft x ${state.tileWidth} ft</p>
193
- <p class="mt-2">🔢 <span class="font-bold">Tiles Needed:</span> ${numTiles} (${numBoxes} boxes)</p>
194
- </div>
195
- `);
196
- state.step = 'complete';
197
-
198
- // Fetch recommended products
199
- fetchRecommendedProducts();
200
- }
201
-
202
- function fetchRecommendedProducts() {
203
- fetch('/recommend', {
204
- method: 'POST',
205
- headers: {
206
- 'Content-Type': 'application/json',
207
- },
208
- body: JSON.stringify({
209
- tile_type: state.tileType,
210
- coverage: state.tileLength * state.tileWidth,
211
- area: state.area,
212
- price_range: [3, 10] // Example price range
213
- })
214
- })
215
- .then(response => response.json())
216
- .then(data => {
217
- if (data.recommended_products && data.recommended_products.length > 0) {
218
- loadProductRecommendations(data.recommended_products);
219
- } else {
220
- recommendations.innerHTML = `
221
- <div class="col-span-4 text-center py-4 text-gray-500">
222
- No strong recommendations available for these parameters.
223
- </div>
224
- `;
225
- }
226
- })
227
- .catch(error => {
228
- console.error('Error fetching recommendations:', error);
229
- });
230
- }
231
-
232
- function loadProductRecommendations(products) {
233
- recommendations.innerHTML = '';
234
-
235
- products.slice(0, 4).forEach(product => {
236
- const productCard = document.createElement('div');
237
- productCard.className = 'bg-white rounded-lg overflow-hidden shadow-sm border border-gray-100';
238
- productCard.innerHTML = `
239
- <div class="h-32 bg-gray-200 flex items-center justify-center">
240
- <svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
241
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
242
- </svg>
243
- </div>
244
- <div class="p-3">
245
- <h4 class="font-medium text-gray-800">${product.name || 'Tile Product'}</h4>
246
- <p class="text-sm text-gray-600 mt-1">${product.price || '$0.00'}/box</p>
247
- <button class="mt-2 w-full bg-indigo-600 text-white py-1 rounded text-sm hover:bg-indigo-700 transition">View Details</button>
248
- </div>
249
- `;
250
- recommendations.appendChild(productCard);
251
- });
252
- }
253
-
254
- function addMessage(sender, message) {
255
- const messageDiv = document.createElement('div');
256
- messageDiv.className = `${sender}-message ${sender === 'user' ? 'ml-auto bg-indigo-600 text-white' : 'bg-gray-100'} rounded-lg p-4 max-w-xs mb-3`;
257
- messageDiv.textContent = message;
258
- chatArea.appendChild(messageDiv);
259
- chatArea.scrollTop = chatArea.scrollHeight;
260
- }
261
-
262
- function showTyping() {
263
- const typingDiv = document.createElement('div');
264
- typingDiv.className = 'typing-indicator bg-gray-100 rounded-lg p-4 max-w-xs mb-3 flex gap-1';
265
- typingDiv.id = 'typing-indicator';
266
- typingDiv.innerHTML = '<span class="w-2 h-2 bg-gray-400 rounded-full"></span><span class="w-2 h-2 bg-gray-400 rounded-full"></span><span class="w-2 h-2 bg-gray-400 rounded-full"></span>';
267
- chatArea.appendChild(typingDiv);
268
- chatArea.scrollTop = chatArea.scrollHeight;
269
- }
270
-
271
- function hideTyping() {
272
- const typingIndicator = document.getElementById('typing-indicator');
273
- if (typingIndicator) typingIndicator.remove();
274
- }
275
- </script>
276
  </body>
277
  </html>
 
45
 
46
  <!-- Chat Area -->
47
  <div class="chat-container p-4 overflow-y-auto" id="chat-area">
48
+ <!-- Initial bot message -->
 
 
 
 
 
 
 
49
  </div>
50
 
51
  <!-- Input Area -->
 
60
  </div>
61
  </div>
62
 
63
+ <!-- Recommendations -->
64
  <div class="bg-gray-50 p-4 border-t">
65
  <h3 class="font-semibold text-gray-800 mb-3">Recommended Products</h3>
66
  <div class="grid grid-cols-2 md:grid-cols-4 gap-4" id="recommendations"></div>
 
68
  </div>
69
  </div>
70
 
71
+ <!-- Include chatbot logic -->
72
+ <script src="chat.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  </body>
74
  </html>