|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Restaurant Chatbot</title> |
|
<style> |
|
body { |
|
font-family: Arial, sans-serif; |
|
} |
|
#chat-container { |
|
max-width: 600px; |
|
margin: 0 auto; |
|
padding: 20px; |
|
border: 1px solid #ddd; |
|
background-color: #f9f9f9; |
|
} |
|
#chat-box { |
|
max-height: 400px; |
|
overflow-y: auto; |
|
margin-bottom: 20px; |
|
border: 1px solid #ddd; |
|
padding: 10px; |
|
background-color: #fff; |
|
} |
|
#user-input { |
|
width: 100%; |
|
padding: 10px; |
|
margin-top: 10px; |
|
} |
|
#send-btn { |
|
padding: 10px 15px; |
|
background-color: #007bff; |
|
color: white; |
|
border: none; |
|
cursor: pointer; |
|
} |
|
#send-btn:hover { |
|
background-color: #0056b3; |
|
} |
|
.bot-message, .user-message { |
|
padding: 10px; |
|
margin-bottom: 10px; |
|
border-radius: 5px; |
|
} |
|
.bot-message { |
|
background-color: #f1f1f1; |
|
} |
|
.user-message { |
|
background-color: #007bff; |
|
color: white; |
|
text-align: right; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<div id="chat-container"> |
|
<h2>Restaurant Chatbot</h2> |
|
<div id="chat-box"> |
|
|
|
</div> |
|
<input type="text" id="user-input" placeholder="Ask about the menu or suggest a dish..."> |
|
<button id="send-btn" onclick="sendMessage()">Send</button> |
|
</div> |
|
|
|
<script> |
|
function sendMessage() { |
|
var userMessage = document.getElementById("user-input").value; |
|
if (userMessage.trim() === "") return; |
|
|
|
appendMessage(userMessage, "user"); |
|
|
|
|
|
fetch('/get_response', { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/x-www-form-urlencoded' |
|
}, |
|
body: 'user_message=' + encodeURIComponent(userMessage) |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
appendMessage(data.response, "bot"); |
|
document.getElementById("user-input").value = ""; |
|
}); |
|
} |
|
|
|
function appendMessage(message, sender) { |
|
var chatBox = document.getElementById("chat-box"); |
|
var messageDiv = document.createElement("div"); |
|
messageDiv.classList.add(sender + "-message"); |
|
messageDiv.innerHTML = message; |
|
chatBox.appendChild(messageDiv); |
|
chatBox.scrollTop = chatBox.scrollHeight; |
|
} |
|
</script> |
|
</body> |
|
</html> |
|
|