File size: 8,985 Bytes
db6e2f8 2ea1682 a008f7a 2ea1682 f6f7504 2ea1682 db6e2f8 2ea1682 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
<!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> |