Spaces:
Runtime error
Runtime error
Gopikanth123
commited on
Update templates/index.html
Browse files- templates/index.html +40 -25
templates/index.html
CHANGED
@@ -313,7 +313,7 @@
|
|
313 |
</div>
|
314 |
</div>
|
315 |
|
316 |
-
<!-- Header
|
317 |
<div class="header">TAJ HOTEL CHATBOT</div>
|
318 |
|
319 |
<!-- Chatbox -->
|
@@ -321,10 +321,18 @@
|
|
321 |
|
322 |
<!-- Footer -->
|
323 |
<div class="footer">
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
</div>
|
329 |
|
330 |
<script>
|
@@ -333,6 +341,7 @@
|
|
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) {
|
@@ -368,26 +377,32 @@
|
|
368 |
}
|
369 |
}
|
370 |
|
371 |
-
//
|
372 |
-
function sendUserMessage(message) {
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
.
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
// Text-to-Speech Function
|
393 |
function speakResponse(text) {
|
|
|
313 |
</div>
|
314 |
</div>
|
315 |
|
316 |
+
<!-- Header -->
|
317 |
<div class="header">TAJ HOTEL CHATBOT</div>
|
318 |
|
319 |
<!-- Chatbox -->
|
|
|
321 |
|
322 |
<!-- Footer -->
|
323 |
<div class="footer">
|
324 |
+
<input type="text" id="user-input" placeholder="Type your message..." />
|
325 |
+
<button id="send-btn">Send</button>
|
326 |
+
<button id="voice-btn">🎤 Start Voice Input</button>
|
327 |
+
|
328 |
+
<!-- Language dropdown -->
|
329 |
+
<select id="language-select">
|
330 |
+
<option value="english" selected>English</option>
|
331 |
+
<option value="telugu">Telugu</option>
|
332 |
+
<option value="hindi">Hindi</option>
|
333 |
+
</select>
|
334 |
+
</div>
|
335 |
+
|
336 |
</div>
|
337 |
|
338 |
<script>
|
|
|
341 |
const sendBtn = document.getElementById('send-btn');
|
342 |
const userInput = document.getElementById('user-input');
|
343 |
const themeSelect = document.getElementById('theme-select');
|
344 |
+
const languageSelect = document.getElementById('language-select');
|
345 |
|
346 |
// Add message to chatbox with visual effects
|
347 |
function addMessage(sender, text) {
|
|
|
377 |
}
|
378 |
}
|
379 |
|
380 |
+
// Function to send user input and selected language to backend
|
381 |
+
function sendUserMessage(message) {
|
382 |
+
const selectedLanguage = languageSelect.value; // Get the selected language
|
383 |
+
|
384 |
+
// Send the message and selected language to the backend
|
385 |
+
fetch('/chat', {
|
386 |
+
method: 'POST',
|
387 |
+
headers: {
|
388 |
+
'Content-Type': 'application/json',
|
389 |
+
},
|
390 |
+
body: JSON.stringify({
|
391 |
+
message: message,
|
392 |
+
language: selectedLanguage, // Include the selected language in the request body
|
393 |
+
}),
|
394 |
+
})
|
395 |
+
.then(response => response.json())
|
396 |
+
.then(data => {
|
397 |
+
const botResponse = data.response;
|
398 |
+
addMessage('bot-message', botResponse);
|
399 |
+
speakResponse(botResponse);
|
400 |
+
})
|
401 |
+
.catch(error => {
|
402 |
+
console.error("Error:", error);
|
403 |
+
addMessage('bot-message', "Sorry, I couldn't process that.");
|
404 |
+
});
|
405 |
+
}
|
406 |
|
407 |
// Text-to-Speech Function
|
408 |
function speakResponse(text) {
|