Spaces:
Runtime error
Runtime error
File size: 1,458 Bytes
4a17e5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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
});
});
|