Subbu1304 commited on
Commit
79296ac
·
verified ·
1 Parent(s): 78ce5bd

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +200 -38
templates/index.html CHANGED
@@ -32,6 +32,9 @@
32
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
33
  display: none;
34
  }
 
 
 
35
  h2 {
36
  font-size: 24px;
37
  font-weight: bold;
@@ -66,6 +69,11 @@
66
  color: #ff6a00;
67
  font-weight: bold;
68
  }
 
 
 
 
 
69
  #confirmation {
70
  display: none;
71
  background-color: #f9f9f9;
@@ -88,87 +96,241 @@
88
  </head>
89
  <body>
90
  <h1 class="header-title">Welcome to Biryani Hub 🍽</h1>
 
 
91
  <div class="container" id="loginForm">
92
- <h2>Login</h2>
93
- <label for="loginEmail">Your Email</label>
94
- <input type="text" id="loginEmail" readonly>
 
95
 
96
- <label for="loginMobile">Your Mobile Number</label>
97
- <input type="text" id="loginMobile" readonly>
 
 
 
98
  </div>
 
 
99
  <div class="container" id="registrationForm">
100
- <h2>Register</h2>
101
- <label for="name">Your Name</label>
102
- <input type="text" id="name" readonly>
 
 
 
 
103
 
104
- <label for="email">Your Email</label>
105
- <input type="text" id="email" readonly>
106
 
107
- <label for="mobile">Your Mobile Number</label>
108
- <input type="text" id="mobile" readonly>
109
  </div>
 
 
110
  <div id="confirmation">
111
  <h2>Confirm Your Details:</h2>
112
  <p><strong>Name:</strong> <span id="confirmName"></span></p>
113
  <p><strong>Email:</strong> <span id="confirmEmail"></span></p>
114
  <p><strong>Phone:</strong> <span id="confirmPhone"></span></p>
115
- <button class="confirm-button" onclick="submitForm()">Confirm</button>
116
  </div>
 
117
  <script>
118
- let recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
119
- recognition.continuous = false;
120
- recognition.interimResults = false;
121
- recognition.lang = 'en-US';
 
 
 
 
 
122
 
123
  function speak(text, callback) {
124
- let speech = new SpeechSynthesisUtterance(text);
125
  speech.onend = callback;
126
  window.speechSynthesis.speak(speech);
127
  }
128
 
129
- function startListeningForEmail() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  recognition.start();
131
  recognition.onresult = function(event) {
132
- let email = event.results[0][0].transcript.trim();
133
- document.getElementById('email').value = email;
134
  recognition.stop();
135
- speak("You said " + email + ". Is it correct?", startListeningForMobile);
 
 
 
 
 
 
 
 
 
 
 
136
  };
137
  }
138
 
139
- function startListeningForMobile() {
140
  recognition.start();
141
  recognition.onresult = function(event) {
142
- let mobile = event.results[0][0].transcript.trim();
143
- document.getElementById('mobile').value = mobile;
144
  recognition.stop();
145
- speak("You said " + mobile + ". Is it correct?", confirmDetails);
 
 
 
 
 
 
 
 
 
 
 
146
  };
147
  }
148
 
149
- function confirmDetails() {
150
- document.getElementById('confirmName').innerText = document.getElementById('name').value;
151
- document.getElementById('confirmEmail').innerText = document.getElementById('email').value;
152
- document.getElementById('confirmPhone').innerText = document.getElementById('mobile').value;
153
- document.getElementById('confirmation').style.display = 'block';
 
 
 
154
  }
155
 
156
- function submitForm() {
157
- speak("Your details have been submitted. Welcome to Biryani Hub!");
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
 
160
- function startListeningForName() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  recognition.start();
162
  recognition.onresult = function(event) {
163
- let name = event.results[0][0].transcript.trim();
164
- document.getElementById('name').value = name;
165
  recognition.stop();
166
- speak("You said " + name + ". Is it correct?", startListeningForEmail);
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  };
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  window.onload = function () {
171
- speak("Please say your name.", startListeningForName);
172
  };
173
  </script>
174
  </body>
 
32
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
33
  display: none;
34
  }
35
+ .form-container {
36
+ width: 100%;
37
+ }
38
  h2 {
39
  font-size: 24px;
40
  font-weight: bold;
 
69
  color: #ff6a00;
70
  font-weight: bold;
71
  }
72
+ .status {
73
+ font-size: 14px;
74
+ color: gray;
75
+ margin-top: 10px;
76
+ }
77
  #confirmation {
78
  display: none;
79
  background-color: #f9f9f9;
 
96
  </head>
97
  <body>
98
  <h1 class="header-title">Welcome to Biryani Hub 🍽</h1>
99
+
100
+ <!-- Login Form -->
101
  <div class="container" id="loginForm">
102
+ <div class="form-container">
103
+ <h2>Login</h2>
104
+ <label for="loginEmail">Your Email</label>
105
+ <input type="text" id="loginEmail" placeholder="Your email will appear here..." readonly>
106
 
107
+ <label for="loginMobile">Your Mobile Number</label>
108
+ <input type="text" id="loginMobile" placeholder="Your mobile number will appear here..." readonly>
109
+
110
+ <p class="info" id="infoMessageLogin">Listening 🗣🎙️...</p>
111
+ </div>
112
  </div>
113
+
114
+ <!-- Registration Form -->
115
  <div class="container" id="registrationForm">
116
+ <div class="form-container">
117
+ <h2>Register</h2>
118
+ <label for="name">Your Name</label>
119
+ <input type="text" id="name" placeholder="Your name will appear here..." readonly>
120
+
121
+ <label for="email">Your Email</label>
122
+ <input type="text" id="email" placeholder="Your email will appear here..." readonly>
123
 
124
+ <label for="mobile">Your Mobile Number</label>
125
+ <input type="text" id="mobile" placeholder="Your mobile number will appear here..." readonly>
126
 
127
+ <p class="info" id="infoMessage">Listening 🗣🎙️...</p>
128
+ </div>
129
  </div>
130
+
131
+ <!-- Confirmation Section -->
132
  <div id="confirmation">
133
  <h2>Confirm Your Details:</h2>
134
  <p><strong>Name:</strong> <span id="confirmName"></span></p>
135
  <p><strong>Email:</strong> <span id="confirmEmail"></span></p>
136
  <p><strong>Phone:</strong> <span id="confirmPhone"></span></p>
137
+ <button class="confirm-button" onclick="autoSubmit()">Confirm</button>
138
  </div>
139
+
140
  <script>
141
+ let recognition;
142
+ if ('webkitSpeechRecognition' in window) {
143
+ recognition = new webkitSpeechRecognition();
144
+ recognition.continuous = false;
145
+ recognition.interimResults = false;
146
+ recognition.lang = 'en-US';
147
+ } else {
148
+ alert("Speech Recognition API is not supported in this browser.");
149
+ }
150
 
151
  function speak(text, callback) {
152
+ const speech = new SpeechSynthesisUtterance(text);
153
  speech.onend = callback;
154
  window.speechSynthesis.speak(speech);
155
  }
156
 
157
+ function askLoginOrRegister() {
158
+ speak("Welcome to Biryani Hub. Are you a new user or an existing user? Please say 'new user' to register or 'existing user' to login.", function() {
159
+ recognition.start();
160
+ recognition.onresult = function(event) {
161
+ let response = event.results[0][0].transcript.trim().toLowerCase();
162
+ recognition.stop();
163
+ if (response.includes("new user")) {
164
+ showRegistrationForm();
165
+ } else if (response.includes("existing user")) {
166
+ showLoginForm();
167
+ } else {
168
+ speak("I didn't understand. Please say 'new user' to register or 'existing user' to login.", askLoginOrRegister);
169
+ }
170
+ };
171
+ });
172
+ }
173
+
174
+ function showLoginForm() {
175
+ document.getElementById('loginForm').style.display = 'block';
176
+ document.getElementById('registrationForm').style.display = 'none';
177
+ speak("Please tell your email and mobile number to login.", startListeningForLogin);
178
+ }
179
+
180
+ function showRegistrationForm() {
181
+ document.getElementById('registrationForm').style.display = 'block';
182
+ document.getElementById('loginForm').style.display = 'none';
183
+ speak("Please say your name to begin registration.", startListeningForName);
184
+ }
185
+
186
+ let nameCaptured, emailCaptured, mobileCaptured;
187
+ let nameField = document.getElementById('name');
188
+ let emailField = document.getElementById('email');
189
+ let mobileField = document.getElementById('mobile');
190
+
191
+ function startListeningForLogin() {
192
  recognition.start();
193
  recognition.onresult = function(event) {
194
+ let loginEmail = event.results[0][0].transcript.trim();
195
+ document.getElementById('loginEmail').value = loginEmail;
196
  recognition.stop();
197
+ speak("You said " + loginEmail + ". Is it correct?", function() {
198
+ recognition.start();
199
+ recognition.onresult = function(event) {
200
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
201
+ recognition.stop();
202
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
203
+ startListeningForMobileLogin();
204
+ } else {
205
+ speak("Let's try again. Please tell your email.", startListeningForLogin);
206
+ }
207
+ };
208
+ });
209
  };
210
  }
211
 
212
+ function startListeningForMobileLogin() {
213
  recognition.start();
214
  recognition.onresult = function(event) {
215
+ let mobileLogin = event.results[0][0].transcript.trim();
216
+ document.getElementById('loginMobile').value = mobileLogin;
217
  recognition.stop();
218
+ speak("You said " + mobileLogin + ". Is it correct?", function() {
219
+ recognition.start();
220
+ recognition.onresult = function(event) {
221
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
222
+ recognition.stop();
223
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
224
+ speak("Login successful!");
225
+ } else {
226
+ speak("Let's try again. Please tell your mobile number.", startListeningForMobileLogin);
227
+ }
228
+ };
229
+ });
230
  };
231
  }
232
 
233
+ function startListeningForName() {
234
+ recognition.start();
235
+ recognition.onresult = function(event) {
236
+ nameCaptured = event.results[0][0].transcript.trim();
237
+ nameField.value = nameCaptured;
238
+ recognition.stop();
239
+ setTimeout(confirmName, 500);
240
+ };
241
  }
242
 
243
+ function confirmName() {
244
+ speak("You said " + nameCaptured + ". Is it okay?", function() {
245
+ recognition.start();
246
+ recognition.onresult = function(event) {
247
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
248
+ recognition.stop();
249
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
250
+ setTimeout(() => speak("Great! Now, tell me your email.", startListeningForEmail), 500);
251
+ } else {
252
+ setTimeout(() => speak("Let's try again. Tell me your name.", startListeningForName), 500);
253
+ }
254
+ };
255
+ });
256
  }
257
 
258
+ function startListeningForEmail() {
259
+ recognition.start();
260
+ recognition.onresult = function(event) {
261
+ emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
262
+ emailField.value = emailCaptured;
263
+ recognition.stop();
264
+ speak("You said " + emailCaptured + ". Is it correct?", function() {
265
+ recognition.start();
266
+ recognition.onresult = function(event) {
267
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
268
+ recognition.stop();
269
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
270
+ setTimeout(() => speak("Great! Now, tell me your mobile number.", startListeningForMobile), 500);
271
+ } else {
272
+ speak("Let's try again. Tell me your email.", startListeningForEmail);
273
+ }
274
+ };
275
+ });
276
+ };
277
+ }
278
+
279
+ function startListeningForMobile() {
280
  recognition.start();
281
  recognition.onresult = function(event) {
282
+ mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
283
+ mobileField.value = mobileCaptured;
284
  recognition.stop();
285
+ speak("You said " + mobileCaptured + ". Is it correct?", function() {
286
+ recognition.start();
287
+ recognition.onresult = function(event) {
288
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
289
+ recognition.stop();
290
+ if (confirmation.includes("ok") || confirmation.includes("yes")) {
291
+ speak("All details are captured. Confirming your registration.", function() {
292
+ autoConfirm();
293
+ });
294
+ } else {
295
+ speak("Let's try again. Tell me your mobile number.", startListeningForMobile);
296
+ }
297
+ };
298
+ });
299
  };
300
  }
301
 
302
+ function autoConfirm() {
303
+ document.getElementById('confirmName').textContent = nameField.value;
304
+ document.getElementById('confirmEmail').textContent = emailField.value;
305
+ document.getElementById('confirmPhone').textContent = mobileField.value;
306
+ document.getElementById('confirmation').style.display = 'block';
307
+ }
308
+
309
+ function autoSubmit() {
310
+ var name = document.getElementById('name').value;
311
+ var email = document.getElementById('email').value;
312
+ var phone = document.getElementById('mobile').value;
313
+ fetch('/submit', {
314
+ method: 'POST',
315
+ headers: { 'Content-Type': 'application/json' },
316
+ body: JSON.stringify({ name: name, email: email, phone: phone })
317
+ })
318
+ .then(response => response.json())
319
+ .then(data => {
320
+ if (data.success) {
321
+ document.getElementById('status').textContent = 'Your details were submitted successfully!';
322
+ document.getElementById('confirmation').style.display = 'none';
323
+ speak("Your registration is complete. Thank you for registering.");
324
+ setTimeout(() => location.reload(), 5000);
325
+ } else {
326
+ document.getElementById('status').textContent = 'There was an error submitting your details.';
327
+ speak("There was an error submitting your details. Please try again.");
328
+ }
329
+ });
330
+ }
331
+
332
  window.onload = function () {
333
+ askLoginOrRegister(); // First, ask the user whether they are a new or existing user
334
  };
335
  </script>
336
  </body>