Chappieut's picture
Upload 30 files
14b27c6 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat with GPT-2</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
}
.chat-container {
width: 400px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
padding: 16px;
}
.chat-box {
height: 300px;
overflow-y: auto;
border: 1px solid #ddd;
padding: 8px;
margin-bottom: 8px;
}
.chat-box div {
margin-bottom: 8px;
}
.user-message {
text-align: right;
}
.bot-message {
text-align: left;
}
.chat-input {
width: calc(100% - 80px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.send-button {
padding: 8px;
border: none;
background: #007bff;
color: white;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-box" id="chat-box"></div>
<input type="text" class="chat-input" id="chat-input" placeholder="Type your message...">
<button class="send-button" onclick="sendMessage()">Send</button>
</div>
<script>
const chatBox = document.getElementById("chat-box");
const chatInput = document.getElementById("chat-input");
async function sendMessage() {
const userMessage = chatInput.value;
if (!userMessage) return;
// Display user message
const userDiv = document.createElement("div");
userDiv.className = "user-message";
userDiv.textContent = "You: " + userMessage;
chatBox.appendChild(userDiv);
// Send message to backend
const response = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: userMessage }),
});
const data = await response.json();
const botReply = data.reply || "Sorry, I didn't understand that.";
// Display bot reply
const botDiv = document.createElement("div");
botDiv.className = "bot-message";
botDiv.textContent = "Bot: " + botReply;
chatBox.appendChild(botDiv);
// Clear input
chatInput.value = "";
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
}
</script>
</body>
</html>