Spaces:
Running
Running
Download translator.html from Aichatbot12321/Transaltor: direct link, hf CLI and curl.
- Browser
- Download file 17.6 kB
-
https://huggingface.co/spaces/Aichatbot12321/Transaltor/resolve/main/translator.html
- Command line
-
hf download hf://spaces/Aichatbot12321/Transaltor/translator.html
-
curl -L -o translator.html https://huggingface.co/spaces/Aichatbot12321/Transaltor/resolve/main/translator.html
17.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>AI Pro Suite - Text Translator</title> | |
| <link rel="manifest" href="/manifest.json"> | |
| <meta name="theme-color" content="#0f172a"> | |
| <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.10.0/localforage.min.js"></script> | |
| <link rel="stylesheet" href="style.css"> | |
| </head> | |
| <body> | |
| <div class="overlay" id="overlay"></div> | |
| <div class="topbar"> | |
| <div class="menuBtn" onclick="toggleSidebar()">☰</div> | |
| <div class="appTitle">AI Pro Suite</div> | |
| </div> | |
| <div class="apiTracker"> | |
| <div>⏱️ Reset: <span id="apiTimer" class="api-val timer">60s</span></div> | |
| <div>🖼️ Vis: <span id="apiVision" class="api-val vision">0</span>/20</div> | |
| <div>📝 Txt: <span id="apiText" class="api-val text">0</span>/20</div> | |
| </div> | |
| <div id="ttsPlayer"> | |
| <div class="ttsIndicator">🔊 Reading</div> | |
| <button class="ttsBtn" id="ttsPlayBtn">⏸️</button> | |
| <button class="ttsBtn" id="ttsStopBtn">⏹️</button> | |
| <button class="ttsBtn" id="ttsCloseBtn">✖️</button> | |
| </div> | |
| <div class="sidebar" id="sidebar" style="overflow-y:auto;"> | |
| <button class="sidebar-close-btn" onclick="toggleSidebar()">✖ Close Menu</button> | |
| <button onclick="window.location.href='index.html'">🏠 Dashboard</button> | |
| <button onclick="window.location.href='lens.html'">✨ Lens Studio</button> | |
| <button onclick="window.location.href='books.html'">📚 Book Deep Study</button> | |
| <button onclick="window.location.href='maths.html'">🧮 Math Solver</button> | |
| <button onclick="window.location.href='search.html'">🔎 Deep Search</button> | |
| <button onclick="window.location.href='downloader.html'">📥 Video Downloader</button> | |
| <button onclick="window.location.href='board.html'">📋 Whiteboard</button> | |
| <button onclick="window.location.href='clone.html'">📑 Website Cloner</button> | |
| <button onclick="window.location.href='runhtml.html'">🌐 Write HTML</button> | |
| <button onclick="window.location.href='youtube.html'">▶️ YouTube Search</button> | |
| <button onclick="window.location.href='managequiz.html'">⚙️ Manage Quiz</button> | |
| <button onclick="window.location.href='tutor.html'">👨🏫 AI Tutor</button> | |
| <button onclick="window.location.href='quiz.html'">📝 Take a Quiz!</button> | |
| <button onclick="window.location.href='book_quiz.html'">📝 Take a Book Quiz!</button> | |
| <button onclick="window.location.href='tables.html'">🔢 Maths Table</button> | |
| <button onclick="window.location.href='coding.html'">💻 AI Coding</button> | |
| <button onclick="window.location.href='chess.html'">♟️ Chess AI</button> | |
| <button onclick="window.location.href='translator.html'" style="border-left: 4px solid var(--primary); color: var(--primary); background: var(--border-light);">🎙️ Text Translator</button> | |
| <button onclick="window.location.href='image.html'">🖼️ Image Translator</button> | |
| <button onclick="window.location.href='create.html'">🎨 Image Creator</button> | |
| <button onclick="window.location.href='qa.html'">📚 Document Q&A</button> | |
| <button onclick="window.location.href='history.html'">🕒 History & Downloads</button> | |
| <button onclick="window.location.href='storage.html'">📂 Storage</button> | |
| <button onclick="window.location.href='hub.html'">🛰️ HF Command Center</button> | |
| <button onclick="window.location.href='live.html'">🗣️ Gemini Live</button> | |
| </div> | |
| <style> | |
| /* This page had almost no dedicated styling before - mic button and voice | |
| header were relying on bare browser defaults. Scoped to this page only. */ | |
| #translatorPage .voiceHeader { display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; } | |
| #translatorPage .micBtn { | |
| width:52px; height:52px; border-radius:50%; border:none; cursor:pointer; font-size:20px; | |
| background:linear-gradient(135deg, var(--primary), var(--secondary)); color:#fff; | |
| box-shadow:0 6px 16px var(--primary-glow); transition:transform .2s ease, box-shadow .2s ease; | |
| display:flex; align-items:center; justify-content:center; flex-shrink:0; | |
| } | |
| #translatorPage .micBtn:hover { transform:scale(1.07); } | |
| #translatorPage .micBtn.recording { background:linear-gradient(135deg, #ef4444, #b91c1c); animation:pulse 0.8s infinite alternate; box-shadow:0 6px 20px rgba(239,68,68,0.6); } | |
| #translatorPage .recordingHint { font-size:12px; color:#ef4444; font-weight:700; text-align:center; margin:-6px 0 12px; display:none; align-items:center; justify-content:center; gap:6px; } | |
| #translatorPage .recordingHint.active { display:flex; } | |
| #translatorPage .charCount { font-size:11px; color:var(--text-muted); text-align:right; margin-top:-8px; margin-bottom:10px; } | |
| #translatorPage select.standard, #translatorPage select { width:100%; margin-bottom:14px; } | |
| #translatorPage #convertBtn { display:flex; align-items:center; justify-content:center; gap:8px; } | |
| #translatorPage #convertBtn:disabled { opacity:0.75; cursor:not-allowed; } | |
| #translatorPage .hardWordsCard { background:rgba(168,85,247,0.08); border:1px solid rgba(168,85,247,0.3); border-radius:16px; padding:14px 16px; margin-top:16px; display:none; } | |
| #translatorPage .hardWordsCard .cardTitle { color:#a855f7; margin-bottom:8px; } | |
| #translatorPage #hardWords { font-size:14px; line-height:1.8; } | |
| </style> | |
| <div class="page active" id="translatorPage"> | |
| <div class="card" style="background:linear-gradient(135deg,#f59e0b,#d97706); border:none; text-align:center;"> | |
| <h1 style="font-size: 24px;">🎙️ Voice & Text Translator</h1> | |
| <p style="font-size: 14px; opacity: 0.9;">Speak or type to instantly translate.</p> | |
| </div> | |
| <div class="card"> | |
| <div class="voiceHeader"> | |
| <div><div class="cardTitle" style="margin-bottom:0;">Input Text</div></div> | |
| <button class="micBtn" id="micBtn" onclick="toggleRecording()" title="Speak your text">🎤</button> | |
| </div> | |
| <div class="recordingHint" id="recordingHint">🔴 Listening... tap the mic again to stop</div> | |
| <select id="voiceSourceLang" style="margin-bottom: 10px;"> | |
| <option value="hi-IN">Speak in: Hindi</option> | |
| <option value="en-US">Speak in: English</option> | |
| </select> | |
| <textarea class="standard" id="inputText" placeholder="Speak into the mic or type your text here..." oninput="document.getElementById('inputCharCount').innerText = this.value.length + ' characters'"></textarea> | |
| <div class="charCount" id="inputCharCount">0 characters</div> | |
| <div class="cardTitle" style="margin-top: 15px;">Translate Into:</div> | |
| <select id="targetLang"> | |
| <option>Hindi</option> | |
| <option>English</option> | |
| <option>French</option> | |
| <option>Spanish</option> | |
| <option>German</option> | |
| <option>Japanese</option> | |
| </select> | |
| <button class="btn blue" id="convertBtn" onclick="runTranslation()">🌍 Convert</button> | |
| <div class="cardTitle" style="margin-top: 20px;">Translation Output:</div> | |
| <div class="status" id="translatedTextStatus" style="display:none; margin-bottom:10px;"></div> | |
| <div class="outputBox" id="translatedText" style="min-height: 100px;">Translation will appear here...</div> | |
| <div class="hardWordsCard" id="hardWordsCard"> | |
| <div class="cardTitle">📖 Hard Words from Original Text</div> | |
| <div id="hardWords"></div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // 🎤 Voice input - was completely non-functional before (called but never defined). | |
| let __translatorRecognition = null; | |
| let __translatorRecording = false; | |
| function toggleRecording() { | |
| const micBtn = document.getElementById('micBtn'); | |
| const hint = document.getElementById('recordingHint'); | |
| const SpeechRecognitionAPI = window.SpeechRecognition || window.webkitSpeechRecognition; | |
| if (!SpeechRecognitionAPI) { | |
| if (typeof showToast === 'function') showToast("🎤 Voice input isn't supported in this browser. Try Chrome."); | |
| else alert("Voice input isn't supported in this browser. Try Chrome."); | |
| return; | |
| } | |
| if (__translatorRecording) { | |
| __translatorRecognition.stop(); | |
| return; | |
| } | |
| const inputBox = document.getElementById('inputText'); | |
| const baseText = inputBox.value.trim() ? inputBox.value.trim() + ' ' : ''; | |
| __translatorRecognition = new SpeechRecognitionAPI(); | |
| __translatorRecognition.lang = document.getElementById('voiceSourceLang').value || 'en-US'; | |
| __translatorRecognition.interimResults = true; | |
| __translatorRecognition.continuous = true; | |
| __translatorRecognition.onstart = () => { | |
| __translatorRecording = true; | |
| micBtn.classList.add('recording'); | |
| micBtn.innerText = '⏹️'; | |
| if (hint) hint.classList.add('active'); | |
| }; | |
| __translatorRecognition.onresult = (event) => { | |
| let interim = '', final = ''; | |
| for (let i = event.resultIndex; i < event.results.length; i++) { | |
| if (event.results[i].isFinal) final += event.results[i][0].transcript; | |
| else interim += event.results[i][0].transcript; | |
| } | |
| inputBox.value = baseText + final + interim; | |
| document.getElementById('inputCharCount').innerText = inputBox.value.length + ' characters'; | |
| }; | |
| __translatorRecognition.onerror = (event) => { | |
| console.error('Speech recognition error:', event.error); | |
| if (event.error === 'not-allowed' && typeof showToast === 'function') showToast("🎤 Microphone access was blocked."); | |
| }; | |
| __translatorRecognition.onend = () => { | |
| __translatorRecording = false; | |
| micBtn.classList.remove('recording'); | |
| micBtn.innerText = '🎤'; | |
| if (hint) hint.classList.remove('active'); | |
| }; | |
| __translatorRecognition.start(); | |
| } | |
| // 🔊 Thin wrapper so any leftover callers of speakText keep working via the shared engine. | |
| function speakText(elementId) { | |
| if (typeof speakAndHighlight === 'function') speakAndHighlight(elementId); | |
| } | |
| document.addEventListener("DOMContentLoaded", () => { | |
| const urlParams = new URLSearchParams(window.location.search); | |
| const restoreId = urlParams.get('restore'); | |
| if (!restoreId) return; | |
| // Wait 800ms to guarantee the page, CSS, and animations are 100% finished loading | |
| setTimeout(() => { | |
| // Automatically hunt down the chat box or text area on the page | |
| let container = document.querySelector('.chat-scroll-area') || | |
| document.getElementById('chatHistory') || | |
| document.getElementById('searchChatHistory') || | |
| document.getElementById('qaAnswerBox') || | |
| document.getElementById('translatedText'); | |
| if (!container) return; | |
| const forceInjectData = (historyData) => { | |
| let item = historyData.find(i => i.id == restoreId); | |
| if (!item) return; | |
| // 🛑 SCENARIO 1: It's a Chat Interface (Search, Image) | |
| if (item.interactions && item.interactions.length > 0 && container.classList.contains('chat-scroll-area')) { | |
| container.innerHTML = ''; // Wipe the empty screen | |
| item.interactions.forEach((inter, index) => { | |
| let imgHtml = inter.image ? `<img src="${inter.image}" class="bubble-img" style="max-width:100%; border-radius:16px; margin-bottom:15px; border: 2px solid var(--border-light); box-shadow: var(--glass-shadow);">` : ''; | |
| let textId = `restored_text_${index}`; | |
| container.insertAdjacentHTML('beforeend', ` | |
| <div class="chat-msg chat-user" style="animation: slideInUp 0.5s ease-out;"> | |
| <div class="bubble" style="background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border-bottom-right-radius: 6px; box-shadow: 0 8px 25px var(--primary-glow);"> | |
| ${imgHtml} | |
| <div>${inter.question.replace(/\n/g, '<br>')}</div> | |
| </div> | |
| </div> | |
| <div class="chat-msg chat-ai" style="animation: bounceInBubble 0.6s ease-out;"> | |
| <div class="bubble" style="background: var(--bg-surface); border: 1px solid var(--border-light); border-bottom-left-radius: 6px; box-shadow: var(--glass-shadow); display: flex; flex-direction: column;"> | |
| <div id="${textId}" style="margin-top:0; width:100%; overflow-x:auto;">${inter.answer.replace(/\n/g, '<br>')}</div> | |
| <div class="action-buttons-container" style="display:flex; flex-wrap:wrap; gap:10px; margin-top:25px; padding-top:15px; border-top:1px solid var(--border-light); width:100%;"> | |
| <button class="btn green" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; cursor: pointer; flex: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.05);" onclick="speakAndHighlight('${textId}')">🔊 Listen</button> | |
| <button class="btn" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; cursor: pointer; flex: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.05);" onclick="copyToClipboard('${textId}')">📋 Copy</button> | |
| </div> | |
| </div> | |
| </div> | |
| `); | |
| }); | |
| // Force the window to scroll to the newly injected text | |
| setTimeout(() => { container.scrollTop = container.scrollHeight; }, 100); | |
| if (typeof showToast === 'function') showToast("🔄 Search Restored Successfully!"); | |
| } | |
| // 🛑 SCENARIO 2: It's a Text Box Interface (Translator, Q&A) | |
| else { | |
| let textId = `restored_text_box`; | |
| let ansText = item.interactions ? item.interactions[0].answer : item.answer; | |
| container.innerHTML = ` | |
| <div id="${textId}" style="margin-top:0;">${ansText.replace(/\n/g, '<br>')}</div> | |
| <div style="display:flex; flex-wrap:wrap; gap:10px; margin-top:25px; padding-top:15px; border-top:1px solid var(--border-light);"> | |
| <button class="btn green" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; flex: 1;" onclick="speakAndHighlight('${textId}')">🔊 Listen</button> | |
| <button class="btn" style="background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)); color: var(--primary); border: 1px solid var(--primary); padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 800; flex: 1;" onclick="copyToClipboard('${textId}')">📋 Copy</button> | |
| </div> | |
| `; | |
| // Refill the input text box too | |
| if (document.getElementById('inputText')) document.getElementById('inputText').value = item.question || ""; | |
| if (typeof showToast === 'function') showToast("🔄 Document Restored Successfully!"); | |
| } | |
| // Safely render any Math/Physics equations (LaTeX) | |
| if (window.MathJax) { | |
| MathJax.typesetPromise([container]).catch(e => console.log(e)); | |
| } | |
| }; | |
| // Safely fetch from your LocalForage database, fallback to LocalStorage | |
| if (typeof localforage !== 'undefined') { | |
| localforage.getItem('aiHistory').then(data => { | |
| if (data && data.length > 0) forceInjectData(data); | |
| else forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]')); | |
| }).catch(() => forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]'))); | |
| } else { | |
| forceInjectData(JSON.parse(localStorage.getItem('aiHistory') || '[]')); | |
| } | |
| }, 800); // 👈 THIS 800ms DELAY IS THE MAGIC FIX. IT WAITS FOR EVERYTHING TO BE READY. | |
| }); | |
| </script> | |
| <script src="ui-controls.js" defer></script> | |
| <script src="main.js" defer></script> | |
| </body> | |
| </html> |