Spaces:
Running
Running
File size: 2,413 Bytes
aacf656 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<!DOCTYPE html>
<html>
<head>
<title>Landon Hotel Chatbot</title>
<style>
/* CSS styles for the chatbot interface */
#chat-container {
width: 400px;
height: 500px;
border: 1px solid #ccc;
overflow-y: scroll;
padding: 10px;
}
.message {
margin-bottom: 10px;
}
.user {
font-weight: bold;
color: blue;
}
.bot {
font-weight: bold;
color: green;
}
</style>
</head>
<body>
<h1>Landon Hotel Chatbot</h1>
<div id="chat-container"></div>
<input type="text" id="user-input" placeholder="Type your message..." />
<button id="send-btn">Send</button>
<script>
const chatContainer = document.getElementById('chat-container');
const userInput = document.getElementById('user-input');
const sendBtn = document.getElementById('send-btn');
sendBtn.addEventListener('click', sendMessage);
function sendMessage() {
const userMessage = userInput.value.trim();
if (userMessage) {
displayMessage('user', userMessage);
sendMessageToServer(userMessage);
userInput.value = '';
}
}
function displayMessage(sender, message) {
const messageElement = document.createElement('div');
messageElement.classList.add('message');
messageElement.classList.add(sender);
messageElement.textContent = `${sender}: ${message}`;
chatContainer.appendChild(messageElement);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
function sendMessageToServer(message) {
fetch('/chatbot', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ question: message }),
})
.then((response) => response.json())
.then((data) => {
displayMessage('bot', data.response);
})
.catch((error) => {
console.error('Error:', error);
});
}
</script>
</body>
</html> |