Ultimate English Learner

Upload an English text page to get translation, vocabulary, pronunciation, and comprehension Questions & Answers!

No file chosen
Image Preview
Image or PDF preview will appear here

Analyzing your chapter, please wait...

Vocabulary

Extracted Text


                            

Pronunciation


                            

Translation


                            

Comprehension Q&A

    if (!response.ok) throw new Error(`API Error ${response.status}: ${response.statusText}`); const data = await response.json(); if (data.candidates?.[0]?.content?.parts?.[0]?.text) { parseAndDisplayResults(data.candidates[0].content.parts[0].text); } else if (data.promptFeedback?.blockReason) { showErrorMessage(`Content blocked by API. Reason: ${data.promptFeedback.blockReason}.`); } else { throw new Error("Received an unexpected or empty response from the API."); } } catch (error) { showErrorMessage(`An error occurred: ${error.message}`); } finally { loadingSpinner.style.display = 'none'; processButton.disabled = false; processButton.textContent = 'Analyze & Translate'; } }); function parseAndDisplayResults(responseText) { const extractSection = (start, end) => responseText.match(new RegExp(`${start}([\\s\\S]*?)${end}`))?.[1].trim() || null; let anyDataFound = false; const displayCard = (card, outputElem, content) => { if (content) { if(card.id === 'wordMeaningsCard') { const meaningRegex = /^(.+?)\s*\|([\s\S]*?)\|([\s\S]*?)$/gm; let matches; let tableHTML = ''; while ((matches = meaningRegex.exec(content)) !== null) { const [full, eng, def, hindi] = matches.map(m => m.trim()); const mainWord = eng.match(/^(.+?)\s*\(/)?.[1] || eng; const hinglish = eng.match(/\((.+?)\)/)?.[1] || ''; tableHTML += `${mainWord}
    (${hinglish})${def}${hindi}`; } outputElem.innerHTML = tableHTML; } else { outputElem.textContent = content; } card.style.display = 'flex'; anyDataFound = true; } else { card.style.display = 'none'; } }; const englishText = extractSection('---START_ENGLISH_TEXT---', '---END_ENGLISH_TEXT---'); const pronunciation = extractSection('---START_PRONUNCIATION---', '---END_PRONUNCIATION---'); const wordMeanings = extractSection('---START_WORD_MEANINGS---', '---END_WORD_MEANINGS---'); const hindiTranslation = extractSection('---START_HINDI_TRANSLATION---', '---END_HINDI_TRANSLATION---'); const qnaBlock = extractSection('---START_QNA---', '---END_QNA---'); displayCard(originalTextCard, originalTextOutput, englishText); displayCard(pronunciationCard, pronunciationOutput, pronunciation); displayCard(hindiTranslationCard, hindiTranslationOutput, hindiTranslation); displayCard(wordMeaningsCard, wordMeaningsOutput, wordMeanings); if (qnaBlock) { const qnaPairs = qnaBlock.split('[QNA_PAIR]').filter(p => p.trim()); if (qnaPairs.length > 0) { qnaOutput.innerHTML = qnaPairs.map(pair => { const lines = pair.trim().split('\n'); const qLine = lines.find(line => line.startsWith('Q:')); const aLine = lines.find(line => line.startsWith('A:')); if (qLine && aLine) { const q = qLine.substring(2).trim(); const a = aLine.substring(2).trim(); return `
  • Q: ${q}

    A: ${a}

  • `; } return ''; }).join(''); } if (qnaOutput.innerHTML === '') { qnaOutput.innerHTML = `
  • Could not generate Q&A for this text.
  • `; } qnaCard.style.display = 'flex'; anyDataFound = true; } else { qnaCard.style.display = 'none'; } if (anyDataFound) { resultsSection.style.display = 'block'; setTimeout(() => { resultsSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); }, 100); } else { showErrorMessage("Could not parse a valid response from the AI."); } } function resetUI(clearFileInfo = false) { processButton.disabled = true; imageDataBase64 = null; currentApiMimeType = null; if (clearFileInfo) { fileInfoDisplay.textContent = 'No file chosen'; imageUpload.value = ''; imagePreview.style.display = 'none'; previewTextPlaceholder.style.display = 'block'; previewTextPlaceholder.innerHTML = 'Image or PDF preview will appear here'; } resultsSection.style.display = 'none'; clearMessages(); } function updatePreview(type, fileName, dataUrl = null) { videoFeed.style.display = 'none'; previewTextPlaceholder.style.display = 'none'; imagePreview.style.display = 'none'; if (type.startsWith('image/')) { imagePreview.src = dataUrl; imagePreview.style.display = 'block'; } else if (type === 'application/pdf') { previewTextPlaceholder.style.display = 'flex'; previewTextPlaceholder.style.flexDirection = 'column'; previewTextPlaceholder.innerHTML = `📄${fileName}`; } } function clearMessages() { errorDisplay.style.display = 'none'; } function showErrorMessage(message) { clearMessages(); errorDisplay.textContent = message; errorDisplay.style.display = 'block'; }