Spaces:
Sleeping
Sleeping
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Wine Chatbot</title> | |
<style> | |
body { font-family: Arial, sans-serif; } | |
.chat-container { width: 300px; margin: 0 auto; } | |
.message { margin: 10px 0; } | |
.user { color: blue; } | |
.bot { color: green; } | |
</style> | |
</head> | |
<body> | |
<div class="chat-container"> | |
<h2>Wine Chatbot</h2> | |
<div id="chat-box"></div> | |
<input type="text" id="user-input" placeholder="Type your message..."> | |
<button onclick="sendMessage()">Send</button> | |
</div> | |
<script> | |
async function sendMessage() { | |
const userInput = document.getElementById('user-input').value; | |
const response = await fetch('/chat', { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ message: userInput }) | |
}); | |
const chatHistory = await response.json(); | |
document.getElementById('chat-box').innerHTML = chatHistory.history.map(entry => | |
`<div class="message ${entry.user ? 'user' : 'bot'}">${entry.user || entry.bot}</div>` | |
).join(''); | |
} | |
</script> | |
</body> | |
</html> | |