mirror of
https://github.com/mudler/LocalAI.git
synced 2025-03-20 19:15:22 +00:00
Some checks failed
Explorer deployment / build-linux (push) Waiting to run
GPU tests / ubuntu-latest (1.21.x) (push) Waiting to run
generate and publish intel docker caches / generate_caches (intel/oneapi-basekit:2025.0.0-0-devel-ubuntu22.04, linux/amd64, ubuntu-latest) (push) Waiting to run
build container images / hipblas-jobs (-aio-gpu-hipblas, rocm/dev-ubuntu-22.04:6.1, hipblas, true, ubuntu:22.04, extras, latest-gpu-hipblas, latest-aio-gpu-hipblas, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -hipblas-ffmpeg) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas-core) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, false, ubuntu:22.04, extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-22.04:6.1, hipblas, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -hipblas-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-intel-f16, quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, true, ubuntu:22.04, extras, latest-gpu-intel-f16, latest-aio-gpu-intel-f16, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -sycl-f16-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-intel-f32, quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, true, ubuntu:22.04, extras, latest-gpu-intel-f32, latest-aio-gpu-intel-f32, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -sycl-f32-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-nvidia-cuda-11, ubuntu:22.04, cublas, 11, 7, true, extras, latest-gpu-nvidia-cuda-11, latest-aio-gpu-nvidia-cuda-11, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -cublas-cuda11-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (-aio-gpu-nvidia-cuda-12, ubuntu:22.04, cublas, 12, 0, true, extras, latest-gpu-nvidia-cuda-12, latest-aio-gpu-nvidia-cuda-12, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -cublas-cuda12-ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f16-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f16, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f16-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, false, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f32-core) (push) Waiting to run
build container images / self-hosted-jobs (quay.io/go-skynet/intel-oneapi-base:latest, sycl_f32, true, ubuntu:22.04, core, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -sycl-f32-ffmpeg-core) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, , , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, ) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, , true, extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, auto, -ffmpeg) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, cublas, 11, 7, , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -cublas-cuda11) (push) Waiting to run
build container images / self-hosted-jobs (ubuntu:22.04, cublas, 12, 0, , extras, --jobs=3 --output-sync=target, linux/amd64, arc-runner-set, false, -cublas-cuda12) (push) Waiting to run
build container images / core-image-build (-aio-cpu, ubuntu:22.04, , true, core, latest-cpu, latest-aio-cpu, --jobs=4 --output-sync=target, linux/amd64,linux/arm64, arc-runner-set, false, auto, -ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 11, 7, , core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda11-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 11, 7, true, core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda11-ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 12, 0, , core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda12-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 12, 0, true, core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -cublas-cuda12-ffmpeg-core) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, vulkan, true, core, latest-vulkan-ffmpeg-core, --jobs=4 --output-sync=target, linux/amd64, arc-runner-set, false, false, -vulkan-ffmpeg-core) (push) Waiting to run
build container images / gh-runner (nvcr.io/nvidia/l4t-jetpack:r36.4.0, cublas, 12, 0, true, core, latest-nvidia-l4t-arm64-core, --jobs=4 --output-sync=target, linux/arm64, ubuntu-24.04-arm, true, false, -nvidia-l4t-arm64-core) (push) Waiting to run
Security Scan / tests (push) Waiting to run
Tests extras backends / tests-transformers (push) Waiting to run
Tests extras backends / tests-rerankers (push) Waiting to run
Tests extras backends / tests-diffusers (push) Waiting to run
Tests extras backends / tests-coqui (push) Waiting to run
tests / tests-linux (1.21.x) (push) Waiting to run
tests / tests-aio-container (push) Waiting to run
tests / tests-apple (1.21.x) (push) Waiting to run
generate and publish GRPC docker caches / generate_caches (ubuntu:22.04, linux/amd64,linux/arm64, arc-runner-set) (push) Has been cancelled
* chore(ui): drop set api key button Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(ui): shore in-progress installs in model view Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): improve text to image view Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
204 lines
7.5 KiB
JavaScript
204 lines
7.5 KiB
JavaScript
// Initialize Alpine store for API key management
|
|
document.addEventListener('alpine:init', () => {
|
|
Alpine.store('chat', { });
|
|
});
|
|
|
|
function genAudio(event) {
|
|
event.preventDefault();
|
|
const input = document.getElementById("input").value;
|
|
|
|
if (!input.trim()) {
|
|
showNotification('error', 'Please enter text to convert to speech');
|
|
return;
|
|
}
|
|
|
|
tts(input);
|
|
}
|
|
|
|
function showNotification(type, message) {
|
|
// Remove any existing notification
|
|
const existingNotification = document.getElementById('notification');
|
|
if (existingNotification) {
|
|
existingNotification.remove();
|
|
}
|
|
|
|
// Create new notification
|
|
const notification = document.createElement('div');
|
|
notification.id = 'notification';
|
|
notification.classList.add(
|
|
'fixed', 'top-24', 'right-4', 'z-50', 'p-4', 'rounded-lg', 'shadow-lg',
|
|
'transform', 'transition-all', 'duration-300', 'ease-in-out', 'translate-y-0',
|
|
'flex', 'items-center', 'gap-2'
|
|
);
|
|
|
|
// Style based on notification type
|
|
if (type === 'error') {
|
|
notification.classList.add('bg-red-900/90', 'border', 'border-red-700', 'text-red-200');
|
|
notification.innerHTML = '<i class="fas fa-circle-exclamation text-red-400 mr-2"></i>' + message;
|
|
} else if (type === 'warning') {
|
|
notification.classList.add('bg-yellow-900/90', 'border', 'border-yellow-700', 'text-yellow-200');
|
|
notification.innerHTML = '<i class="fas fa-triangle-exclamation text-yellow-400 mr-2"></i>' + message;
|
|
} else if (type === 'success') {
|
|
notification.classList.add('bg-green-900/90', 'border', 'border-green-700', 'text-green-200');
|
|
notification.innerHTML = '<i class="fas fa-circle-check text-green-400 mr-2"></i>' + message;
|
|
} else {
|
|
notification.classList.add('bg-blue-900/90', 'border', 'border-blue-700', 'text-blue-200');
|
|
notification.innerHTML = '<i class="fas fa-circle-info text-blue-400 mr-2"></i>' + message;
|
|
}
|
|
|
|
// Add close button
|
|
const closeBtn = document.createElement('button');
|
|
closeBtn.innerHTML = '<i class="fas fa-xmark"></i>';
|
|
closeBtn.classList.add('ml-auto', 'text-gray-400', 'hover:text-white', 'transition-colors');
|
|
closeBtn.onclick = () => {
|
|
notification.classList.add('opacity-0', 'translate-y-[-20px]');
|
|
setTimeout(() => notification.remove(), 300);
|
|
};
|
|
notification.appendChild(closeBtn);
|
|
|
|
// Add to DOM
|
|
document.body.appendChild(notification);
|
|
|
|
// Animate in
|
|
setTimeout(() => {
|
|
notification.classList.add('opacity-0', 'translate-y-[-20px]');
|
|
notification.offsetHeight; // Force reflow
|
|
notification.classList.remove('opacity-0', 'translate-y-[-20px]');
|
|
}, 10);
|
|
|
|
// Auto dismiss after 5 seconds
|
|
setTimeout(() => {
|
|
if (document.getElementById('notification')) {
|
|
notification.classList.add('opacity-0', 'translate-y-[-20px]');
|
|
setTimeout(() => notification.remove(), 300);
|
|
}
|
|
}, 5000);
|
|
}
|
|
|
|
async function tts(input) {
|
|
// Show loader and prepare UI
|
|
const loader = document.getElementById("loader");
|
|
const inputField = document.getElementById("input");
|
|
const resultDiv = document.getElementById("result");
|
|
|
|
loader.style.display = "block";
|
|
inputField.value = "";
|
|
inputField.disabled = true;
|
|
resultDiv.innerHTML = '<div class="text-center text-gray-400 italic">Processing your request...</div>';
|
|
|
|
// Get the model and make API request
|
|
const model = document.getElementById("tts-model").value;
|
|
try {
|
|
const response = await fetch("tts", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
model: model,
|
|
input: input,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const jsonData = await response.json();
|
|
resultDiv.innerHTML = `
|
|
<div class="bg-red-900/30 border border-red-700/50 rounded-lg p-4 text-center">
|
|
<i class="fas fa-circle-exclamation text-red-400 text-2xl mb-2"></i>
|
|
<p class="text-red-300 font-medium">${jsonData.error.message || 'An error occurred'}</p>
|
|
</div>
|
|
`;
|
|
showNotification('error', 'Failed to generate audio');
|
|
return;
|
|
}
|
|
|
|
// Handle successful response
|
|
const blob = await response.blob();
|
|
const audioUrl = window.URL.createObjectURL(blob);
|
|
|
|
// Create audio player
|
|
const audioPlayer = document.createElement('div');
|
|
audioPlayer.className = 'flex flex-col items-center space-y-4 w-full';
|
|
|
|
// Create audio element with styled controls
|
|
const audio = document.createElement('audio');
|
|
audio.controls = true;
|
|
audio.src = audioUrl;
|
|
audio.className = 'w-full my-4';
|
|
audioPlayer.appendChild(audio);
|
|
|
|
// Create action buttons container
|
|
const actionButtons = document.createElement('div');
|
|
actionButtons.className = 'flex flex-wrap justify-center gap-3';
|
|
|
|
// Download button
|
|
const downloadLink = document.createElement('a');
|
|
downloadLink.href = audioUrl;
|
|
downloadLink.download = `tts-${model}-${new Date().toISOString().slice(0, 10)}.mp3`;
|
|
downloadLink.className = 'group flex items-center bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg';
|
|
downloadLink.innerHTML = `
|
|
<i class="fas fa-download mr-2"></i>
|
|
<span>Download</span>
|
|
<i class="fas fa-arrow-right opacity-0 group-hover:opacity-100 group-hover:translate-x-2 ml-2 transition-all duration-300"></i>
|
|
`;
|
|
actionButtons.appendChild(downloadLink);
|
|
|
|
// Replay button
|
|
const replayButton = document.createElement('button');
|
|
replayButton.className = 'group flex items-center bg-purple-600 hover:bg-purple-700 text-white py-2 px-4 rounded-lg transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg';
|
|
replayButton.innerHTML = `
|
|
<i class="fas fa-rotate-right mr-2"></i>
|
|
<span>Replay</span>
|
|
`;
|
|
replayButton.onclick = () => audio.play();
|
|
actionButtons.appendChild(replayButton);
|
|
|
|
// Add text display
|
|
const textDisplay = document.createElement('div');
|
|
textDisplay.className = 'mt-4 p-4 bg-gray-800/50 border border-gray-700/50 rounded-lg text-gray-300 text-center italic';
|
|
textDisplay.textContent = `"${input}"`;
|
|
|
|
// Add all elements to result div
|
|
audioPlayer.appendChild(actionButtons);
|
|
resultDiv.innerHTML = '';
|
|
resultDiv.appendChild(audioPlayer);
|
|
resultDiv.appendChild(textDisplay);
|
|
|
|
// Play audio automatically
|
|
audio.play();
|
|
|
|
// Show success notification
|
|
showNotification('success', 'Audio generated successfully');
|
|
|
|
} catch (error) {
|
|
console.error('Error generating audio:', error);
|
|
resultDiv.innerHTML = `
|
|
<div class="bg-red-900/30 border border-red-700/50 rounded-lg p-4 text-center">
|
|
<i class="fas fa-circle-exclamation text-red-400 text-2xl mb-2"></i>
|
|
<p class="text-red-300 font-medium">Network error: Failed to connect to the server</p>
|
|
</div>
|
|
`;
|
|
showNotification('error', 'Network error occurred');
|
|
} finally {
|
|
// Reset UI state
|
|
loader.style.display = "none";
|
|
inputField.disabled = false;
|
|
inputField.focus();
|
|
}
|
|
}
|
|
|
|
// Set up event listeners when DOM is loaded
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
document.getElementById("input").focus();
|
|
document.getElementById("tts").addEventListener("submit", genAudio);
|
|
document.getElementById("loader").style.display = "none";
|
|
|
|
// Add basic keyboard shortcuts
|
|
document.addEventListener('keydown', (e) => {
|
|
// Submit on Ctrl+Enter
|
|
if (e.key === 'Enter' && e.ctrlKey && document.activeElement.id === 'input') {
|
|
e.preventDefault();
|
|
document.getElementById("tts").dispatchEvent(new Event('submit'));
|
|
}
|
|
});
|
|
}); |