Gopikanth123 commited on
Commit
d419ce8
·
verified ·
1 Parent(s): d825801

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +94 -130
templates/index.html CHANGED
@@ -303,19 +303,7 @@
303
  <option value="soft-lavender">Soft Lavender</option>
304
  <option value="bright-summer">Bright Summer</option>
305
  </select>
306
- </div>
307
- <div class="language-toggle">
308
- <label for="language-select">Select Language:</label>
309
- <select id="language-select">
310
- <option value="en">English</option>
311
- <option value="es">Spanish</option>
312
- <option value="fr">French</option>
313
- <option value="de">German</option>
314
- <option value="hi">Hindi</option>
315
- <option value="zh">Chinese</option>
316
- <option value="ar">Arabic</option>
317
- </select>
318
- </div>
319
  <div class="color-picker">
320
  <label>Accent Color:</label>
321
  <div class="color-circle" style="background-color: #6a0dad;" onclick="changeColor('#6a0dad')"></div>
@@ -340,124 +328,100 @@
340
  </div>
341
 
342
  <script>
343
- const chatBox = document.getElementById('chat-box');
344
- const voiceBtn = document.getElementById('voice-btn');
345
- const sendBtn = document.getElementById('send-btn');
346
- const userInput = document.getElementById('user-input');
347
- const themeSelect = document.getElementById('theme-select');
348
-
349
- // Function to add messages to the chatbox
350
- function addMessage(sender, text) {
351
- const msgDiv = document.createElement('div');
352
- msgDiv.classList.add('message', sender);
353
- msgDiv.textContent = text;
354
- chatBox.appendChild(msgDiv);
355
- chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
356
- }
357
-
358
- // Speech Recognition Setup
359
- const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
360
- recognition.lang = 'en-US';
361
- recognition.interimResults = false; // Set to true for interim results
362
-
363
- // Start speech recognition when voice button is clicked
364
- voiceBtn.addEventListener('click', () => {
365
- recognition.start();
366
- });
367
-
368
- // Process the speech result
369
- recognition.addEventListener('result', (e) => {
370
- const transcript = e.results[0][0].transcript;
371
- addMessage('user-message', transcript);
372
- sendUserMessage(transcript);
373
- });
374
-
375
- // Handle cases when no result is found
376
- recognition.addEventListener('nomatch', () => {
377
- const message = 'No speech detected';
378
- addMessage('user-message', message);
379
- sendUserMessage(message);
380
- });
381
-
382
- // Handle speech recognition errors
383
- recognition.addEventListener('error', (e) => {
384
- console.error("Speech recognition error", e);
385
- const message = 'No speech detected';
386
- addMessage('user-message', message);
387
- sendUserMessage(message);
388
- });
389
-
390
- // Send user input to the backend
391
- function sendUserMessage(message) {
392
- fetch('/chat', {
393
- method: 'POST',
394
- headers: {
395
- 'Content-Type': 'application/json',
396
- },
397
- body: JSON.stringify({ message: message }),
398
- })
399
- .then(response => response.json())
400
- .then(data => {
401
- const botResponse = data.response;
402
- addMessage('bot-message', botResponse);
403
- speakResponse(botResponse);
404
  })
405
- .catch(error => {
406
- console.error("Error:", error);
407
- addMessage('bot-message', "Sorry, I couldn't process that.");
408
- });
409
- }
410
-
411
- // Text-to-Speech Function
412
- function speakResponse(text) {
413
- const utterance = new SpeechSynthesisUtterance(text);
414
- utterance.lang = 'en-US';
415
- window.speechSynthesis.speak(utterance);
416
- }
417
-
418
- // Event listeners for sending messages
419
- sendBtn.addEventListener('click', () => {
420
- const message = userInput.value.trim();
421
- if (message) {
422
- addMessage('user-message', message);
423
- sendUserMessage(message);
424
- userInput.value = ''; // Clear the input field after sending
425
- }
426
- });
427
-
428
- // Handle pressing 'Enter' key to send messages
429
- userInput.addEventListener('keypress', (e) => {
430
- if (e.key === 'Enter') {
431
- sendBtn.click(); // Trigger button click
432
- }
433
- });
434
-
435
- // Theme selection handling
436
- themeSelect.addEventListener('change', (e) => {
437
- changeTheme(e.target.value);
438
- });
439
-
440
- // Function to change the theme based on selection
441
- function changeTheme(theme) {
442
- document.documentElement.classList.remove('theme-calm-azure', 'theme-elegant-charcoal', 'theme-fresh-greenery', 'theme-soft-lavender', 'theme-bright-summer');
443
- if (theme !== 'default') {
444
- document.documentElement.classList.add('theme-' + theme);
445
- }
446
- }
447
-
448
- // Event listener for language selection, if integrated
449
- document.getElementById("language-select").addEventListener("change", function () {
450
- const selectedLanguage = this.value;
451
- console.log(`Language selected: ${selectedLanguage}`);
452
- updateBotLanguage(selectedLanguage); // Function to handle language updates
453
- });
454
-
455
- // Function to handle language-specific logic
456
- function updateBotLanguage(language) {
457
- alert(`Chatbot will now respond in: ${language.toUpperCase()}`);
458
- // You might want to integrate translation logic here.
459
- }
460
- </script>
461
  </body>
462
 
463
  </html>
 
303
  <option value="soft-lavender">Soft Lavender</option>
304
  <option value="bright-summer">Bright Summer</option>
305
  </select>
306
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
307
  <div class="color-picker">
308
  <label>Accent Color:</label>
309
  <div class="color-circle" style="background-color: #6a0dad;" onclick="changeColor('#6a0dad')"></div>
 
328
  </div>
329
 
330
  <script>
331
+ const chatBox = document.getElementById('chat-box');
332
+ const voiceBtn = document.getElementById('voice-btn');
333
+ const sendBtn = document.getElementById('send-btn');
334
+ const userInput = document.getElementById('user-input');
335
+ const themeSelect = document.getElementById('theme-select');
336
+
337
+ // Add message to chatbox with visual effects
338
+ function addMessage(sender, text) {
339
+ const msgDiv = document.createElement('div');
340
+ msgDiv.classList.add('message', sender);
341
+ msgDiv.textContent = text;
342
+ chatBox.appendChild(msgDiv);
343
+ chatBox.scrollTop = chatBox.scrollHeight;
344
+ }
345
+
346
+ // Speech Recognition Setup
347
+ const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
348
+ recognition.lang = 'en-US';
349
+
350
+ voiceBtn.addEventListener('click', () => recognition.start());
351
+
352
+ recognition.addEventListener('result', (e) => {
353
+ const transcript = e.results[0][0].transcript;
354
+ addMessage('user-message', transcript);
355
+ sendUserMessage(transcript);
356
+ });
357
+
358
+ // Function to change the accent color
359
+ function changeColor(color) {
360
+ document.documentElement.style.setProperty('--accent-color', color);
361
+ }
362
+
363
+ // Function to change the theme
364
+ function changeTheme(theme) {
365
+ document.documentElement.classList.remove('theme-calm-azure', 'theme-elegant-charcoal', 'theme-fresh-greenery', 'theme-soft-lavender', 'theme-bright-summer');
366
+ if (theme !== 'default') {
367
+ document.documentElement.classList.add('theme-' + theme);
368
+ }
369
+ }
370
+
371
+ // Send user input to backend (placeholder URL)
372
+ function sendUserMessage(message) {
373
+ fetch('/chat', {
374
+ method: 'POST',
375
+ headers: {
376
+ 'Content-Type': 'application/json',
377
+ },
378
+ body: JSON.stringify({ message: message }),
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  })
380
+ .then(response => response.json())
381
+ .then(data => {
382
+ const botResponse = data.response;
383
+ addMessage('bot-message', botResponse);
384
+ speakResponse(botResponse);
385
+ })
386
+ .catch(error => {
387
+ console.error("Error:", error);
388
+ addMessage('bot-message', "Sorry, I couldn't process that.");
389
+ });
390
+ }
391
+
392
+ // Text-to-Speech Function
393
+ function speakResponse(text) {
394
+ const utterance = new SpeechSynthesisUtterance(text);
395
+ utterance.lang = 'en-US';
396
+ window.speechSynthesis.speak(utterance);
397
+ }
398
+ // Event listeners for buttons
399
+ sendBtn.addEventListener('click', () => {
400
+ const message = userInput.value.trim();
401
+ if (message) {
402
+ addMessage('user-message', message);
403
+ sendUserMessage(message);
404
+ userInput.value = ''; // Clear input field after sending
405
+ }
406
+ });
407
+
408
+ // Handle pressing 'Enter' key for sending messages
409
+ userInput.addEventListener('keypress', (e) => {
410
+ if (e.key === 'Enter') {
411
+ sendBtn.click(); // Trigger button click
412
+ }
413
+ });
414
+
415
+ // Update theme when selected from dropdown
416
+ themeSelect.addEventListener('change', (e) => {
417
+ changeTheme(e.target.value);
418
+ });
419
+
420
+ recognition.addEventListener('error', (event) => {
421
+ console.error("Speech recognition error", event);
422
+ });
423
+
424
+ </script>
 
 
 
 
 
 
 
 
 
 
 
425
  </body>
426
 
427
  </html>