bignova / templates /index.html
aydayya
add files
590afda
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Chat</title>
<style>
body {
background-color: #121212;
color: white;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.chat-container {
display: flex;
flex-direction: column;
justify-content: flex-end;
height: 100vh;
padding: 20px;
}
.messages {
flex-grow: 1;
overflow-y: auto;
margin-bottom: 20px;
padding: 10px;
background-color: #1e1e1e;
border-radius: 8px;
max-height: 80%;
}
.input-container {
display: flex;
justify-content: space-between;
align-items: center;
}
.input-field {
width: 80%;
padding: 10px;
background-color: #333;
color: white;
border: none;
border-radius: 5px;
}
.send-button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.send-button:hover {
background-color: #45a049;
}
.message {
margin-bottom: 15px;
}
.user-message {
text-align: right;
color: #4CAF50;
}
.ai-message {
text-align: left;
color: #f1f1f1;
}
</style>
</head>
<body>
<div class="chat-container">
<div id="messages" class="messages">
<!-- Messages will be displayed here -->
</div>
<div class="input-container">
<input type="text" id="messageInput" class="input-field" placeholder="Type a message..." onkeydown="if(event.key === 'Enter'){sendMessage();}">
<button id="sendButton" class="send-button" onclick="sendMessage()">Send</button>
</div>
</div>
<script>
async function sendMessage() {
const inputField = document.getElementById("messageInput");
const message = inputField.value.trim();
if (message) {
// Display user's message in the chat
displayMessage(message, "user-message");
// Clear the input field
inputField.value = '';
// Send the message to the backend and get the AI's response
const response = await fetch(`/chat/${encodeURIComponent(message)}`);
const data = await response.json();
const aiResponse = data.response;
// Display AI's response in the chat
displayMessage(aiResponse, "ai-message");
}
}
function displayMessage(message, className) {
const messagesContainer = document.getElementById("messages");
const messageElement = document.createElement("div");
messageElement.classList.add("message", className);
messageElement.textContent = message;
messagesContainer.appendChild(messageElement);
// Scroll to the bottom of the messages
messagesContainer.scrollTop = messagesContainer.scrollHeight;
}
</script>
</body>
</html>