assistant / templates /index.html
SamirXR's picture
Update templates/index.html
f6f7504 verified
raw
history blame
8.99 kB
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NyX AI</title>
<link rel="icon" href="https://cdn.discordapp.com/attachments/913760038361890867/931879891417317386/show.png" type="image/png">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/monokai.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script>
<style>
body {
background-color: #000;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#chat-container {
background-color: #111;
width: 90%;
max-width: 800px;
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 80vh;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
#conversation {
overflow-y: auto;
flex-grow: 1;
margin-bottom: 20px;
padding: 10px;
background-color: #000;
border-radius: 10px;
}
.message {
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
font-size: 16px;
}
.user-message {
background-color: #222;
align-self: flex-end;
color: #fff;
}
.bot-message {
background-color: #444;
align-self: flex-start;
color: #fff;
}
#user-input {
width: 70%;
padding: 10px;
border: none;
background-color: #222;
color: #fff;
font-size: 18px;
border-radius: 5px;
}
#send-button, #clear-chat {
width: 15%;
margin-left: 5px;
padding: 10px;
border: none;
background-color: #222;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
font-size: 18px;
border-radius: 5px;
}
#send-button:hover, #clear-chat:hover {
background-color: #444;
}
#generating-response {
display: none;
position: absolute;
bottom: 20%;
left: 50%;
transform: translateX(-50%);
color: #fff;
font-size: 20px;
animation: fadeIn 0.5s ease 0s 1 normal;
}
#xr7-link {
color: #fff;
text-decoration: none;
align-self: center;
margin-top: 10px;
}
@keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}
@media (max-width: 768px) {
#user-input {
width: 60%;
font-size: 16px;
}
#send-button, #clear-chat {
width: 20%;
font-size: 16px;
}
}
#logo {
display: block;
width: 100px; /* adjust as needed */
height: auto;
margin: 0 auto 1px; /* 20px bottom margin */
}
.logo-switch-container {
display: flex;
justify-content: space-between;
align-items: center;
}
input[type=checkbox] {
height: 0;
width: 0;
visibility: hidden;
}
label {
cursor: pointer;
text-indent: -9999px;
width: 50px;
height: 25px;
background: #444;
display: block;
border-radius: 50px;
position: relative;
}
label:after {
content: '';
position: absolute;
top: 2.5px;
left: 2.5px;
width: 20px;
height: 20px;
background: #fff;
border-radius: 20px;
transition: 0.3s;
}
input:checked + label {
background: #222;
}
input:checked + label:after {
left: calc(100% - 2.5px);
transform: translateX(-100%);
}
label:active:after {
width: 30px;
}
/* Add margin to the switch container */
#switch-container {
margin-right: 15px;
margin-top: -15px;
}
</style>
</head>
<body>
<div id="chat-container">
<div class="logo-switch-container">
<img id="logo" src="https://cdn.discordapp.com/attachments/1041233711930298408/1210734168976265216/nyx-high-resolution-logo-white-on-transparent-background_1.png" alt="Logo">
<div id="switch-container">
<input type="checkbox" id="switch" /><label for="switch">Toggle</label>
</div>
</div>
<div id="conversation">
<div class="message user-message">User: Hello, how are you?</div>
<div class="message bot-message">NyX: I'm doing well. How can I assist you today?</div>
</div>
<div style="display: flex;">
<input id="user-input" type="text" placeholder="Type a message and press Enter">
<button id="send-button">Send</button>
<button id="clear-chat">Clear Chat</button>
</div>
<div id="generating-response">Generating Response...</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
hljs.highlightAll();
});
if (!localStorage.getItem('session_id')) {
localStorage.setItem('session_id', 'session-' + Math.random().toString(36).substr(2, 9));
}
async function generateResponse(inputText) {
const generatingResponse = document.getElementById('generating-response');
generatingResponse.style.display = 'block';
const toggle = document.getElementById('switch').checked;
const response = await fetch('/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
prompt: inputText,
session_id: localStorage.getItem('session_id'),
toggle: toggle
})
});
generatingResponse.style.display = 'none';
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return data.result;
}
const conversation = document.getElementById('conversation');
const userInput = document.getElementById('user-input');
const clearChatButton = document.getElementById('clear-chat');
const sendButton = document.getElementById('send-button');
let isProcessing = false;
userInput.addEventListener('keypress', async (e) => {
if (e.key === 'Enter' && !isProcessing) {
sendMessage();
}
});
sendButton.addEventListener('click', () => {
if (!isProcessing) {
sendMessage();
}
});
clearChatButton.addEventListener('click', () => {
conversation.innerHTML = '';
});
function sendMessage() {
const userMessage = userInput.value.trim();
if (userMessage === '') {
return;
}
isProcessing = true;
sendButton.disabled = true;
const userMessageDiv = document.createElement('div');
userMessageDiv.textContent = 'User: ' + userMessage;
userMessageDiv.className = 'message user-message';
conversation.appendChild(userMessageDiv);
userInput.value = '';
generateResponse(userMessage)
.then((text) => {
const botMessageDiv = document.createElement('div');
botMessageDiv.className = 'message bot-message';
if (text.includes('```')) {
const pre = document.createElement('pre');
const code = document.createElement('code');
code.innerHTML = 'NyX: ' + text.replace(/```/g, '');
pre.appendChild(code);
botMessageDiv.appendChild(pre);
hljs.highlightBlock(code);
} else {
botMessageDiv.innerHTML = 'NyX: ' + text;
}
conversation.appendChild(botMessageDiv);
conversation.scrollTop = conversation.scrollHeight;
})
.catch((error) => {
console.error(error);
})
.finally(() => {
sendButton.disabled = false;
isProcessing = false;
});
}
</script>
</body>
</html>