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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PyxiLabs._.Vocify - Text to Speech API</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <!-- Favicon -->
    <link rel="icon" href="/static/icon.png" type="image/png">
    <link rel="icon" href="/static/icon.png" sizes="32x32" type="image/png">
    <link rel="icon" href="/static/icon.png" sizes="16x16" type="image/png">
    <link rel="apple-touch-icon" href="/static/icon.png">
    <link rel="icon" href="/static/icon.png" sizes="192x192">
    <style>
        :root {
            --gradient-start: #ff0066;
            --gradient-end: #3366ff;
        }

        body {
            background-image: url('static/bg3.png');
            background-size: cover;
            background-position: center;
            background-attachment: fixed;
            min-height: 100vh;
        }

        .gradient-text {
            background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .custom-shadow {
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        }

        .content-box {
            background: rgba(0, 0, 0, 0.15);
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .hover-scale {
            transition: transform 0.2s;
        }

        .hover-scale:hover {
            transform: scale(1.02);
        }

        .glass-effect {
            background: rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .input-dark {
            background: rgba(0, 0, 0, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: #fff;
            backdrop-filter: blur(4px);
        }

        .input-dark::placeholder {
            color: rgba(255, 255, 255, 0.6);
        }

        .input-dark:focus {
            border-color: var(--gradient-start);
            box-shadow: 0 0 0 2px rgba(255, 0, 102, 0.2);
            background: rgba(0, 0, 0, 0.15);
        }

        .gradient-btn {
            background: linear-gradient(45deg, var(--gradient-start), var(--gradient-end));
            backdrop-filter: blur(4px);
            transition: all 0.3s ease;
        }

        .gradient-btn:hover {
            filter: brightness(1.1);
            transform: translateY(-2px);
            background: linear-gradient(45deg, var(--gradient-end), var(--gradient-start));
        }

        select option {
            background-color: rgba(0, 0, 0, 0.8);
            color: white;
        }

        audio::-webkit-media-controls-panel {
            background: rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(4px);
        }

        audio::-webkit-media-controls-current-time-display,
        audio::-webkit-media-controls-time-remaining-display {
            color: white;
        }

        .text-shadow {
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        }

        pre {
            background: rgba(0, 0, 0, 0.1) !important;
            backdrop-filter: blur(4px);
            white-space: pre-wrap;
            word-wrap: break-word;
        }

        .white-text {
            color: rgba(255, 255, 255, 0.9);
        }

        /* Enhanced Loading Bar */
        .loading-bar-container {
            height: 12px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            overflow: hidden;
            margin-top: 1rem;
            position: relative;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        .loading-bar {
            height: 100%;
            background: linear-gradient(90deg, #ff0066, #3366ff);
            width: 0%;
            border-radius: 10px;
            transition: width 0.5s ease-in-out;
            position: relative;
            overflow: hidden;
        }

        .loading-bar::after {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.2));
            animation: shimmer 2s infinite;
        }

        @keyframes shimmer {
            0% {
                left: -100%;
            }
            100% {
                left: 100%;
            }
        }

        .loading-bar-text {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-size: 0.9rem;
            font-weight: bold;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
            background: rgba(0, 0, 0, 0.5);
            padding: 2px 8px;
            border-radius: 12px;
            backdrop-filter: blur(4px);
        }
    </style>
</head>
<body class="text-white text-shadow">
    <div class="container mx-auto px-4 py-8 md:py-12 max-w-6xl relative">
        <!-- Header -->
        <header class="text-center mb-8 md:mb-12">
            <div class="glass-effect inline-block px-6 md:px-10 py-4 md:py-6 rounded-3xl mb-6 md:mb-8">
                <h1 class="text-3xl md:text-5xl lg:text-7xl font-bold gradient-text mb-3 md:mb-4 tracking-tight">PyxiLabs._.Vocify</h1>
                <p class="white-text text-lg md:text-xl lg:text-2xl max-w-2xl mx-auto">Transform your text into natural speech with our powerful API</p>
            </div>
        </header>

        <!-- Main Content -->
        <div class="max-w-3xl mx-auto content-box rounded-3xl custom-shadow p-4 md:p-8 lg:p-10 hover-scale">
            <!-- Model Selection -->
            <div class="mb-6 md:mb-8">
                <label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="model">
                    Select Model
                </label>
                <div class="relative">
                    <select id="model" class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 appearance-none text-base md:text-lg">
                    </select>
                    <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 md:px-4 text-white">
                        <svg class="fill-current h-4 w-4 md:h-5 md:w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
                            <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
                        </svg>
                    </div>
                </div>
            </div>

            <!-- Voice Selection -->
            <div class="mb-6 md:mb-8">
                <label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="voice">
                    Select Voice
                </label>
                <div class="relative">
                    <select id="voice" class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 appearance-none text-base md:text-lg">
                    </select>
                    <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-3 md:px-4 text-white">
                        <svg class="fill-current h-4 w-4 md:h-5 md:w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
                            <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/>
                        </svg>
                    </div>
                </div>
            </div>

            <!-- Text Input -->
            <div class="mb-6 md:mb-8">
                <label class="block white-text text-base md:text-lg font-medium mb-2 md:mb-3" for="text">
                    Enter Text
                </label>
                <textarea
                    id="text"
                    rows="4"
                    maxlength="5000"
                    class="w-full px-4 md:px-5 py-3 md:py-4 rounded-xl input-dark focus:outline-none focus:ring-2 focus:ring-red-400 resize-none text-base md:text-lg"
                    placeholder="Enter your text here (max 5000 characters)..."
                ></textarea>
                <p id="char-count" class="text-sm md:text-base white-text mt-2 text-right">0/5000 characters</p>
            </div>

            <!-- Generate Button -->
            <button
                id="generate"
                class="w-full gradient-btn text-white font-bold py-4 md:py-5 px-6 md:px-8 rounded-xl text-base md:text-lg shadow-lg"
            >
                Generate Speech
            </button>

            <!-- Loading Bar -->
            <div id="loading-bar-container" class="hidden relative mt-6">
                <div class="loading-bar-container">
                    <div id="loading-bar" class="loading-bar"></div>
                </div>
                <div id="loading-bar-text" class="loading-bar-text">0%</div>
            </div>

            <!-- Audio Player -->
            <div id="audio-container" class="mt-6 md:mt-8 hidden">
                <div class="glass-effect p-4 md:p-6 rounded-xl">
                    <audio id="audio-player" controls class="w-full">
                        Your browser does not support the audio element.
                    </audio>
                </div>
            </div>

            <!-- Loading Spinner -->
            <div id="loading" class="hidden mt-6 md:mt-8 text-center">
                <div class="inline-block animate-spin rounded-full h-10 w-10 md:h-12 md:w-12 border-4 border-red-500 border-t-transparent"></div>
            </div>

            <!-- Error Message -->
            <div id="error" class="hidden mt-6 md:mt-8 text-red-400 text-center font-medium glass-effect p-4 md:p-6 rounded-xl">
            </div>
        </div>

        <!-- API Documentation -->
        <div class="mt-12 md:mt-16 text-center">
            <h2 class="text-2xl md:text-3xl font-bold mb-6 md:mb-8 white-text glass-effect inline-block px-6 md:px-8 py-2 md:py-3 rounded-xl">API Documentation</h2>
            <div class="content-box rounded-xl p-6 md:p-8 custom-shadow inline-block text-left hover-scale max-w-full overflow-x-auto">
                <pre class="p-4 md:p-6 rounded-xl overflow-x-auto text-white"><code class="text-sm md:text-base">POST /v1/audio/speech
{
    "model": "Pyx r1-voice",
    "input": "Your text here",
    "voice": "selected_voice"
}

Rate Limits (Free Tier):
- Requests Per Minute (RPM): 10
- Requests Per Hour (RPH): 100
- Requests Per Day (RPD): 1,000</code></pre>
            </div>
        </div>

        <!-- Footer -->
        <footer class="mt-12 md:mt-16 text-center">
            <p class="white-text text-sm md:text-base glass-effect inline-block px-4 md:px-6 py-2 md:py-3 rounded-xl">
                © 2024 PyxiLabs._.Vocify. All rights reserved.
            </p>
        </footer>
    </div>

    <script>
        const modelSelect = document.getElementById('model');
        const voiceSelect = document.getElementById('voice');
        const textInput = document.getElementById('text');
        const charCount = document.getElementById('char-count');
        const generateBtn = document.getElementById('generate');
        const audioContainer = document.getElementById('audio-container');
        const audioPlayer = document.getElementById('audio-player');
        const loading = document.getElementById('loading');
        const error = document.getElementById('error');
        const loadingBarContainer = document.getElementById('loading-bar-container');
        const loadingBar = document.getElementById('loading-bar');
        const loadingBarText = document.getElementById('loading-bar-text');

        let modelsData = {};

        async function fetchModels() {
            try {
                const response = await fetch('/v1/models');
                const data = await response.json();
                modelsData = data.models.reduce((acc, model) => {
                    acc[model.id] = model;
                    return acc;
                }, {});

                // Populate model select
                data.models.forEach(model => {
                    const option = document.createElement('option');
                    option.value = model.id;
                    option.textContent = `${model.name} (${model.owner})`;
                    modelSelect.appendChild(option);
                });

                // Initialize voices for first model
                if (data.models.length > 0) {
                    updateVoices(data.models[0].id);
                }
            } catch (err) {
                showError('Failed to load models. Please refresh the page.');
            }
        }

        function updateVoices(modelId) {
            // Clear existing voices
            voiceSelect.innerHTML = '';

            const model = modelsData[modelId];
            if (model && model.vocals) {
                model.vocals.forEach(voice => {
                    const option = document.createElement('option');
                    option.value = voice.id;
                    option.textContent = voice.id.charAt(0).toUpperCase() + voice.id.slice(1);
                    voiceSelect.appendChild(option);
                });
            }
        }

        modelSelect.addEventListener('change', (e) => {
            updateVoices(e.target.value);
        });

        textInput.addEventListener('input', () => {
            const length = textInput.value.length;
            charCount.textContent = `${length}/5000 characters`;

            if (length > 4900) {
                charCount.classList.add('text-red-400');
                charCount.classList.remove('white-text');
            } else {
                charCount.classList.remove('text-red-400');
                charCount.classList.add('white-text');
            }
        });

        generateBtn.addEventListener('click', async () => {
            const text = textInput.value.trim();
            const model = modelSelect.value;
            const voice = voiceSelect.value;

            if (!text) {
                showError('Please enter some text to convert to speech');
                return;
            }

            showLoading();
            hideError();

            let progress = 0;
            loadingBar.style.width = `${progress}%`;
            loadingBarText.textContent = `${progress}%`;

            const intervalId = setInterval(() => {
                progress += 10;
                if (progress > 95) progress = 95; // Keep it below 100 until success
                loadingBar.style.width = `${progress}%`;
                loadingBarText.textContent = `${progress}%`;
            }, 300);

            try {
                const response = await fetch('/v1/audio/speech', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        model: model,
                        input: text,
                        voice: voice
                    })
                });

                clearInterval(intervalId);

                if (!response.ok) {
                    loadingBar.style.width = `100%`;
                    loadingBarText.textContent = `Failed`;
                    throw new Error('Failed to generate speech. Please try again.');
                }

                const audioBlob = await response.blob();
                const audioUrl = URL.createObjectURL(audioBlob);

                loadingBar.style.width = `100%`;
                loadingBarText.textContent = `100%`;
                audioPlayer.src = audioUrl;
                showAudioPlayer();
                audioPlayer.play();
            } catch (err) {
                showError(err.message);
            } finally {
                if (error.classList.contains('hidden')) {
                    setTimeout(hideLoading, 500); // Keep the 100% for a bit if successful
                } else {
                    hideLoading(); // Hide immediately if there's an error
                }
            }
        });

        function showLoading() {
            loadingBarContainer.classList.remove('hidden');
            loading.classList.remove('hidden');
            generateBtn.disabled = true;
            generateBtn.classList.add('opacity-50');
        }

        function hideLoading() {
            loadingBarContainer.classList.add('hidden');
            loading.classList.add('hidden');
            generateBtn.disabled = false;
            generateBtn.classList.remove('opacity-50');
        }

        function showError(message) {
            error.textContent = message;
            error.classList.remove('hidden');
            error.scrollIntoView({ behavior: 'smooth', block: 'center' });
        }

        function hideError() {
            error.classList.add('hidden');
        }

        function showAudioPlayer() {
            audioContainer.classList.remove('hidden');
        }

        // Initialize the application
        fetchModels();
    </script>
</body>
</html>