Update index.html
Browse files- index.html +120 -64
index.html
CHANGED
@@ -1,69 +1,125 @@
|
|
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 |
-
</
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
6 |
+
<title>Tile Calculator AI</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<style>
|
9 |
+
/* Your existing styles… */
|
10 |
+
</style>
|
11 |
+
</head>
|
12 |
+
<body class="bg-gray-100">
|
13 |
+
<!-- (Header + Chat Area + Input Area omitted for brevity) -->
|
14 |
+
<div id="chat-area" class="chat-container p-4 overflow-y-auto">
|
15 |
+
<div class="bot-message bg-gray-100 rounded-lg p-4 max-w-xs mb-3">
|
16 |
+
<p>Hello! 👋 Floor or wall tiles?</p>
|
17 |
+
<button onclick="selectTileType('floor')" class="quick-reply">Floor</button>
|
18 |
+
<button onclick="selectTileType('wall')" class="quick-reply">Wall</button>
|
19 |
+
</div>
|
20 |
+
</div>
|
21 |
+
<!-- Recommendations Section -->
|
22 |
+
<div id="recommendations" class="grid grid-cols-2 md:grid-cols-4 gap-4 p-4 border-t bg-gray-50"></div>
|
23 |
+
|
24 |
+
<script>
|
25 |
+
const state = { step: 'tileType', tileType: null, length: null, width: null };
|
26 |
+
const chatArea = document.getElementById('chat-area'),
|
27 |
+
userInput = null, /* we won't use user text input here for simplicity */,
|
28 |
+
recommendations = document.getElementById('recommendations');
|
29 |
+
|
30 |
+
function selectTileType(type){
|
31 |
+
state.tileType = type;
|
32 |
+
state.step = 'length';
|
33 |
+
appendBot(`Great. What's the length of the area in ft?`);
|
34 |
}
|
35 |
+
|
36 |
+
function appendBot(text) {
|
37 |
+
chatArea.insertAdjacentHTML('beforeend', `
|
38 |
+
<div class="bot-message bg-gray-100 rounded-lg p-4 mb-3">${text}</div>
|
39 |
+
`);
|
40 |
+
chatArea.scrollTop = chatArea.scrollHeight;
|
41 |
}
|
42 |
+
|
43 |
+
function appendUser(text) {
|
44 |
+
chatArea.insertAdjacentHTML('beforeend', `
|
45 |
+
<div class="user-message ml-auto bg-indigo-600 text-white rounded-lg p-4 mb-3">${text}</div>
|
46 |
+
`);
|
47 |
+
chatArea.scrollTop = chatArea.scrollHeight;
|
48 |
}
|
49 |
+
|
50 |
+
function askValue(val){
|
51 |
+
const answer = prompt(val);
|
52 |
+
if (!answer) return appendBot('Input canceled.');
|
53 |
+
appendUser(answer);
|
54 |
+
processValue(parseFloat(answer));
|
55 |
+
}
|
56 |
+
|
57 |
+
function processValue(num){
|
58 |
+
if (state.step === 'length'){
|
59 |
+
state.length = num;
|
60 |
+
state.step = 'width';
|
61 |
+
appendBot("And the width (ft)?");
|
62 |
+
askValue("Width in ft:");
|
63 |
+
} else if (state.step === 'width'){
|
64 |
+
state.width = num;
|
65 |
+
calculate();
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
function calculate(){
|
70 |
+
const area = state.length * state.width;
|
71 |
+
const coverage = 1; // tile covers 1 sq ft default
|
72 |
+
const numTiles = Math.ceil(area * 1.1 / coverage);
|
73 |
+
appendBot(`📐 Area: ${area.toFixed(2)} ft²<br>🧮 Tiles needed (incl. 10%): ${numTiles}`);
|
74 |
+
fetchRecommendations(coverage, area);
|
75 |
+
}
|
76 |
+
|
77 |
+
function fetchRecommendations(coverage, area){
|
78 |
+
fetch('/recommend', {
|
79 |
+
method: 'POST',
|
80 |
+
headers:{'Content-Type':'application/json'},
|
81 |
+
body: JSON.stringify({
|
82 |
+
tile_type: state.tileType,
|
83 |
+
coverage,
|
84 |
+
area,
|
85 |
+
price_range: [3,10]
|
86 |
+
})
|
87 |
})
|
88 |
+
.then(r=>r.json())
|
89 |
+
.then(d=> {
|
90 |
+
if (d.recommended_products?.length){
|
91 |
+
showProducts(d.recommended_products);
|
92 |
+
} else {
|
93 |
+
appendBot("No recommendations found for your specs.");
|
94 |
+
}
|
95 |
+
});
|
96 |
+
}
|
97 |
+
|
98 |
+
function showProducts(products){
|
99 |
+
recommendations.innerHTML = '';
|
100 |
+
products.forEach(p => {
|
101 |
+
recommendations.insertAdjacentHTML('beforeend', `
|
102 |
+
<div class="bg-white shadow rounded-lg p-4">
|
103 |
+
<h4 class="font-medium">${p.name}</h4>
|
104 |
+
<p class="text-sm">₹${p.price}/box</p>
|
105 |
+
<a href="${p.link}" target="_blank" class="text-indigo-600 hover:underline">View</a>
|
106 |
+
</div>
|
107 |
+
`);
|
108 |
+
});
|
109 |
+
}
|
110 |
+
|
111 |
+
// start logic: after selecting tile type, ask length
|
112 |
+
document.addEventListener('DOMContentLoaded', ()=> {
|
113 |
+
if(state.step!=='tileType') return;
|
114 |
+
document.querySelectorAll('.quick-reply').forEach(btn=>{
|
115 |
+
btn.onclick = ()=> {
|
116 |
+
const type = btn.getAttribute('onclick').match(/'(\w+)'/)[1];
|
117 |
+
appendUser(type);
|
118 |
+
selectTileType(type);
|
119 |
+
askValue("Length in ft:");
|
120 |
+
}
|
121 |
+
});
|
122 |
});
|
123 |
+
</script>
|
124 |
+
</body>
|
125 |
+
</html>
|