Spaces:
Sleeping
Sleeping
Gopikanth123
commited on
Update templates/index.html
Browse files- 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 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
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 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
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>
|