Spaces:
Sleeping
Sleeping
File size: 1,478 Bytes
bf858f1 |
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 40 41 42 43 44 45 46 47 48 49 50 |
async function sendMessage() {
const userInput = document.getElementById('user-input').value;
if (!userInput) return;
const chatBox = document.getElementById('chat-box');
// Display user's message
const userMessage = document.createElement('div');
userMessage.classList.add('message', 'user');
userMessage.textContent = userInput;
chatBox.appendChild(userMessage);
// Clear the input field
document.getElementById('user-input').value = '';
// Send the message to the server
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: userInput })
});
const data = await response.json();
// Create a new div for the bot's response
const botMessage = document.createElement('div');
botMessage.classList.add('message', 'bot');
botMessage.innerHTML = data.response; // Use innerHTML to render Markdown
chatBox.appendChild(botMessage);
// Scroll to the bottom of the chat box
chatBox.scrollTop = chatBox.scrollHeight;
}
function handleKeyPress(event) {
if (event.key === 'Enter') {
sendMessage();
}
}
async function exitChat() {
await fetch('/shutdown', { method: 'POST' });
}
function newChat() {
const chatBox = document.getElementById('chat-box');
chatBox.innerHTML = '<div class="message bot">Hi, Welcome to the Medical Bot. What is your query?</div>';
}
|