lokesh341 commited on
Commit
21e0e48
·
verified ·
1 Parent(s): 96f1a3c

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +156 -92
templates/index.html CHANGED
@@ -4,20 +4,110 @@
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Biryani Hub - Voice Login & Register</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  <script>
9
  let recognition;
10
- let nameCaptured = "";
11
- let emailCaptured = "";
12
- let mobileCaptured = "";
13
-
14
  if ('webkitSpeechRecognition' in window) {
15
  recognition = new webkitSpeechRecognition();
16
  recognition.continuous = false;
17
  recognition.interimResults = false;
18
  recognition.lang = 'en-US';
19
  } else {
20
- alert("Speech Recognition API not supported in this browser.");
21
  }
22
 
23
  function speak(text, callback) {
@@ -26,138 +116,112 @@
26
  window.speechSynthesis.speak(speech);
27
  }
28
 
 
 
 
 
29
  function askLoginOrRegister() {
30
- speak("Are you a new customer or an existing customer?", function() {
31
  recognition.start();
32
- recognition.onresult = function(event) {
33
  let response = event.results[0][0].transcript.trim().toLowerCase();
34
  recognition.stop();
35
  if (response.includes("new")) {
36
- checkIfUserExists();
37
  } else if (response.includes("existing")) {
38
- showLoginForm();
39
  } else {
40
- speak("Please say 'new' for registration or 'existing' for login.", askLoginOrRegister);
41
  }
42
  };
43
  });
44
  }
45
 
46
- function checkIfUserExists() {
47
- var email = document.getElementById('email').value;
48
- var phone = document.getElementById('mobile').value;
49
-
50
- fetch('/login', {
51
- method: 'POST',
52
- headers: { 'Content-Type': 'application/json' },
53
- body: JSON.stringify({ email: email, phone_number: phone })
54
- })
55
- .then(response => response.json())
56
- .then(data => {
57
- if (data.success) {
58
- speak("You are already registered. Logging you in now.");
59
- autoLoginSubmit();
60
- } else {
61
- speak("Please provide your details for registration.");
62
- showRegistrationForm();
63
- }
64
  });
65
  }
66
 
67
- function showRegistrationForm() {
68
- speak("Please tell me your name.", startListeningForName);
69
- }
70
-
71
- function startListeningForName() {
72
  recognition.start();
73
- recognition.onresult = function(event) {
74
- nameCaptured = event.results[0][0].transcript.trim();
75
- document.getElementById('name').value = nameCaptured;
76
- recognition.stop();
77
- speak("You said " + nameCaptured + ". Is it correct?", confirmName);
78
- };
79
- }
80
-
81
- function confirmName() {
82
- recognition.start();
83
- recognition.onresult = function(event) {
84
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
85
  recognition.stop();
86
- if (confirmation.includes("ok")) {
87
- speak("Now, tell me your email.", startListeningForEmail);
88
  } else {
89
- speak("Let's try again. Tell me your name.", startListeningForName);
90
  }
91
  };
92
  }
93
 
94
- function startListeningForEmail() {
95
- recognition.start();
96
- recognition.onresult = function(event) {
97
- emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
98
- document.getElementById('email').value = emailCaptured;
99
- recognition.stop();
100
- speak("You said " + emailCaptured + ". Is it correct?", confirmEmail);
101
- };
 
 
 
 
102
  }
103
 
104
- function confirmEmail() {
105
  recognition.start();
106
- recognition.onresult = function(event) {
107
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
108
  recognition.stop();
109
- if (confirmation.includes("ok")) {
110
- speak("Now, tell me your mobile number.", startListeningForMobile);
111
  } else {
112
- speak("Let's try again. Tell me your email.", startListeningForEmail);
113
  }
114
  };
115
  }
116
 
117
- function startListeningForMobile() {
118
- recognition.start();
119
- recognition.onresult = function(event) {
120
- mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
121
- document.getElementById('mobile').value = mobileCaptured;
122
- recognition.stop();
123
- speak("You said " + mobileCaptured + ". Is it correct?", confirmMobile);
124
- };
 
 
 
 
125
  }
126
 
127
- function confirmMobile() {
128
  recognition.start();
129
- recognition.onresult = function(event) {
130
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
131
  recognition.stop();
132
- if (confirmation.includes("ok")) {
133
- autoSubmit();
 
134
  } else {
135
- speak("Let's try again. Tell me your mobile number.", startListeningForMobile);
136
  }
137
  };
138
  }
139
 
140
- function autoSubmit() {
141
- fetch('/submit', {
142
- method: 'POST',
143
- headers: { 'Content-Type': 'application/json' },
144
- body: JSON.stringify({ name: nameCaptured, email: emailCaptured, phone: mobileCaptured })
145
- })
146
- .then(response => response.json())
147
- .then(data => {
148
- if (data.success) {
149
- speak("Registration complete. Thank you!");
150
- } else {
151
- speak(data.message);
152
- }
153
- });
154
- }
155
-
156
  window.onload = function () {
157
  askLoginOrRegister();
158
  };
159
  </script>
160
- </head>
161
- <body>
162
  </body>
163
  </html>
 
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Biryani Hub - Register & Login</title>
8
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ font-family: 'Roboto', sans-serif;
12
+ background: linear-gradient(135deg, #f4c542, #ff8f6a);
13
+ margin: 0;
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ height: 100vh;
18
+ text-align: center;
19
+ }
20
+ .container {
21
+ background-color: #fff;
22
+ padding: 40px 50px;
23
+ border-radius: 10px;
24
+ width: 500px;
25
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
26
+ display: flex;
27
+ justify-content: space-between;
28
+ }
29
+ .form-container {
30
+ width: 100%;
31
+ }
32
+ h1 {
33
+ font-size: 24px;
34
+ color: #ff6a00;
35
+ }
36
+ label {
37
+ font-size: 16px;
38
+ display: block;
39
+ margin-top: 15px;
40
+ color: #333;
41
+ font-weight: bold;
42
+ }
43
+ input {
44
+ width: 100%;
45
+ padding: 12px;
46
+ font-size: 16px;
47
+ border: 2px solid #ccc;
48
+ border-radius: 8px;
49
+ margin-top: 5px;
50
+ background-color: #f9f9f9;
51
+ box-sizing: border-box;
52
+ }
53
+ input:focus {
54
+ border-color: #ff6a00;
55
+ outline: none;
56
+ }
57
+ .info {
58
+ font-size: 16px;
59
+ color: #ff6a00;
60
+ font-weight: bold;
61
+ margin-top: 10px;
62
+ }
63
+ .status {
64
+ font-size: 14px;
65
+ color: gray;
66
+ margin-top: 10px;
67
+ }
68
+ .confirm-button {
69
+ padding: 10px 20px;
70
+ background-color: #ff6a00;
71
+ color: white;
72
+ border: none;
73
+ border-radius: 5px;
74
+ cursor: pointer;
75
+ margin-top: 10px;
76
+ }
77
+ .confirm-button:hover {
78
+ background-color: #e65e00;
79
+ }
80
+ </style>
81
+ </head>
82
+ <body>
83
+ <div class="container">
84
+ <div class="form-container" id="registrationForm">
85
+ <h1>Welcome to Biryani Hub 🍽</h1>
86
+ <h2 class="info" id="infoMessage">Listening... 🗣🎙</h2>
87
+ <p class="status" id="status">🔊 Speak Now...</p>
88
+
89
+ <label for="name">Your Name</label>
90
+ <input type="text" id="name" placeholder="Listening for name..." readonly>
91
+
92
+ <label for="email">Your Email</label>
93
+ <input type="text" id="email" placeholder="Listening for email..." readonly>
94
+
95
+ <label for="mobile">Your Mobile Number</label>
96
+ <input type="text" id="mobile" placeholder="Listening for mobile number..." readonly>
97
+
98
+ <button class="confirm-button" onclick="startVoiceRecognition()">Restart Voice Input</button>
99
+ </div>
100
+ </div>
101
+
102
  <script>
103
  let recognition;
 
 
 
 
104
  if ('webkitSpeechRecognition' in window) {
105
  recognition = new webkitSpeechRecognition();
106
  recognition.continuous = false;
107
  recognition.interimResults = false;
108
  recognition.lang = 'en-US';
109
  } else {
110
+ alert("Speech Recognition API is not supported in this browser.");
111
  }
112
 
113
  function speak(text, callback) {
 
116
  window.speechSynthesis.speak(speech);
117
  }
118
 
119
+ function startVoiceRecognition() {
120
+ askLoginOrRegister();
121
+ }
122
+
123
  function askLoginOrRegister() {
124
+ speak("Are you a new customer or an existing customer? Say 'new' to register or 'existing' to login.", function () {
125
  recognition.start();
126
+ recognition.onresult = function (event) {
127
  let response = event.results[0][0].transcript.trim().toLowerCase();
128
  recognition.stop();
129
  if (response.includes("new")) {
130
+ captureName();
131
  } else if (response.includes("existing")) {
132
+ speak("Login is currently unavailable. Please register first.");
133
  } else {
134
+ speak("I didn't understand. Please say 'new' for registration.", askLoginOrRegister);
135
  }
136
  };
137
  });
138
  }
139
 
140
+ function captureName() {
141
+ speak("Please say your name.", function () {
142
+ recognition.start();
143
+ recognition.onresult = function (event) {
144
+ let nameCaptured = event.results[0][0].transcript.trim();
145
+ document.getElementById('name').value = nameCaptured;
146
+ recognition.stop();
147
+ speak("You said " + nameCaptured + ". Is it correct?", function () {
148
+ confirmName(nameCaptured);
149
+ });
150
+ };
 
 
 
 
 
 
 
151
  });
152
  }
153
 
154
+ function confirmName(nameCaptured) {
 
 
 
 
155
  recognition.start();
156
+ recognition.onresult = function (event) {
 
 
 
 
 
 
 
 
 
 
157
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
158
  recognition.stop();
159
+ if (confirmation.includes("yes") || confirmation.includes("ok")) {
160
+ captureEmail();
161
  } else {
162
+ captureName();
163
  }
164
  };
165
  }
166
 
167
+ function captureEmail() {
168
+ speak("Now, say your email.", function () {
169
+ recognition.start();
170
+ recognition.onresult = function (event) {
171
+ let emailCaptured = event.results[0][0].transcript.trim().replace(/\bat\b/g, '@').replace(/\s+/g, '');
172
+ document.getElementById('email').value = emailCaptured;
173
+ recognition.stop();
174
+ speak("You said " + emailCaptured + ". Is it correct?", function () {
175
+ confirmEmail(emailCaptured);
176
+ });
177
+ };
178
+ });
179
  }
180
 
181
+ function confirmEmail(emailCaptured) {
182
  recognition.start();
183
+ recognition.onresult = function (event) {
184
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
185
  recognition.stop();
186
+ if (confirmation.includes("yes") || confirmation.includes("ok")) {
187
+ captureMobile();
188
  } else {
189
+ captureEmail();
190
  }
191
  };
192
  }
193
 
194
+ function captureMobile() {
195
+ speak("Now, say your mobile number.", function () {
196
+ recognition.start();
197
+ recognition.onresult = function (event) {
198
+ let mobileCaptured = event.results[0][0].transcript.trim().replace(/\s+/g, '');
199
+ document.getElementById('mobile').value = mobileCaptured;
200
+ recognition.stop();
201
+ speak("You said " + mobileCaptured + ". Is it correct?", function () {
202
+ confirmMobile(mobileCaptured);
203
+ });
204
+ };
205
+ });
206
  }
207
 
208
+ function confirmMobile(mobileCaptured) {
209
  recognition.start();
210
+ recognition.onresult = function (event) {
211
  let confirmation = event.results[0][0].transcript.trim().toLowerCase();
212
  recognition.stop();
213
+ if (confirmation.includes("yes") || confirmation.includes("ok")) {
214
+ speak("Your details are confirmed. Registration complete!");
215
+ setTimeout(() => location.reload(), 5000);
216
  } else {
217
+ captureMobile();
218
  }
219
  };
220
  }
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  window.onload = function () {
223
  askLoginOrRegister();
224
  };
225
  </script>
 
 
226
  </body>
227
  </html>