PyxiLabs's picture
Update templates/index.html
32f5a26 verified
raw
history blame
22.7 kB
<!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">
<style>
/* Root Variables */
:root {
--gradient-start: #ff0066;
--gradient-end: #3366ff;
}
/* Base Styles */
body {
background-image: url('static/bg3.png');
background-size: cover;
background-position: center;
background-attachment: fixed;
min-height: 100vh;
}
/* Text Effects */
.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);
}
.text-shadow {
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.white-text {
color: rgba(255, 255, 255, 0.9);
}
/* Container Effects */
.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);
}
.glass-effect {
background: rgba(0, 0, 0, 0.1);
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);
}
/* Form Elements */
.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);
}
select option {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
.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));
}
/* Code Block Styles */
pre {
background: rgba(0, 0, 0, 0.1) !important;
backdrop-filter: blur(4px);
white-space: pre-wrap;
word-wrap: break-word;
}
/* Audio Player Styles */
.audio-player {
background: rgba(0, 0, 0, 0.2);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 16px;
padding: 20px;
color: white;
}
.progress-bar {
width: 100%;
height: 5px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
cursor: pointer;
position: relative;
}
.progress {
height: 100%;
background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
border-radius: 10px;
transition: width 0.1s linear;
}
.progress-handle {
width: 12px;
height: 12px;
background: white;
border-radius: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
pointer-events: none;
}
.time-display {
font-family: monospace;
font-size: 14px;
color: rgba(255, 255, 255, 0.8);
}
.control-button {
width: 40px;
height: 40px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: white;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.2s ease;
}
.control-button:hover {
background: rgba(255, 255, 255, 0.2);
transform: scale(1.05);
}
.volume-slider {
width: 100px;
height: 4px;
background: rgba(255, 255, 255, 0.1);
border-radius: 2px;
cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 12px;
height: 12px;
background: white;
border-radius: 50%;
cursor: pointer;
}
.download-button {
background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
color: white;
padding: 8px 16px;
border-radius: 8px;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s ease;
}
.download-button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
/* Loading Spinner */
.spinner {
width: 40px;
height: 40px;
border: 3px solid rgba(255, 255, 255, 0.1);
border-radius: 50%;
border-top-color: #ff0066;
animation: spin 1s linear infinite;
}
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.audio-player {
padding: 15px;
}
.control-button {
width: 36px;
height: 36px;
}
.volume-slider {
width: 80px;
}
.download-button {
padding: 6px 12px;
}
}
/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
.hover-scale,
.gradient-btn,
.control-button,
.download-button {
transition: none;
}
.spinner {
animation: none;
}
}
/* High Contrast Mode */
@media (prefers-contrast: high) {
.glass-effect,
.content-box,
.input-dark {
background: rgba(0, 0, 0, 0.8);
backdrop-filter: none;
}
.gradient-text {
background: none;
color: white;
}
}
</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 Spinner -->
<div id="loading" class="hidden flex justify-center items-center p-8">
<div class="spinner"></div>
</div>
<!-- Audio Player -->
<div id="audio-container" class="hidden mt-6">
<div class="audio-player">
<div class="flex items-center gap-4 mb-4">
<button id="playPauseBtn" class="control-button">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M8 5v14l11-7z"/>
</svg>
</button>
<div class="flex-grow">
<div class="progress-bar" id="progressBar">
<div class="progress" id="progress"></div>
<div class="progress-handle" id="progressHandle"></div>
</div>
<div class="flex justify-between mt-1">
<span class="time-display" id="currentTime">0:00</span>
<span class="time-display" id="duration">0:00</span>
</div>
</div>
<div class="flex items-center gap-2">
<button id="muteBtn" class="control-button">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
<path d="M16 8c1 1 1.5 2.5 1.5 4s-.5 3-1.5 4"/>
<path d="M19 5c2 2 3 4.5 3 7s-1 5-3 7"/>
</svg>
</button>
<input type="range" class="volume-slider" id="volumeSlider" min="0" max="100" value="100">
</div>
<button id="downloadBtn" class="download-button">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
<path d="M3 17h18M10 4v10m0 0l4-4m-4 4l-4-4"/>
</svg>
Download
</button>
</div>
<audio id="audio-player" class="hidden"></audio>
</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');
// Audio Player Controls
const playPauseBtn = document.getElementById('playPauseBtn');
const muteBtn = document.getElementById('muteBtn');
const volumeSlider = document.getElementById('volumeSlider');
const progressBar = document.getElementById('progressBar');
const progress = document.getElementById('progress');
const progressHandle = document.getElementById('progressHandle');
const currentTimeDisplay = document.getElementById('currentTime');
const durationDisplay = document.getElementById('duration');
const downloadBtn = document.getElementById('downloadBtn');
let modelsData = {};
// Initialize the application
fetchModels();
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');
}
});
generate.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
}
}
});
// Audio Player Controls
playPauseBtn.addEventListener('click', () => {
if (audioPlayer.paused) {
audioPlayer.play();
playPauseBtn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M8 5h3v14H8zm5 0h3v14h-3z"/>
</svg>
`;
} else {
audioPlayer.pause();
playPauseBtn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M8 5v14l11-7z"/>
</svg>
`;
}
});
// Update progress bar
audioPlayer.addEventListener('timeupdate', () => {
const percentage = (audioPlayer.currentTime / audioPlayer.duration) * 100;
progress.style.width = `${percentage}%`;
progressHandle.style.left = `${percentage}%`;
currentTimeDisplay.textContent = formatTime(audioPlayer.currentTime);
});
// Click on progress bar
progressBar.addEventListener('click', (e) => {
const rect = progressBar.getBoundingClientRect();
const percentage = (e.clientX - rect.left) / rect.width;
audioPlayer.currentTime = percentage * audioPlayer.duration;
});
// Volume control
volumeSlider.addEventListener('input', (e) => {
audioPlayer.volume = e.target.value / 100;
updateMuteButton();
});
// Mute toggle
muteBtn.addEventListener('click', () => {
audioPlayer.muted = !audioPlayer.muted;
updateMuteButton();
});
// Duration display
audioPlayer.addEventListener('loadedmetadata', () => {
durationDisplay.textContent = formatTime(audioPlayer.duration);
});
// Download functionality
downloadBtn.addEventListener('click', () => {
const audioUrl = audioPlayer.src;
const a = document.createElement('a');
a.href = audioUrl;
a.download = 'generated-speech.mp3';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
// Helper functions
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`;
}
function updateMuteButton() {
if (audioPlayer.muted || audioPlayer.volume === 0) {
muteBtn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
<path d="M18 7l-4 4m0-4l4 4"/>
</svg>
`;
} else {
muteBtn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" stroke="currentColor">
<path d="M8 4l6-4v20l-6-4H2V8h6z"/>
<path d="M16 8c1 1 1.5 2.5 1.5 4s-.5 3-1.5 4"/>
<path d="M19 5c2 2 3 4.5 3 7s-1 5-3 7"/>
</svg>
`;
}
}
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');
}
</script>
</body>
</html>