Spaces:
Paused
Paused
File size: 9,335 Bytes
f081192 |
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 |
// API Base URL - automatically uses the current host
const API_BASE = window.location.origin;
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
console.log('๐ Initializing Flare.NX & Orynx AI Labs Dashboard');
checkHealth();
checkGPU();
loadGPUInfo();
});
// Health Check
async function checkHealth() {
const statusEl = document.getElementById('healthStatus');
const cardEl = document.getElementById('healthCard');
try {
statusEl.innerHTML = '<div class="spinner"></div> Checking...';
const response = await fetch(`${API_BASE}/health`);
const data = await response.json();
if (data.status === 'healthy' && data.gpu_available) {
statusEl.innerHTML = `
<div class="status-ok">โ
Healthy</div>
<div class="status-detail">GPU: ${data.device_name}</div>
<div class="status-detail">Devices: ${data.cuda_devices}</div>
`;
cardEl.classList.add('status-ok');
cardEl.classList.remove('status-error');
} else {
statusEl.innerHTML = '<div class="status-warning">โ ๏ธ CPU Only</div>';
cardEl.classList.add('status-warning');
}
} catch (error) {
statusEl.innerHTML = '<div class="status-error">โ Error</div>';
cardEl.classList.add('status-error');
console.error('Health check error:', error);
}
}
// GPU Status Check
async function checkGPU() {
const statusEl = document.getElementById('gpuStatus');
const cardEl = document.getElementById('gpuCard');
try {
statusEl.innerHTML = '<div class="spinner"></div> Loading...';
const response = await fetch(`${API_BASE}/gpu-info`);
const data = await response.json();
if (data.cuda_available && data.devices.length > 0) {
const device = data.devices[0];
statusEl.innerHTML = `
<div class="status-ok">โ
Active</div>
<div class="status-detail">${device.name}</div>
<div class="status-detail">${device.total_memory_gb} GB VRAM</div>
`;
cardEl.classList.add('status-ok');
cardEl.classList.remove('status-error');
} else {
statusEl.innerHTML = '<div class="status-warning">โ ๏ธ No GPU</div>';
cardEl.classList.add('status-warning');
}
} catch (error) {
statusEl.innerHTML = '<div class="status-error">โ Error</div>';
cardEl.classList.add('status-error');
console.error('GPU check error:', error);
}
}
// Load GPU Information
async function loadGPUInfo() {
const detailsEl = document.getElementById('gpuDetails');
try {
const response = await fetch(`${API_BASE}/gpu-info`);
const data = await response.json();
if (data.cuda_available && data.devices.length > 0) {
const device = data.devices[0];
detailsEl.innerHTML = `
<div class="gpu-card">
<div class="gpu-header">
<h3>๐ฎ ${device.name}</h3>
<span class="gpu-badge">Device #${device.id}</span>
</div>
<div class="gpu-specs">
<div class="spec-item">
<span class="spec-label">Total Memory:</span>
<span class="spec-value">${device.total_memory_gb} GB</span>
</div>
<div class="spec-item">
<span class="spec-label">Compute Capability:</span>
<span class="spec-value">${device.major}.${device.minor}</span>
</div>
<div class="spec-item">
<span class="spec-label">Multiprocessors:</span>
<span class="spec-value">${device.multi_processor_count}</span>
</div>
<div class="spec-item">
<span class="spec-label">Total Devices:</span>
<span class="spec-value">${data.device_count}</span>
</div>
</div>
<div class="gpu-performance">
<div class="performance-bar">
<div class="performance-fill" style="width: 95%"></div>
</div>
<p class="performance-text">GPU Performance: Optimal</p>
</div>
</div>
`;
} else {
detailsEl.innerHTML = `
<div class="gpu-card gpu-unavailable">
<p>โ ๏ธ CUDA not available. Running on CPU.</p>
</div>
`;
}
} catch (error) {
detailsEl.innerHTML = `
<div class="gpu-card gpu-error">
<p>โ Error loading GPU information.</p>
</div>
`;
console.error('GPU info error:', error);
}
}
// Process Text
async function processText() {
const textInput = document.getElementById('textInput').value;
const maxLength = parseInt(document.getElementById('maxLength').value);
const outputGroup = document.getElementById('outputGroup');
const outputContent = document.getElementById('outputContent');
if (!textInput.trim()) {
alert('Please enter some text to process!');
return;
}
try {
outputContent.innerHTML = '<div class="spinner"></div> Processing with GPU...';
outputGroup.style.display = 'block';
const response = await fetch(`${API_BASE}/process`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: textInput,
max_length: maxLength
})
});
const data = await response.json();
outputContent.innerHTML = `
<div class="result-card">
<div class="result-item">
<strong>Input:</strong>
<div class="result-value">${data.input}</div>
</div>
<div class="result-item">
<strong>Processed:</strong>
<div class="result-value result-highlight">${data.processed}</div>
</div>
<div class="result-item">
<strong>Length:</strong>
<span class="result-badge">${data.length} characters</span>
</div>
<div class="result-item">
<strong>Max Length:</strong>
<span class="result-badge">${data.max_length}</span>
</div>
<div class="result-item">
<strong>GPU Used:</strong>
<span class="result-badge ${data.gpu_used ? 'badge-success' : 'badge-warning'}">
${data.gpu_used ? 'โ
Yes' : 'โ ๏ธ No'}
</span>
</div>
</div>
`;
} catch (error) {
outputContent.innerHTML = `
<div class="error-message">
โ Error processing text: ${error.message}
</div>
`;
console.error('Process error:', error);
}
}
// Test Endpoint
async function testEndpoint(endpoint) {
const responseSection = document.getElementById('responseSection');
const responseContent = document.getElementById('responseContent');
try {
responseContent.textContent = 'Loading...';
responseSection.style.display = 'block';
responseSection.scrollIntoView({ behavior: 'smooth' });
// Use /api for root endpoint, others as-is
const url = endpoint === '/' ? `${API_BASE}/api` : `${API_BASE}${endpoint}`;
const response = await fetch(url);
const data = await response.json();
responseContent.textContent = JSON.stringify(data, null, 2);
responseContent.classList.add('json-highlight');
} catch (error) {
responseContent.textContent = `Error: ${error.message}`;
console.error('Endpoint test error:', error);
}
}
// Copy Response
function copyResponse() {
const responseContent = document.getElementById('responseContent');
navigator.clipboard.writeText(responseContent.textContent).then(() => {
const btn = document.querySelector('.btn-copy');
const originalText = btn.textContent;
btn.textContent = 'โ
Copied!';
setTimeout(() => {
btn.textContent = originalText;
}, 2000);
});
}
// Close Response
function closeResponse() {
document.getElementById('responseSection').style.display = 'none';
}
// Auto-refresh status every 30 seconds
setInterval(() => {
checkHealth();
checkGPU();
}, 30000);
|