Download web_interface.html from tahp0604/speech-to-speech-translator: direct link, hf CLI and curl.
- Browser
- Download file 18.8 kB
-
https://huggingface.co/spaces/tahp0604/speech-to-speech-translator/resolve/main/web_interface.html
- Command line
-
hf download hf://spaces/tahp0604/speech-to-speech-translator/web_interface.html
-
curl -L -o web_interface.html https://huggingface.co/spaces/tahp0604/speech-to-speech-translator/resolve/main/web_interface.html
18.8 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Speech Translation Hub</title> | |
| <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script> | |
| <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script> | |
| <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| padding: 20px; | |
| } | |
| .container { | |
| max-width: 800px; | |
| margin: 0 auto; | |
| } | |
| .header { | |
| text-align: center; | |
| color: white; | |
| margin-bottom: 40px; | |
| } | |
| .header h1 { | |
| font-size: 2.5em; | |
| margin-bottom: 10px; | |
| font-weight: 700; | |
| } | |
| .header p { | |
| font-size: 1.1em; | |
| opacity: 0.9; | |
| } | |
| .card { | |
| background: white; | |
| border-radius: 20px; | |
| padding: 40px; | |
| box-shadow: 0 20px 60px rgba(0,0,0,0.3); | |
| } | |
| .upload-zone { | |
| border: 3px dashed #667eea; | |
| border-radius: 15px; | |
| padding: 40px; | |
| text-align: center; | |
| cursor: pointer; | |
| transition: all 0.3s; | |
| background: #f8f9ff; | |
| } | |
| .upload-zone:hover { | |
| border-color: #764ba2; | |
| background: #f0f2ff; | |
| } | |
| .upload-zone.dragover { | |
| border-color: #764ba2; | |
| background: #e8ebff; | |
| transform: scale(1.02); | |
| } | |
| .upload-icon { | |
| font-size: 4em; | |
| margin-bottom: 15px; | |
| } | |
| .upload-zone h3 { | |
| color: #667eea; | |
| margin-bottom: 10px; | |
| font-size: 1.3em; | |
| } | |
| .upload-zone p { | |
| color: #666; | |
| font-size: 0.95em; | |
| } | |
| .file-input { | |
| display: none; | |
| } | |
| .language-selector { | |
| margin-top: 30px; | |
| } | |
| .language-selector label { | |
| display: block; | |
| margin-bottom: 10px; | |
| color: #333; | |
| font-weight: 600; | |
| font-size: 1.05em; | |
| } | |
| .language-selector select { | |
| width: 100%; | |
| padding: 15px; | |
| border: 2px solid #e0e0e0; | |
| border-radius: 10px; | |
| font-size: 1em; | |
| background: white; | |
| cursor: pointer; | |
| transition: all 0.3s; | |
| } | |
| .language-selector select:focus { | |
| outline: none; | |
| border-color: #667eea; | |
| } | |
| .translate-btn { | |
| width: 100%; | |
| padding: 18px; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| border: none; | |
| border-radius: 10px; | |
| font-size: 1.1em; | |
| font-weight: 600; | |
| cursor: pointer; | |
| margin-top: 25px; | |
| transition: all 0.3s; | |
| } | |
| .translate-btn:hover:not(:disabled) { | |
| transform: translateY(-2px); | |
| box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4); | |
| } | |
| .translate-btn:disabled { | |
| opacity: 0.6; | |
| cursor: not-allowed; | |
| } | |
| .status-section { | |
| margin-top: 30px; | |
| padding: 20px; | |
| background: #f8f9ff; | |
| border-radius: 10px; | |
| display: none; | |
| } | |
| .status-section.visible { | |
| display: block; | |
| } | |
| .status-header { | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| margin-bottom: 15px; | |
| } | |
| .status-badge { | |
| padding: 6px 12px; | |
| border-radius: 20px; | |
| font-size: 0.85em; | |
| font-weight: 600; | |
| } | |
| .status-badge.processing { | |
| background: #ffd93d; | |
| color: #664d03; | |
| } | |
| .status-badge.completed { | |
| background: #6bcf7f; | |
| color: #0f5132; | |
| } | |
| .status-badge.failed { | |
| background: #f56565; | |
| color: white; | |
| } | |
| .progress-bar { | |
| width: 100%; | |
| height: 8px; | |
| background: #e0e0e0; | |
| border-radius: 10px; | |
| overflow: hidden; | |
| margin: 15px 0; | |
| } | |
| .progress-fill { | |
| height: 100%; | |
| background: linear-gradient(90deg, #667eea, #764ba2); | |
| animation: progress 2s ease-in-out infinite; | |
| } | |
| @keyframes progress { | |
| 0% { width: 0%; } | |
| 50% { width: 70%; } | |
| 100% { width: 100%; } | |
| } | |
| .result-section { | |
| margin-top: 20px; | |
| } | |
| .result-item { | |
| margin-bottom: 15px; | |
| } | |
| .result-item label { | |
| display: block; | |
| font-weight: 600; | |
| color: #555; | |
| margin-bottom: 5px; | |
| font-size: 0.9em; | |
| } | |
| .result-item .text-content { | |
| padding: 12px; | |
| background: white; | |
| border-radius: 8px; | |
| border-left: 4px solid #667eea; | |
| font-size: 1.05em; | |
| line-height: 1.5; | |
| } | |
| .audio-player { | |
| width: 100%; | |
| margin-top: 10px; | |
| } | |
| .download-btn { | |
| padding: 12px 24px; | |
| background: #667eea; | |
| color: white; | |
| border: none; | |
| border-radius: 8px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| margin-top: 15px; | |
| transition: all 0.3s; | |
| } | |
| .download-btn:hover { | |
| background: #764ba2; | |
| transform: translateY(-1px); | |
| } | |
| .spinner { | |
| border: 3px solid #f3f3f3; | |
| border-top: 3px solid #667eea; | |
| border-radius: 50%; | |
| width: 30px; | |
| height: 30px; | |
| animation: spin 1s linear infinite; | |
| display: inline-block; | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| .selected-file { | |
| margin-top: 15px; | |
| padding: 15px; | |
| background: #e8f5e9; | |
| border-radius: 8px; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .selected-file .file-icon { | |
| font-size: 2em; | |
| } | |
| .selected-file .file-info { | |
| flex: 1; | |
| } | |
| .selected-file .file-name { | |
| font-weight: 600; | |
| color: #2e7d32; | |
| } | |
| .selected-file .file-size { | |
| font-size: 0.85em; | |
| color: #666; | |
| } | |
| .error-message { | |
| background: #ffebee; | |
| color: #c62828; | |
| padding: 15px; | |
| border-radius: 8px; | |
| margin-top: 15px; | |
| border-left: 4px solid #c62828; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| <script type="text/babel"> | |
| const { useState, useEffect, useRef } = React; | |
| // Configure your API endpoint | |
| const API_BASE_URL = "http://localhost:8000"; | |
| function App() { | |
| const [audioFile, setAudioFile] = useState(null); | |
| const [targetLanguage, setTargetLanguage] = useState("Hindi"); | |
| const [languages, setLanguages] = useState([]); | |
| const [jobId, setJobId] = useState(null); | |
| const [status, setStatus] = useState(null); | |
| const [result, setResult] = useState(null); | |
| const [error, setError] = useState(null); | |
| const [isProcessing, setIsProcessing] = useState(false); | |
| const [dragOver, setDragOver] = useState(false); | |
| const fileInputRef = useRef(null); | |
| useEffect(() => { | |
| // Fetch supported languages | |
| fetch(`${API_BASE_URL}/languages`) | |
| .then(res => res.json()) | |
| .then(data => setLanguages(data.supported_languages)) | |
| .catch(err => console.error("Error fetching languages:", err)); | |
| }, []); | |
| useEffect(() => { | |
| if (!jobId) return; | |
| // Poll for status | |
| const interval = setInterval(() => { | |
| fetch(`${API_BASE_URL}/status/${jobId}`) | |
| .then(res => res.json()) | |
| .then(data => { | |
| setStatus(data.status); | |
| if (data.status === "completed") { | |
| setResult(data); | |
| setIsProcessing(false); | |
| clearInterval(interval); | |
| } else if (data.status === "failed") { | |
| setError(data.error || "Translation failed"); | |
| setIsProcessing(false); | |
| clearInterval(interval); | |
| } | |
| }) | |
| .catch(err => { | |
| setError("Failed to check status"); | |
| setIsProcessing(false); | |
| clearInterval(interval); | |
| }); | |
| }, 2000); | |
| return () => clearInterval(interval); | |
| }, [jobId]); | |
| const handleFileSelect = (file) => { | |
| if (file) { | |
| setAudioFile(file); | |
| setResult(null); | |
| setError(null); | |
| setJobId(null); | |
| setStatus(null); | |
| } | |
| }; | |
| const handleDragOver = (e) => { | |
| e.preventDefault(); | |
| setDragOver(true); | |
| }; | |
| const handleDragLeave = () => { | |
| setDragOver(false); | |
| }; | |
| const handleDrop = (e) => { | |
| e.preventDefault(); | |
| setDragOver(false); | |
| const file = e.dataTransfer.files[0]; | |
| handleFileSelect(file); | |
| }; | |
| const handleTranslate = async () => { | |
| if (!audioFile || !targetLanguage) { | |
| setError("Please select an audio file and target language"); | |
| return; | |
| } | |
| setIsProcessing(true); | |
| setError(null); | |
| setResult(null); | |
| const formData = new FormData(); | |
| formData.append("audio_file", audioFile); | |
| formData.append("target_language", targetLanguage); | |
| try { | |
| const response = await fetch(`${API_BASE_URL}/translate`, { | |
| method: "POST", | |
| body: formData | |
| }); | |
| if (!response.ok) { | |
| throw new Error("Translation request failed"); | |
| } | |
| const data = await response.json(); | |
| setJobId(data.job_id); | |
| setStatus("processing"); | |
| } catch (err) { | |
| setError(err.message); | |
| setIsProcessing(false); | |
| } | |
| }; | |
| const handleDownload = () => { | |
| if (jobId) { | |
| window.open(`${API_BASE_URL}/download/${jobId}`, "_blank"); | |
| } | |
| }; | |
| const formatFileSize = (bytes) => { | |
| if (bytes < 1024) return bytes + " B"; | |
| if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + " KB"; | |
| return (bytes / (1024 * 1024)).toFixed(2) + " MB"; | |
| }; | |
| return ( | |
| <div className="container"> | |
| <div className="header"> | |
| <h1>ποΈ Speech Translation Hub</h1> | |
| <p>Translate speech from any language to your preferred language</p> | |
| </div> | |
| <div className="card"> | |
| <div | |
| className={`upload-zone ${dragOver ? 'dragover' : ''}`} | |
| onClick={() => fileInputRef.current?.click()} | |
| onDragOver={handleDragOver} | |
| onDragLeave={handleDragLeave} | |
| onDrop={handleDrop} | |
| > | |
| <div className="upload-icon">π΅</div> | |
| <h3>Upload Audio File</h3> | |
| <p>Click to browse or drag and drop</p> | |
| <p style={{marginTop: '5px', fontSize: '0.85em'}}> | |
| Supported: WAV, MP3, M4A, FLAC | |
| </p> | |
| <input | |
| ref={fileInputRef} | |
| type="file" | |
| className="file-input" | |
| accept="audio/*" | |
| onChange={(e) => handleFileSelect(e.target.files[0])} | |
| /> | |
| </div> | |
| {audioFile && ( | |
| <div className="selected-file"> | |
| <div className="file-icon">π</div> | |
| <div className="file-info"> | |
| <div className="file-name">{audioFile.name}</div> | |
| <div className="file-size">{formatFileSize(audioFile.size)}</div> | |
| </div> | |
| </div> | |
| )} | |
| <div className="language-selector"> | |
| <label>Target Language:</label> | |
| <select | |
| value={targetLanguage} | |
| onChange={(e) => setTargetLanguage(e.target.value)} | |
| > | |
| {languages.map(lang => ( | |
| <option key={lang} value={lang}>{lang}</option> | |
| ))} | |
| </select> | |
| </div> | |
| <button | |
| className="translate-btn" | |
| onClick={handleTranslate} | |
| disabled={!audioFile || isProcessing} | |
| > | |
| {isProcessing ? ( | |
| <> | |
| <span className="spinner" style={{marginRight: '10px'}}></span> | |
| Translating... | |
| </> | |
| ) : ( | |
| "π Start Translation" | |
| )} | |
| </button> | |
| {error && ( | |
| <div className="error-message"> | |
| β {error} | |
| </div> | |
| )} | |
| <div className={`status-section ${status ? 'visible' : ''}`}> | |
| <div className="status-header"> | |
| <h3>Translation Status:</h3> | |
| <span className={`status-badge ${status}`}> | |
| {status === "processing" && "β³ Processing"} | |
| {status === "completed" && "β Completed"} | |
| {status === "failed" && "β Failed"} | |
| </span> | |
| </div> | |
| {status === "processing" && ( | |
| <div className="progress-bar"> | |
| <div className="progress-fill"></div> | |
| </div> | |
| )} | |
| {result && ( | |
| <div className="result-section"> | |
| <div className="result-item"> | |
| <label>π Detected Language:</label> | |
| <div className="text-content"> | |
| {result.detected_language} | |
| </div> | |
| </div> | |
| <div className="result-item"> | |
| <label>π Original Text:</label> | |
| <div className="text-content"> | |
| {result.source_text} | |
| </div> | |
| </div> | |
| <div className="result-item"> | |
| <label>π Translated Text ({targetLanguage}):</label> | |
| <div className="text-content"> | |
| {result.translated_text} | |
| </div> | |
| </div> | |
| <div className="result-item"> | |
| <label>π Translated Audio:</label> | |
| <audio | |
| controls | |
| className="audio-player" | |
| src={`${API_BASE_URL}/download/${jobId}`} | |
| /> | |
| </div> | |
| <button | |
| className="download-btn" | |
| onClick={handleDownload} | |
| > | |
| β¬οΈ Download Audio | |
| </button> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| ReactDOM.render(<App />, document.getElementById('root')); | |
| </script> | |
| </body> | |
| </html> | |