hotelvoicechat / static /script.js
prasanth345's picture
Create script.js
4a17e5d verified
document.addEventListener('DOMContentLoaded', () => {
const chatHistory = document.getElementById('chat-history');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
const voiceChatButton = document.getElementById('voice-chat');
// Function to update chat history
function updateChatHistory(message) {
const messageDiv = document.createElement('div');
messageDiv.textContent = message;
chatHistory.appendChild(messageDiv);
}
// Handle sending messages
sendButton.addEventListener('click', async () => {
const input = userInput.value.trim();
if (input) {
updateChatHistory(`You: ${input}`);
userInput.value = '';
// Call the backend API to generate response
const response = await fetch('/generate_text', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ input_text: input }),
});
const data = await response.json();
updateChatHistory(`Assistant: ${data}`);
}
});
// Handle voice chat
voiceChatButton.addEventListener('click', () => {
// Implementation for voice chat functionality
// Example: Start recording voice and send it to the backend for processing
});
});