Spaces:
Sleeping
Sleeping
Download static/script.js from Skinnyeggs/auto-caption: direct link, hf CLI and curl.
- Browser
- Download file 3.74 kB
-
https://huggingface.co/spaces/Skinnyeggs/auto-caption/resolve/main/static/script.js
- Command line
-
hf download hf://spaces/Skinnyeggs/auto-caption/static/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Skinnyeggs/auto-caption/resolve/main/static/script.js
3.74 kB
| const dropZone = document.getElementById('drop-zone'); | |
| const fileInput = document.getElementById('file-input'); | |
| const processingInfo = document.getElementById('processing-info'); | |
| const resultContainer = document.getElementById('result-container'); | |
| const progressBar = document.getElementById('progress-bar'); | |
| const statusText = document.getElementById('status-text'); | |
| const transcriptPreview = document.getElementById('transcript-preview'); | |
| const transcriptContent = document.getElementById('transcript-content'); | |
| let currentFileData = null; | |
| // Drag and Drop | |
| dropZone.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| dropZone.classList.add('drag-over'); | |
| }); | |
| dropZone.addEventListener('dragleave', () => { | |
| dropZone.classList.remove('drag-over'); | |
| }); | |
| dropZone.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| dropZone.classList.remove('drag-over'); | |
| const file = e.dataTransfer.files[0]; | |
| if (file && file.type.startsWith('video/')) { | |
| handleFileUpload(file); | |
| } else { | |
| alert('Please upload a valid video file.'); | |
| } | |
| }); | |
| dropZone.addEventListener('click', () => fileInput.click()); | |
| fileInput.addEventListener('change', (e) => { | |
| const file = e.target.files[0]; | |
| if (file) handleFileUpload(file); | |
| }); | |
| async function handleFileUpload(file) { | |
| dropZone.classList.add('hidden'); | |
| processingInfo.classList.remove('hidden'); | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| try { | |
| statusText.innerText = "Transcribing with AI... This may take a minute."; | |
| updateProgress(30); | |
| const response = await fetch('/process', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| if (!response.ok) throw new Error('Upload failed'); | |
| const result = await response.json(); | |
| currentFileData = result; | |
| updateProgress(100); | |
| showResults(result); | |
| } catch (error) { | |
| console.error(error); | |
| alert('Error processing video: ' + error.message); | |
| resetUI(); | |
| } | |
| } | |
| function updateProgress(percent) { | |
| progressBar.style.width = percent + '%'; | |
| } | |
| function showResults(result) { | |
| processingInfo.classList.add('hidden'); | |
| resultContainer.classList.remove('hidden'); | |
| document.getElementById('download-srt').onclick = () => { | |
| window.location.href = `/download/${result.srt_filename}`; | |
| }; | |
| document.getElementById('preview-btn').onclick = () => { | |
| renderTranscript(result.transcript); | |
| transcriptPreview.classList.remove('hidden'); | |
| }; | |
| } | |
| function renderTranscript(transcript) { | |
| transcriptContent.innerHTML = ''; | |
| transcript.forEach(line => { | |
| const div = document.createElement('div'); | |
| div.className = 'transcript-line'; | |
| div.innerHTML = ` | |
| <span class="time">${formatTime(line.start)}</span> | |
| <span class="text">${line.text}</span> | |
| `; | |
| transcriptContent.appendChild(div); | |
| }); | |
| } | |
| function formatTime(seconds) { | |
| const h = Math.floor(seconds / 3600); | |
| const m = Math.floor((seconds % 3600) / 60); | |
| const s = Math.floor(seconds % 60); | |
| const ms = Math.floor((seconds % 1) * 1000); | |
| return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}.${ms.toString().padStart(3, '0')}`; | |
| } | |
| function resetUI() { | |
| dropZone.classList.remove('hidden'); | |
| processingInfo.classList.add('hidden'); | |
| resultContainer.classList.add('hidden'); | |
| transcriptPreview.classList.add('hidden'); | |
| progressBar.style.width = '0%'; | |
| fileInput.value = ''; | |
| } | |
| document.getElementById('reset-btn').onclick = resetUI; | |
| document.getElementById('close-preview').onclick = () => transcriptPreview.classList.add('hidden'); | |