Swathi6 commited on
Commit
21b7cba
·
verified ·
1 Parent(s): 08a8bb7

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +293 -0
templates/index.html ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Biryani Hub - Register & Login</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ font-family: 'Roboto', sans-serif;
11
+ background: linear-gradient(135deg, #f4c542, #ff8f6a);
12
+ margin: 0;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ height: 100vh;
17
+ text-align: center;
18
+ }
19
+ .container {
20
+ background-color: #fff;
21
+ padding: 40px 50px;
22
+ border-radius: 10px;
23
+ width: 500px;
24
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
25
+ }
26
+ h1 {
27
+ font-size: 24px;
28
+ color: #ff6a00;
29
+ }
30
+ h2 {
31
+ font-size: 15px;
32
+ color: #lemonchiffon;
33
+ }
34
+ label {
35
+ font-size: 16px;
36
+ display: block;
37
+ margin-top: 15px;
38
+ color: #333;
39
+ font-weight: bold;
40
+ }
41
+ input {
42
+ width: 100%;
43
+ padding: 12px;
44
+ font-size: 16px;
45
+ border: 2px solid #ccc;
46
+ border-radius: 8px;
47
+ margin-top: 5px;
48
+ background-color: #f9f9f9;
49
+ box-sizing: border-box;
50
+ }
51
+ input:focus {
52
+ border-color: #ff6a00;
53
+ outline: none;
54
+ }
55
+ .info {
56
+ font-size: 16px;
57
+ color: #ff6a00;
58
+ font-weight: bold;
59
+ margin-top: 10px;
60
+ }
61
+ .status {
62
+ font-size: 14px;
63
+ color: gray;
64
+ margin-top: 10px;
65
+ }
66
+ .confirm-button, .switch-button {
67
+ padding: 10px 20px;
68
+ background-color: #ff6a00;
69
+ color: white;
70
+ border: none;
71
+ border-radius: 5px;
72
+ cursor: pointer;
73
+ margin-top: 10px;
74
+ }
75
+ .confirm-button:hover, .switch-button:hover {
76
+ background-color: #e65e00;
77
+ }
78
+ </style>
79
+ </head>
80
+ <body>
81
+ <!-- Welcome Page -->
82
+ <div class="container" id="welcomePage">
83
+ <h1>Welcome to Biriyani Hub 🍽</h1>
84
+ <h2>🔊 Please say 'Hi Biryani Hub' to start.</h2>
85
+ </div>
86
+
87
+ <!-- Registration Form -->
88
+ <div class="container" id="registrationForm" style="display: none;">
89
+ <h2>Register</h2>
90
+ <label for="name">🧒🏻👧🏻Your Name🎙️</label>
91
+ <input type="text" id="name" placeholder="Listening for name..." readonly>
92
+
93
+ <label for="email">Ⓜ️Your Email🎙️</label>
94
+ <input type="text" id="email" placeholder="Listening for email..." readonly>
95
+
96
+ <label for="mobile">📱Your Mobile Number🎙️</label>
97
+ <input type="text" id="mobile" placeholder="Listening for mobile number..." readonly>
98
+
99
+ <p class="status" id="registrationStatus">Listening... 🗣</p>
100
+ </div>
101
+
102
+ <!-- Login Form -->
103
+ <div class="container" id="loginForm" style="display: none;">
104
+ <h2>Login</h2>
105
+ <label for="loginEmail">Ⓜ️Your Email🎙️</label>
106
+ <input type="text" id="loginEmail" placeholder="Listening for email..." readonly>
107
+
108
+ <label for="loginMobile">📱Your Mobile Number🎙️</label>
109
+ <input type="text" id="loginMobile" placeholder="Listening for mobile number..." readonly>
110
+
111
+ <p class="status" id="loginStatus">Listening... 🗣</p>
112
+ </div>
113
+
114
+ <script>
115
+ let recognition;
116
+ if ('webkitSpeechRecognition' in window) {
117
+ recognition = new webkitSpeechRecognition();
118
+ recognition.continuous = false; // Listen only when wake word is detected
119
+ recognition.interimResults = false; // Don't return partial results
120
+ recognition.lang = 'en-US';
121
+ } else {
122
+ alert("Speech Recognition API is not supported in this browser.");
123
+ }
124
+ // Start listening for wake word: "Hi Biryani Hub"
125
+ function listenForGreeting() {
126
+ recognition.start();
127
+ recognition.onresult = function (event) {
128
+ let response = event.results[0][0].transcript.trim().toLowerCase();
129
+ recognition.stop();
130
+ if (response.includes("hi biryani hub")) {
131
+ speak("How can I assist you today?", function () {
132
+ askLoginOrRegister(); // Proceed to ask whether they are new or existing
133
+ });
134
+ } else {
135
+ speak("I didn't hear 'Hi Biryani Hub'. Please say it again to proceed.", listenForGreeting);
136
+ }
137
+ };
138
+ }
139
+ function speak(text, callback) {
140
+ const speech = new SpeechSynthesisUtterance(text);
141
+ speech.onend = callback;
142
+ window.speechSynthesis.speak(speech);
143
+ }
144
+ // Ask user if they are a new or existing customer
145
+ function askLoginOrRegister() {
146
+ speak("Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
147
+ recognition.start();
148
+ recognition.onresult = function (event) {
149
+ let response = event.results[0][0].transcript.trim().toLowerCase();
150
+ recognition.stop();
151
+ if (response.includes("new")) {
152
+ showRegistrationForm();
153
+ captureName();
154
+ } else if (response.includes("existing")) {
155
+ showLoginForm();
156
+ captureLoginDetails();
157
+ } else {
158
+ speak("I didn't understand. Please say 'new' for registration or 'existing' for login.", askLoginOrRegister);
159
+ }
160
+ };
161
+ });
162
+ }
163
+ function showRegistrationForm() {
164
+ document.getElementById('welcomePage').style.display = 'none';
165
+ document.getElementById('registrationForm').style.display = 'block';
166
+ document.getElementById('loginForm').style.display = 'none';
167
+ }
168
+ function showLoginForm() {
169
+ document.getElementById('welcomePage').style.display = 'none';
170
+ document.getElementById('registrationForm').style.display = 'none';
171
+ document.getElementById('loginForm').style.display = 'block';
172
+ }
173
+ // Capture name for registration
174
+ function captureName() {
175
+ speak("Please say your name.", function () {
176
+ recognition.start();
177
+ recognition.onresult = function (event) {
178
+ let nameCaptured = event.results[0][0].transcript.trim();
179
+ document.getElementById('name').value = nameCaptured;
180
+ recognition.stop();
181
+ speak("You said " + nameCaptured + ". Is it correct?", function () {
182
+ confirmName(nameCaptured);
183
+ });
184
+ };
185
+ });
186
+ }
187
+ function confirmName(nameCaptured) {
188
+ recognition.start();
189
+ recognition.onresult = function (event) {
190
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
191
+ recognition.stop();
192
+ if (isConfirmation(confirmation)) {
193
+ captureEmail();
194
+ } else {
195
+ captureName();
196
+ }
197
+ };
198
+ }
199
+ // Capture email for registration
200
+ function captureEmail() {
201
+ speak("Now, say your email.", function () {
202
+ recognition.start();
203
+ recognition.onresult = function (event) {
204
+ let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
205
+ document.getElementById('email').value = emailCaptured;
206
+ recognition.stop();
207
+ speak("You said " + emailCaptured + ". Is it correct?", function () {
208
+ confirmEmail(emailCaptured);
209
+ });
210
+ };
211
+ });
212
+ }
213
+ function confirmEmail(emailCaptured) {
214
+ recognition.start();
215
+ recognition.onresult = function (event) {
216
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
217
+ recognition.stop();
218
+ if (isConfirmation(confirmation)) {
219
+ captureMobile();
220
+ } else {
221
+ captureEmail();
222
+ }
223
+ };
224
+ }
225
+ // Capture mobile number for registration
226
+ function captureMobile() {
227
+ speak("Now, say your mobile number.", function () {
228
+ recognition.start();
229
+ recognition.onresult = function (event) {
230
+ let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
231
+ document.getElementById('mobile').value = mobileCaptured;
232
+ recognition.stop();
233
+ speak("You said " + mobileCaptured + ". Is it correct?", function () {
234
+ confirmMobile(mobileCaptured);
235
+ });
236
+ };
237
+ });
238
+ }
239
+ function confirmMobile(mobileCaptured) {
240
+ recognition.start();
241
+ recognition.onresult = function (event) {
242
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
243
+ recognition.stop();
244
+ if (isConfirmation(confirmation)) {
245
+ submitRegistration();
246
+ } else {
247
+ captureMobile();
248
+ }
249
+ };
250
+ }
251
+ // Confirmation check for 'yes', 'ok', etc.
252
+ function isConfirmation(confirmation) {
253
+ const validResponses = ["yes", "ok", "yeah", "correct", "yep"];
254
+ return validResponses.some(response => confirmation.includes(response));
255
+ }
256
+ function submitRegistration() {
257
+ const name = document.getElementById('name').value.trim();
258
+ const email = document.getElementById('email').value.trim();
259
+ const phone = document.getElementById('mobile').value.trim();
260
+ if (!name || !email || !phone) {
261
+ alert("Please provide all required details.");
262
+ return;
263
+ }
264
+ console.log("Sending data:", { name, email, phone });
265
+ fetch('/submit', {
266
+ method: 'POST',
267
+ headers: { 'Content-Type': 'application/json' },
268
+ body: JSON.stringify({ name, email, phone })
269
+ })
270
+ .then(response => response.json())
271
+ .then(data => {
272
+ console.log("Response Data:", data);
273
+ if (data.success) {
274
+ speak(`Thank you for registering, ${name}!`);
275
+ setTimeout(() => {
276
+ location.reload(); // Refresh the page after registration
277
+ }, 6000); // 6 seconds delay before refresh
278
+ } else {
279
+ speak("There was an error submitting your details. Please try again.");
280
+ }
281
+ })
282
+ .catch(error => {
283
+ console.error("Fetch Error:", error);
284
+ speak("An error occurred. Please try again.");
285
+ });
286
+ }
287
+ // Start listening for the wake word as soon as the page is loaded
288
+ window.onload = function () {
289
+ listenForGreeting(); // Start listening for "Hi Biryani Hub"
290
+ };
291
+ </script>
292
+ </body>
293
+ </html>