Update index.html
Browse files- index.html +88 -55
index.html
CHANGED
|
@@ -53,15 +53,19 @@
|
|
| 53 |
<h1 class="text-4xl font-extrabold tracking-tight text-white">Cartesia <span class="text-blue-500">AI</span></h1>
|
| 54 |
<p class="text-gray-400">TTS + Voice Cloning π€</p>
|
| 55 |
</div>
|
| 56 |
-
<div class="space-y-2">
|
| 57 |
-
<div class="flex items-center gap-3 cartesia-card p-2 px-4 rounded-full">
|
| 58 |
-
<
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
</div>
|
| 61 |
-
<div id="
|
| 62 |
-
<
|
| 63 |
-
<div class="credit-badge" id="creditBadge">π° Loading...</div>
|
| 64 |
-
<button id="refreshCreditsBtn" class="text-xs text-gray-500 hover:text-gray-300 mt-1">π Refresh</button>
|
| 65 |
</div>
|
| 66 |
</div>
|
| 67 |
</div>
|
|
@@ -225,6 +229,8 @@
|
|
| 225 |
const shareBtn = document.getElementById('shareBtn');
|
| 226 |
const creditArea = document.getElementById('creditArea');
|
| 227 |
const creditBadge = document.getElementById('creditBadge');
|
|
|
|
|
|
|
| 228 |
|
| 229 |
// Clone elements
|
| 230 |
const uploadArea = document.getElementById('uploadArea');
|
|
@@ -282,6 +288,65 @@
|
|
| 282 |
}
|
| 283 |
}
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
// Toggle key visibility
|
| 286 |
toggleShowKey.addEventListener('click', () => {
|
| 287 |
const type = apiKeyInput.type === 'password' ? 'text' : 'password';
|
|
@@ -297,6 +362,7 @@
|
|
| 297 |
statusDot.className = "h-3 w-3 rounded-full bg-red-500 pulse-red";
|
| 298 |
statusText.textContent = "DISCONNECTED";
|
| 299 |
creditArea.classList.add('hidden');
|
|
|
|
| 300 |
});
|
| 301 |
|
| 302 |
// Connect and fetch voices + credits
|
|
@@ -329,52 +395,8 @@
|
|
| 329 |
voiceSelect.appendChild(option);
|
| 330 |
});
|
| 331 |
|
| 332 |
-
// Fetch credits
|
| 333 |
-
|
| 334 |
-
let credits = null;
|
| 335 |
-
|
| 336 |
-
// Try endpoint 1
|
| 337 |
-
try {
|
| 338 |
-
const creditsResponse = await fetch(`${CARTESIA_API_URL}/account/billing/credits`, {
|
| 339 |
-
headers: {
|
| 340 |
-
"X-API-Key": key,
|
| 341 |
-
"Cartesia-Version": "2024-06-10"
|
| 342 |
-
}
|
| 343 |
-
});
|
| 344 |
-
|
| 345 |
-
if (creditsResponse.ok) {
|
| 346 |
-
const creditsData = await creditsResponse.json();
|
| 347 |
-
credits = creditsData.credits || creditsData.remaining_credits || creditsData.balance || 0;
|
| 348 |
-
}
|
| 349 |
-
} catch (e1) {
|
| 350 |
-
// Try endpoint 2
|
| 351 |
-
try {
|
| 352 |
-
const accountResponse = await fetch(`${CARTESIA_API_URL}/account`, {
|
| 353 |
-
headers: {
|
| 354 |
-
"X-API-Key": key,
|
| 355 |
-
"Cartesia-Version": "2024-06-10"
|
| 356 |
-
}
|
| 357 |
-
});
|
| 358 |
-
|
| 359 |
-
if (accountResponse.ok) {
|
| 360 |
-
const accountData = await accountResponse.json();
|
| 361 |
-
credits = accountData.credits || accountData.remaining_credits || accountData.balance || 0;
|
| 362 |
-
}
|
| 363 |
-
} catch (e2) {
|
| 364 |
-
console.log("Credits endpoints failed");
|
| 365 |
-
}
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
if (credits !== null && credits > 0) {
|
| 369 |
-
creditBadge.textContent = `π° ${(credits).toFixed(0)} Credits`;
|
| 370 |
-
creditArea.classList.remove('hidden');
|
| 371 |
-
} else if (credits !== null) {
|
| 372 |
-
creditBadge.textContent = `π° ${(credits).toFixed(0)} Credits`;
|
| 373 |
-
creditArea.classList.remove('hidden');
|
| 374 |
-
}
|
| 375 |
-
} catch (e) {
|
| 376 |
-
console.log("Credit fetch error:", e);
|
| 377 |
-
}
|
| 378 |
|
| 379 |
statusDot.className = "h-3 w-3 rounded-full bg-green-500 shadow-lg shadow-green-900";
|
| 380 |
statusText.textContent = "CONNECTED";
|
|
@@ -393,6 +415,17 @@
|
|
| 393 |
|
| 394 |
connectBtn.addEventListener('click', fetchVoices);
|
| 395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
// File upload
|
| 397 |
uploadArea.addEventListener('click', () => audioFile.click());
|
| 398 |
uploadArea.addEventListener('dragover', (e) => {
|
|
@@ -603,4 +636,4 @@
|
|
| 603 |
window.addEventListener('load', initializeApp);
|
| 604 |
</script>
|
| 605 |
</body>
|
| 606 |
-
</html>
|
|
|
|
| 53 |
<h1 class="text-4xl font-extrabold tracking-tight text-white">Cartesia <span class="text-blue-500">AI</span></h1>
|
| 54 |
<p class="text-gray-400">TTS + Voice Cloning π€</p>
|
| 55 |
</div>
|
| 56 |
+
<div class="space-y-2 w-full md:w-auto">
|
| 57 |
+
<div class="flex items-center gap-3 cartesia-card p-2 px-4 rounded-full justify-between md:justify-start">
|
| 58 |
+
<div class="flex items-center gap-3">
|
| 59 |
+
<span id="statusDot" class="h-3 w-3 rounded-full bg-red-500 pulse-red flex-shrink-0"></span>
|
| 60 |
+
<span id="statusText" class="text-sm font-medium text-gray-300 uppercase">Disconnected</span>
|
| 61 |
+
</div>
|
| 62 |
+
<div id="creditArea" class="hidden flex items-center gap-2">
|
| 63 |
+
<span class="text-xs text-gray-400">|</span>
|
| 64 |
+
<div class="credit-badge" id="creditBadge">π° Loading...</div>
|
| 65 |
+
</div>
|
| 66 |
</div>
|
| 67 |
+
<div id="creditRefreshArea" class="hidden text-center md:text-right">
|
| 68 |
+
<button id="refreshCreditsBtn" class="text-xs text-gray-500 hover:text-gray-300">π Refresh Credits</button>
|
|
|
|
|
|
|
| 69 |
</div>
|
| 70 |
</div>
|
| 71 |
</div>
|
|
|
|
| 229 |
const shareBtn = document.getElementById('shareBtn');
|
| 230 |
const creditArea = document.getElementById('creditArea');
|
| 231 |
const creditBadge = document.getElementById('creditBadge');
|
| 232 |
+
const refreshCreditsBtn = document.getElementById('refreshCreditsBtn');
|
| 233 |
+
const creditRefreshArea = document.getElementById('creditRefreshArea');
|
| 234 |
|
| 235 |
// Clone elements
|
| 236 |
const uploadArea = document.getElementById('uploadArea');
|
|
|
|
| 288 |
}
|
| 289 |
}
|
| 290 |
|
| 291 |
+
// Fetch and display credits
|
| 292 |
+
async function fetchCredits(key) {
|
| 293 |
+
try {
|
| 294 |
+
let credits = null;
|
| 295 |
+
|
| 296 |
+
// Try endpoint 1
|
| 297 |
+
try {
|
| 298 |
+
const creditsResponse = await fetch(`${CARTESIA_API_URL}/account/billing/credits`, {
|
| 299 |
+
headers: {
|
| 300 |
+
"X-API-Key": key,
|
| 301 |
+
"Cartesia-Version": "2024-06-10"
|
| 302 |
+
}
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
+
if (creditsResponse.ok) {
|
| 306 |
+
const creditsData = await creditsResponse.json();
|
| 307 |
+
credits = creditsData.credits || creditsData.remaining_credits || creditsData.balance || 0;
|
| 308 |
+
console.log("Credits from /account/billing/credits:", credits);
|
| 309 |
+
}
|
| 310 |
+
} catch (e1) {
|
| 311 |
+
console.log("Endpoint 1 failed, trying endpoint 2");
|
| 312 |
+
// Try endpoint 2
|
| 313 |
+
try {
|
| 314 |
+
const accountResponse = await fetch(`${CARTESIA_API_URL}/account`, {
|
| 315 |
+
headers: {
|
| 316 |
+
"X-API-Key": key,
|
| 317 |
+
"Cartesia-Version": "2024-06-10"
|
| 318 |
+
}
|
| 319 |
+
});
|
| 320 |
+
|
| 321 |
+
if (accountResponse.ok) {
|
| 322 |
+
const accountData = await accountResponse.json();
|
| 323 |
+
credits = accountData.credits || accountData.remaining_credits || accountData.balance || 0;
|
| 324 |
+
console.log("Credits from /account:", credits);
|
| 325 |
+
}
|
| 326 |
+
} catch (e2) {
|
| 327 |
+
console.log("Both endpoints failed", e1, e2);
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
if (credits !== null) {
|
| 332 |
+
const displayCredits = typeof credits === 'number' ? credits.toFixed(0) : credits;
|
| 333 |
+
creditBadge.textContent = `π° ${displayCredits} Credits`;
|
| 334 |
+
creditArea.classList.remove('hidden');
|
| 335 |
+
creditRefreshArea.classList.remove('hidden');
|
| 336 |
+
console.log("Credits displayed:", displayCredits);
|
| 337 |
+
} else {
|
| 338 |
+
creditBadge.textContent = `π° Unable to fetch`;
|
| 339 |
+
creditArea.classList.remove('hidden');
|
| 340 |
+
creditRefreshArea.classList.remove('hidden');
|
| 341 |
+
}
|
| 342 |
+
} catch (e) {
|
| 343 |
+
console.log("Credit fetch error:", e);
|
| 344 |
+
creditBadge.textContent = `π° Error`;
|
| 345 |
+
creditArea.classList.remove('hidden');
|
| 346 |
+
creditRefreshArea.classList.remove('hidden');
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
// Toggle key visibility
|
| 351 |
toggleShowKey.addEventListener('click', () => {
|
| 352 |
const type = apiKeyInput.type === 'password' ? 'text' : 'password';
|
|
|
|
| 362 |
statusDot.className = "h-3 w-3 rounded-full bg-red-500 pulse-red";
|
| 363 |
statusText.textContent = "DISCONNECTED";
|
| 364 |
creditArea.classList.add('hidden');
|
| 365 |
+
creditRefreshArea.classList.add('hidden');
|
| 366 |
});
|
| 367 |
|
| 368 |
// Connect and fetch voices + credits
|
|
|
|
| 395 |
voiceSelect.appendChild(option);
|
| 396 |
});
|
| 397 |
|
| 398 |
+
// Fetch credits
|
| 399 |
+
fetchCredits(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
|
| 401 |
statusDot.className = "h-3 w-3 rounded-full bg-green-500 shadow-lg shadow-green-900";
|
| 402 |
statusText.textContent = "CONNECTED";
|
|
|
|
| 415 |
|
| 416 |
connectBtn.addEventListener('click', fetchVoices);
|
| 417 |
|
| 418 |
+
// Refresh credits button
|
| 419 |
+
if (refreshCreditsBtn) {
|
| 420 |
+
refreshCreditsBtn.addEventListener('click', async () => {
|
| 421 |
+
const key = apiKeyInput.value.trim();
|
| 422 |
+
if (!key) return updateLog("API Key daalo pehle", "error");
|
| 423 |
+
refreshCreditsBtn.textContent = "β³ Loading...";
|
| 424 |
+
await fetchCredits(key);
|
| 425 |
+
refreshCreditsBtn.textContent = "π Refresh Credits";
|
| 426 |
+
});
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
// File upload
|
| 430 |
uploadArea.addEventListener('click', () => audioFile.click());
|
| 431 |
uploadArea.addEventListener('dragover', (e) => {
|
|
|
|
| 636 |
window.addEventListener('load', initializeApp);
|
| 637 |
</script>
|
| 638 |
</body>
|
| 639 |
+
</html>
|