Subbu1304 commited on
Commit
148fa44
·
verified ·
1 Parent(s): e0f5c7b

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +35 -190
templates/index.html CHANGED
@@ -32,9 +32,6 @@
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,11 +66,6 @@
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,68 +88,46 @@
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
- let emailCaptured = "";
143
- let mobileCaptured = "";
144
- if ('webkitSpeechRecognition' in window) {
145
- recognition = new webkitSpeechRecognition();
146
- recognition.continuous = false;
147
- recognition.interimResults = false;
148
- recognition.lang = 'en-US';
149
- } else {
150
- alert("Speech Recognition API is not supported in this browser.");
151
- }
152
 
153
  function speak(text, callback) {
154
- const speech = new SpeechSynthesisUtterance(text);
155
  speech.onend = callback;
156
  window.speechSynthesis.speak(speech);
157
  }
158
 
159
  function askLoginOrRegister() {
160
- 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() {
161
  recognition.start();
162
  recognition.onresult = function(event) {
163
  let response = event.results[0][0].transcript.trim().toLowerCase();
@@ -167,7 +137,7 @@
167
  } else if (response.includes("existing user")) {
168
  showLoginForm();
169
  } else {
170
- speak("I didn't understand. Please say 'new user' to register or 'existing user' to login.", askLoginOrRegister);
171
  }
172
  };
173
  });
@@ -175,169 +145,44 @@
175
 
176
  function showLoginForm() {
177
  document.getElementById('loginForm').style.display = 'block';
178
- document.getElementById('registrationForm').style.display = 'none';
179
- speak("Please tell your email and mobile number to login.", startListeningForLogin);
180
  }
181
 
182
  function showRegistrationForm() {
183
  document.getElementById('registrationForm').style.display = 'block';
184
- document.getElementById('loginForm').style.display = 'none';
185
- speak("Please say your name to begin registration.", startListeningForName);
186
- }
187
-
188
- let nameCaptured, emailCaptured, mobileCaptured;
189
- let nameField = document.getElementById('name');
190
- let emailField = document.getElementById('email');
191
- let mobileField = document.getElementById('mobile');
192
-
193
- function startListeningForLogin() {
194
- recognition.start();
195
- recognition.onresult = function(event) {
196
- let loginEmail = event.results[0][0].transcript.trim();
197
- document.getElementById('loginEmail').value = loginEmail;
198
- recognition.stop();
199
- loginEmail = loginEmail.replace(/\bat\b/g, "@").replace(/\s+/g, ''); // Fix "at" to "@"
200
- document.getElementById('loginEmail').value = loginEmail;
201
-
202
- speak("You said " + loginEmail + ". Is it correct?", function() {
203
- recognition.start();
204
- recognition.onresult = function(event) {
205
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
206
- recognition.stop();
207
- if (confirmation.includes("ok") || confirmation.includes("yes")) {
208
- startListeningForMobileLogin(); // Move to mobile number
209
- } else {
210
- speak("Let's try again. Please tell your email.", startListeningForLogin);
211
- }
212
- };
213
- });
214
- };
215
- }
216
-
217
- function startListeningForMobileLogin() {
218
- recognition.start();
219
- recognition.onresult = function(event) {
220
- let mobileLogin = event.results[0][0].transcript.trim();
221
- document.getElementById('loginMobile').value = mobileLogin;
222
- recognition.stop();
223
- speak("You said " + mobileLogin + ". Is it correct?", function() {
224
- recognition.start();
225
- recognition.onresult = function(event) {
226
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
227
- recognition.stop();
228
- if (confirmation.includes("ok") || confirmation.includes("yes")) {
229
- speak("Login successful!");
230
- } else {
231
- speak("Let's try again. Please tell your mobile number.", startListeningForMobileLogin);
232
- }
233
- };
234
- });
235
- };
236
  }
237
 
238
  function startListeningForName() {
239
  recognition.start();
240
  recognition.onresult = function(event) {
241
- nameCaptured = event.results[0][0].transcript.trim();
242
- nameField.value = nameCaptured;
243
  recognition.stop();
244
- setTimeout(confirmName, 500);
245
  };
246
  }
247
 
248
  function confirmName() {
249
- speak("You said " + nameCaptured + ". Is it okay?", function() {
250
- recognition.start();
251
- recognition.onresult = function(event) {
252
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
253
- recognition.stop();
254
- if (confirmation.includes("ok") || confirmation.includes("yes")) {
255
- setTimeout(() => speak("Great! Now, tell me your email.", startListeningForEmail), 500);
256
- } else {
257
- setTimeout(() => speak("Let's try again. Tell me your name.", startListeningForName), 500);
258
- }
259
- };
260
- });
261
- }
262
-
263
- function startListeningForEmail() {
264
- recognition.start();
265
- recognition.onresult = function(event) {
266
- emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
267
- emailField.value = emailCaptured;
268
- recognition.stop();
269
- speak("You said " + emailCaptured + ". Is it correct?", function() {
270
- recognition.start();
271
- recognition.onresult = function(event) {
272
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
273
- recognition.stop();
274
- if (confirmation.includes("ok") || confirmation.includes("yes")) {
275
- setTimeout(() => speak("Great! Now, tell me your mobile number.", startListeningForMobile), 500);
276
- } else {
277
- speak("Let's try again. Tell me your email.", startListeningForEmail);
278
- }
279
- };
280
- });
281
- };
282
- }
283
-
284
- function startListeningForMobile() {
285
  recognition.start();
286
  recognition.onresult = function(event) {
287
- mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
288
- mobileField.value = mobileCaptured;
289
  recognition.stop();
290
- speak("You said " + mobileCaptured + ". Is it correct?", function() {
291
- recognition.start();
292
- recognition.onresult = function(event) {
293
- let confirmation = event.results[0][0].transcript.trim().toLowerCase();
294
- recognition.stop();
295
- if (confirmation.includes("ok") || confirmation.includes("yes")) {
296
- speak("All details are captured. Confirming your registration.", function() {
297
- autoConfirm();
298
- });
299
- } else {
300
- speak("Let's try again. Tell me your mobile number.", startListeningForMobile);
301
- }
302
- };
303
- });
304
  };
305
  }
306
 
307
- function autoConfirm() {
308
- document.getElementById('confirmName').textContent = nameField.value;
309
- document.getElementById('confirmEmail').textContent = emailField.value;
310
- document.getElementById('confirmPhone').textContent = mobileField.value;
311
- document.getElementById('confirmation').style.display = 'block';
312
  }
313
 
314
- function autoSubmit() {
315
- var name = document.getElementById('name').value;
316
- var email = document.getElementById('email').value;
317
- var phone = document.getElementById('mobile').value;
318
- fetch('/submit', {
319
- method: 'POST',
320
- headers: { 'Content-Type': 'application/json' },
321
- body: JSON.stringify({ name: name, email: email, phone: phone })
322
- })
323
- .then(response => response.json())
324
- .then(data => {
325
- if (data.success) {
326
- document.getElementById('status').textContent = 'Your details were submitted successfully!';
327
- document.getElementById('confirmation').style.display = 'none';
328
- speak("Your registration is complete. Thank you for registering.");
329
- setTimeout(() => location.reload(), 5000);
330
- } else {
331
- document.getElementById('status').textContent = 'There was an error submitting your details.';
332
- speak("There was an error submitting your details. Please try again.");
333
- }
334
- });
335
- }
336
-
337
- window.onload = function () {
338
- askLoginOrRegister(); // First, ask the user whether they are a new or existing user
339
- };
340
  </script>
341
  </body>
342
  </html>
343
 
 
 
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
  color: #ff6a00;
67
  font-weight: bold;
68
  }
 
 
 
 
 
69
  #confirmation {
70
  display: none;
71
  background-color: #f9f9f9;
 
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 askLoginOrRegister() {
130
+ speak("Welcome to Biryani Hub. Are you a new user or an existing user?", function() {
131
  recognition.start();
132
  recognition.onresult = function(event) {
133
  let response = event.results[0][0].transcript.trim().toLowerCase();
 
137
  } else if (response.includes("existing user")) {
138
  showLoginForm();
139
  } else {
140
+ speak("Please say 'new user' or 'existing user'.", askLoginOrRegister);
141
  }
142
  };
143
  });
 
145
 
146
  function showLoginForm() {
147
  document.getElementById('loginForm').style.display = 'block';
148
+ speak("Please say your email.", startListeningForEmail);
 
149
  }
150
 
151
  function showRegistrationForm() {
152
  document.getElementById('registrationForm').style.display = 'block';
153
+ speak("Please say your name.", startListeningForName);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
  function startListeningForName() {
157
  recognition.start();
158
  recognition.onresult = function(event) {
159
+ let name = event.results[0][0].transcript.trim();
160
+ document.getElementById('name').value = name;
161
  recognition.stop();
162
+ speak("You said " + name + ". Is it correct?", confirmName);
163
  };
164
  }
165
 
166
  function confirmName() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  recognition.start();
168
  recognition.onresult = function(event) {
169
+ let confirmation = event.results[0][0].transcript.trim().toLowerCase();
 
170
  recognition.stop();
171
+ if (confirmation.includes("yes")) {
172
+ speak("Great! Now, say your email.", startListeningForEmail);
173
+ } else {
174
+ speak("Let's try again. Please say your name.", startListeningForName);
175
+ }
 
 
 
 
 
 
 
 
 
176
  };
177
  }
178
 
179
+ function submitForm() {
180
+ speak("Your details have been submitted. Welcome to Biryani Hub!");
 
 
 
181
  }
182
 
183
+ window.onload = askLoginOrRegister;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  </script>
185
  </body>
186
  </html>
187
 
188
+