Spaces:
Running
Running
improve to production rdy app - Follow Up Deployment
Browse files- index.html +229 -13
index.html
CHANGED
|
@@ -61,6 +61,33 @@
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
</script>
|
| 65 |
</head>
|
| 66 |
<body class="bg-gray-900 overflow-hidden font-terminal min-h-screen">
|
|
@@ -181,33 +208,222 @@
|
|
| 181 |
<div class="flex items-center">
|
| 182 |
<div class="text-green-500 mr-3 font-bold">user@terminal:~$</div>
|
| 183 |
<div class="flex-grow flex items-center border border-green-700 bg-black/30">
|
| 184 |
-
<
|
| 185 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
</div>
|
| 187 |
-
<input type="text" class="flex-grow bg-transparent outline-none px-2 py-1 text-green-300" placeholder="Enter cognitive query...">
|
| 188 |
</div>
|
| 189 |
-
<button class="ml-3 px-4 py-1 bg-green-700 hover:bg-green-600 text-cyan-100 font-bold rounded-sm">Execute</button>
|
| 190 |
</div>
|
| 191 |
|
| 192 |
<div class="mt-3 flex justify-between text-xs text-cyan-400">
|
| 193 |
-
<div>
|
| 194 |
<i class="fas fa-brain mr-1"></i>
|
| 195 |
-
|
| 196 |
</div>
|
| 197 |
-
<div>
|
| 198 |
<i class="fas fa-bolt mr-1"></i>
|
| 199 |
-
|
| 200 |
</div>
|
| 201 |
-
<div>
|
| 202 |
<i class="fas fa-database mr-1"></i>
|
| 203 |
-
|
| 204 |
</div>
|
| 205 |
-
<div class="text-yellow-400 font-bold">
|
| 206 |
-
<i class="fas fa-star"></i>
|
| 207 |
-
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
</div>
|
| 211 |
</div>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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=5dimension/terminal" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 213 |
</html>
|
|
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|
| 64 |
+
|
| 65 |
+
// Configuration
|
| 66 |
+
const CONFIG = {
|
| 67 |
+
HF_API_URL: "https://api-inference.huggingface.co/models/",
|
| 68 |
+
DEFAULT_MODEL: "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 69 |
+
MAX_TOKENS: 4096,
|
| 70 |
+
RATE_LIMIT: 3000, // ms between requests
|
| 71 |
+
HISTORY_SIZE: 20
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
const PROMPT_TEMPLATES = {
|
| 75 |
+
"standard": `[INST] You are NeuroCognitive Terminal v9.24.6. Provide detailed technical analysis with references.
|
| 76 |
+
Break response into clear sections with markdown formatting. Current date: ${new Date().toISOString()}
|
| 77 |
+
User Query: {query}[/INST]`,
|
| 78 |
+
"creative": `[INST] Generate innovative ideas combining multiple disciplines. Use lateral thinking and unconventional approaches.
|
| 79 |
+
Query: {query} Consider these unexpected angles:[/INST]`,
|
| 80 |
+
"technical": `[INST] Respond with precise technical specifications, equations, and implementation details.
|
| 81 |
+
Query: {query} Include: 1) Technical requirements 2) Implementation steps 3) Sample code[/INST]`
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
// State management
|
| 85 |
+
const AppState = {
|
| 86 |
+
history: JSON.parse(localStorage.getItem('terminalHistory')) || [],
|
| 87 |
+
lastRequestTime: 0,
|
| 88 |
+
currentModel: CONFIG.DEFAULT_MODEL,
|
| 89 |
+
apiKey: localStorage.getItem('hfApiKey') || ''
|
| 90 |
+
};
|
| 91 |
</script>
|
| 92 |
</head>
|
| 93 |
<body class="bg-gray-900 overflow-hidden font-terminal min-h-screen">
|
|
|
|
| 208 |
<div class="flex items-center">
|
| 209 |
<div class="text-green-500 mr-3 font-bold">user@terminal:~$</div>
|
| 210 |
<div class="flex-grow flex items-center border border-green-700 bg-black/30">
|
| 211 |
+
<select class="bg-black text-green-400 px-2 h-full border-r border-green-800">
|
| 212 |
+
<option value="standard">Standard</option>
|
| 213 |
+
<option value="creative">Creative</option>
|
| 214 |
+
<option value="technical">Technical</option>
|
| 215 |
+
</select>
|
| 216 |
+
<input id="promptInput" type="text" class="flex-grow bg-transparent outline-none px-2 py-1 text-green-300" placeholder="Enter cognitive query...">
|
| 217 |
+
<div class="h-full bg-green-500/30 px-3 font-mono flex items-center">
|
| 218 |
+
<div class="inline-block w-4 h-6 bg-green-400 prompt"></div>
|
| 219 |
</div>
|
|
|
|
| 220 |
</div>
|
| 221 |
+
<button onclick="TerminalApp.executePrompt()" class="ml-3 px-4 py-1 bg-green-700 hover:bg-green-600 text-cyan-100 font-bold rounded-sm">Execute</button>
|
| 222 |
</div>
|
| 223 |
|
| 224 |
<div class="mt-3 flex justify-between text-xs text-cyan-400">
|
| 225 |
+
<div class="flex items-center">
|
| 226 |
<i class="fas fa-brain mr-1"></i>
|
| 227 |
+
<span>LLM: <span id="llmStatus" class="text-green-400">${CONFIG.DEFAULT_MODEL.split('/').pop()}</span></span>
|
| 228 |
</div>
|
| 229 |
+
<div class="flex items-center">
|
| 230 |
<i class="fas fa-bolt mr-1"></i>
|
| 231 |
+
<span>Tokens: <span id="tokenCounter">0</span>/2048</span>
|
| 232 |
</div>
|
| 233 |
+
<div class="flex items-center">
|
| 234 |
<i class="fas fa-database mr-1"></i>
|
| 235 |
+
<span>Context: <span id="contextStatus">Ready</span></span>
|
| 236 |
</div>
|
| 237 |
+
<div class="text-yellow-400 font-bold flex items-center">
|
| 238 |
+
<i class="fas fa-star mr-1"></i>
|
| 239 |
+
<span>Score: <span id="aiScore">+30</span></span>
|
| 240 |
</div>
|
| 241 |
</div>
|
| 242 |
</div>
|
| 243 |
</div>
|
| 244 |
+
<script>
|
| 245 |
+
// API Client
|
| 246 |
+
class HuggingFaceClient {
|
| 247 |
+
static async query(payload, model = CONFIG.DEFAULT_MODEL) {
|
| 248 |
+
const now = Date.now();
|
| 249 |
+
if (now - AppState.lastRequestTime < CONFIG.RATE_LIMIT) {
|
| 250 |
+
throw new Error(`Rate limited. Please wait ${Math.ceil((CONFIG.RATE_LIMIT - (now - AppState.lastRequestTime))/1000)}s`);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (!AppState.apiKey) {
|
| 254 |
+
throw new Error('API key not configured. Set your HuggingFace token in settings.');
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
AppState.lastRequestTime = now;
|
| 258 |
+
|
| 259 |
+
const response = await fetch(`${CONFIG.HF_API_URL}${model}`, {
|
| 260 |
+
headers: {
|
| 261 |
+
"Authorization": `Bearer ${AppState.apiKey}`,
|
| 262 |
+
"Content-Type": "application/json"
|
| 263 |
+
},
|
| 264 |
+
method: "POST",
|
| 265 |
+
body: JSON.stringify(payload),
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
if (!response.ok) {
|
| 269 |
+
const error = await response.json();
|
| 270 |
+
throw new Error(error.error || 'API request failed');
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
return response.json();
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
// UI Components
|
| 278 |
+
class TerminalUI {
|
| 279 |
+
static addHistoryEntry(prompt, response) {
|
| 280 |
+
const entry = {
|
| 281 |
+
timestamp: new Date().toISOString(),
|
| 282 |
+
prompt,
|
| 283 |
+
response,
|
| 284 |
+
model: AppState.currentModel
|
| 285 |
+
};
|
| 286 |
+
|
| 287 |
+
AppState.history.unshift(entry);
|
| 288 |
+
if (AppState.history.length > CONFIG.HISTORY_SIZE) {
|
| 289 |
+
AppState.history.pop();
|
| 290 |
+
}
|
| 291 |
+
localStorage.setItem('terminalHistory', JSON.stringify(AppState.history));
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
static async streamResponse(responseText, prompt) {
|
| 295 |
+
const terminalOutput = document.querySelector('.terminal-scrollbar');
|
| 296 |
+
const responseDiv = document.createElement('div');
|
| 297 |
+
responseDiv.className = 'mb-4';
|
| 298 |
+
terminalOutput.appendChild(responseDiv);
|
| 299 |
+
|
| 300 |
+
// Add prompt to history immediately
|
| 301 |
+
const promptDiv = document.createElement('div');
|
| 302 |
+
promptDiv.className = 'mb-2';
|
| 303 |
+
promptDiv.innerHTML = `
|
| 304 |
+
<div class="flex items-start">
|
| 305 |
+
<div class="text-cyan-400 mr-2">user@terminal:~$</div>
|
| 306 |
+
<div class="font-mono">${prompt}</div>
|
| 307 |
+
</div>
|
| 308 |
+
`;
|
| 309 |
+
terminalOutput.insertBefore(promptDiv, responseDiv);
|
| 310 |
+
|
| 311 |
+
// Prepare response area
|
| 312 |
+
responseDiv.innerHTML = `
|
| 313 |
+
<div class="flex items-start">
|
| 314 |
+
<div class="text-purple-400 mr-2">neuro-ai@core:~$</div>
|
| 315 |
+
<div class="font-mono">RESPONSE_STREAM</div>
|
| 316 |
+
</div>
|
| 317 |
+
<div class="ml-6 mt-2 text-green-300 whitespace-pre-wrap"></div>
|
| 318 |
+
`;
|
| 319 |
+
|
| 320 |
+
const contentDiv = responseDiv.querySelector('.whitespace-pre-wrap');
|
| 321 |
+
let currentText = '';
|
| 322 |
+
|
| 323 |
+
for (const char of responseText) {
|
| 324 |
+
currentText += char;
|
| 325 |
+
contentDiv.textContent = currentText;
|
| 326 |
+
terminalOutput.scrollTop = terminalOutput.scrollHeight;
|
| 327 |
+
await new Promise(r => setTimeout(r, 5));
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
this.addHistoryEntry(prompt, responseText);
|
| 331 |
+
return currentText;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
static showError(message) {
|
| 335 |
+
const terminalOutput = document.querySelector('.terminal-scrollbar');
|
| 336 |
+
const errorDiv = document.createElement('div');
|
| 337 |
+
errorDiv.className = 'mb-4 text-red-400';
|
| 338 |
+
errorDiv.innerHTML = `
|
| 339 |
+
<div class="flex items-start">
|
| 340 |
+
<div class="text-red-500 mr-2">system@error:~$</div>
|
| 341 |
+
<div class="font-mono">${message}</div>
|
| 342 |
+
</div>
|
| 343 |
+
`;
|
| 344 |
+
terminalOutput.appendChild(errorDiv);
|
| 345 |
+
terminalOutput.scrollTop = terminalOutput.scrollHeight;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
static toggleLoading(state) {
|
| 349 |
+
const statusEl = document.getElementById('contextStatus');
|
| 350 |
+
const llmStatus = document.getElementById('llmStatus');
|
| 351 |
+
|
| 352 |
+
if (state) {
|
| 353 |
+
statusEl.textContent = 'Processing';
|
| 354 |
+
statusEl.classList.add('text-yellow-400');
|
| 355 |
+
llmStatus.classList.add('animate-pulse');
|
| 356 |
+
} else {
|
| 357 |
+
statusEl.textContent = 'Ready';
|
| 358 |
+
statusEl.classList.remove('text-yellow-400');
|
| 359 |
+
llmStatus.classList.remove('animate-pulse');
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// Main Application
|
| 365 |
+
class TerminalApp {
|
| 366 |
+
static async executePrompt() {
|
| 367 |
+
const input = document.getElementById('promptInput');
|
| 368 |
+
const prompt = input.value.trim();
|
| 369 |
+
if (!prompt) return;
|
| 370 |
+
|
| 371 |
+
const mode = document.querySelector('select').value;
|
| 372 |
+
const fullPrompt = PROMPT_TEMPLATES[mode].replace('{query}', prompt);
|
| 373 |
+
|
| 374 |
+
TerminalUI.toggleLoading(true);
|
| 375 |
+
|
| 376 |
+
try {
|
| 377 |
+
const response = await HuggingFaceClient.query({
|
| 378 |
+
inputs: fullPrompt,
|
| 379 |
+
parameters: {
|
| 380 |
+
max_new_tokens: 1024,
|
| 381 |
+
temperature: mode === 'technical' ? 0.3 : 0.7,
|
| 382 |
+
return_full_text: false
|
| 383 |
+
}
|
| 384 |
+
});
|
| 385 |
+
|
| 386 |
+
const result = Array.isArray(response) ? response[0].generated_text : response.generated_text;
|
| 387 |
+
const processedText = await TerminalUI.streamResponse(result, prompt);
|
| 388 |
+
|
| 389 |
+
document.getElementById('tokenCounter').textContent = processedText.length;
|
| 390 |
+
input.value = '';
|
| 391 |
+
} catch (error) {
|
| 392 |
+
TerminalUI.showError(error.message);
|
| 393 |
+
console.error('API Error:', error);
|
| 394 |
+
} finally {
|
| 395 |
+
TerminalUI.toggleLoading(false);
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
static init() {
|
| 400 |
+
// Load settings
|
| 401 |
+
const settingsButton = document.createElement('div');
|
| 402 |
+
settingsButton.innerHTML = `
|
| 403 |
+
<div class="fixed bottom-20 right-4 bg-black/80 border border-cyan-700 p-2 rounded cursor-pointer hover:bg-cyan-900/50"
|
| 404 |
+
onclick="TerminalApp.showSettings()">
|
| 405 |
+
<i class="fas fa-cog"></i>
|
| 406 |
+
</div>
|
| 407 |
+
`;
|
| 408 |
+
document.body.appendChild(settingsButton);
|
| 409 |
+
|
| 410 |
+
// Display initial history if any
|
| 411 |
+
if (AppState.history.length > 0) {
|
| 412 |
+
const lastEntry = AppState.history[0];
|
| 413 |
+
TerminalUI.streamResponse(lastEntry.response, lastEntry.prompt);
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
static showSettings() {
|
| 418 |
+
// Implementation for settings modal
|
| 419 |
+
alert('Settings modal would appear here to configure API key and model');
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
// Initialize app
|
| 424 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 425 |
+
TerminalApp.init();
|
| 426 |
+
});
|
| 427 |
+
</script>
|
| 428 |
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=5dimension/terminal" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 429 |
</html>
|