Spaces:
Sleeping
Sleeping
Add real PDF and DOCX text extraction to file upload
Browse filesUses pdf.js (Mozilla) and mammoth.js loaded from CDN to extract
text from uploaded documents client-side. No backend needed.
Shows character count after extraction, with error handling for
unsupported or corrupt files.
Co-authored-by: Cursor <cursoragent@cursor.com>
4 unmodified lines5678910498 unmodified lines509510511512513514515516517128 unmodified lines64664764864965065165265365465565665765865966066166266311 unmodified lines67567667767867968068168268368468568668768868969069169257 unmodified lines75075175275375475528 unmodified lines7847857867877887897907917927937947957967977987998001 unmodified line80280380480580680710 unmodified lines81881982082182282390 unmodified lines9149159169179189194 unmodified lines<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Eddison Intelligence β Patent Assistant</title><link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Mono:wght@300;400;500&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300&display=swap" rel="stylesheet"><style>*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }498 unmodified lines<div class="card-label">Upload notes or documents</div><div class="upload-zone" id="uploadZone" onclick="document.getElementById('fileInput').click()"><div class="upload-icon">π</div><div class="upload-text"><strong>Click to upload</strong> or drag & drop a .txt or .pdf file</div></div><input type="file" id="fileInput" accept=".txt,.pdf,.doc,.docx" onchange="handleFile(event)"><div id="fileAttached" style="display:none"></div></div>128 unmodified lines};// βββ NAVIGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction goToStep(n) {[1,2,3].forEach(i => {document.getElementById(`step${i}`).style.display = 'none';document.getElementById(`nav${i}`).className = 'step-btn';});document.getElementById(`step${n}`).style.display = 'block';document.getElementById(`nav${n}`).className = 'step-btn active';// mark previous as donefor(let i = 1; i < n; i++) document.getElementById(`nav${i}`).className = 'step-btn done';window.scrollTo({ top: 0, behavior: 'smooth' });if (n === 2) populateSearchPanel();if (n === 3) generateClaim();}// βββ STEP 1: FILE HANDLING βββββββββββββββββββββββββββββββββββββββββββββββββββ11 unmodified linesfunction processFile(file) {const div = document.getElementById('fileAttached');div.style.display = 'flex';div.innerHTML = `<span>π</span><span>${file.name}</span>`;if (file.type === 'text/plain' || file.name.endsWith('.txt')) {const reader = new FileReader();reader.onload = e => {document.getElementById('ideaText').value = e.target.result.slice(0, 3000);};reader.readAsText(file);} else {document.getElementById('ideaText').value = `[Uploaded: ${file.name} β text extraction simulated for demo]`;}}// βββ STEP 1: ANALYZE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββasync function analyzeIdea() {const text = document.getElementById('ideaText').value.trim();57 unmodified linesdocument.getElementById('extractedSection').scrollIntoView({ behavior: 'smooth', block: 'start' });}btn.disabled = false;btn.innerHTML = 'β¦ Re-analyze';}28 unmodified linesconst idx = state.selectedKeywords.indexOf(kw);if (idx > -1) { state.selectedKeywords.splice(idx, 1); el.classList.remove('selected'); }else { state.selectedKeywords.push(kw); el.classList.add('selected'); }}function toggleKindCode(code, el) {const idx = state.selectedKindCodes.indexOf(code);if (idx > -1) { state.selectedKindCodes.splice(idx, 1); el.classList.remove('selected'); }else { state.selectedKindCodes.push(code); el.classList.add('selected'); }}function removeTag(e, type, i) {e.stopPropagation();state.keywords.splice(i, 1);state.selectedKeywords = state.selectedKeywords.filter(k => state.keywords.includes(k));renderKeywords();}function removeKindCode(e, i) {e.stopPropagation();1 unmodified linestate.kindCodes.splice(i, 1);state.selectedKindCodes = state.selectedKindCodes.filter(c => c !== code);renderKindCodes();}function addTagOnEnter(e, type) { if (e.key === 'Enter') addTag(type); }function addTag(type) {10 unmodified lines}document.getElementById('kcInput').value = '';}}// βββ STEP 2: POPULATE SEARCH PANEL βββββββββββββββββββββββββββββββββββββββββββ90 unmodified linesrenderPriorArt();document.getElementById('priorArtResults').style.display = 'block';document.getElementById('priorArtResults').scrollIntoView({ behavior: 'smooth' });btn.disabled = false;btn.innerHTML = 'β Re-Search';}4 unmodified lines56789101112498 unmodified lines511512513514515516517518519128 unmodified lines64864965065165265365465565665765865966066166266366466566611 unmodified lines67867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974057 unmodified lines79879980080180280380428 unmodified lines8338348358368378388398408418428438448458468478488498508518521 unmodified line85485585685785885986010 unmodified lines87187287387487587687790 unmodified lines9689699709719729739744 unmodified lines<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Eddison Intelligence β Patent Assistant</title><link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Mono:wght@300;400;500&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,300&display=swap" rel="stylesheet"><script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mammoth/1.6.0/mammoth.browser.min.js"></script><style>*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }498 unmodified lines<div class="card-label">Upload notes or documents</div><div class="upload-zone" id="uploadZone" onclick="document.getElementById('fileInput').click()"><div class="upload-icon">π</div><div class="upload-text"><strong>Click to upload</strong> or drag & drop a .txt, .pdf, or .docx file</div></div><input type="file" id="fileInput" accept=".txt,.pdf,.docx" onchange="handleFile(event)"><div id="fileAttached" style="display:none"></div></div>128 unmodified lines};// βββ NAVIGATION ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction goToStep(n, opts = {}) {[1,2,3].forEach(i => {document.getElementById(`step${i}`).style.display = 'none';document.getElementById(`nav${i}`).className = 'step-btn';});document.getElementById(`step${n}`).style.display = 'block';document.getElementById(`nav${n}`).className = 'step-btn active';for(let i = 1; i < n; i++) document.getElementById(`nav${i}`).className = 'step-btn done';window.scrollTo({ top: 0, behavior: 'smooth' });state.currentStep = n;saveState();if (n === 2) populateSearchPanel();if (n === 3 && !opts.skipGenerate) generateClaim();}// βββ STEP 1: FILE HANDLING βββββββββββββββββββββββββββββββββββββββββββββββββββ11 unmodified linesfunction processFile(file) {const div = document.getElementById('fileAttached');div.style.display = 'flex';div.innerHTML = `<span>π</span><span>${file.name} β extracting text...</span>`;const ext = file.name.split('.').pop().toLowerCase();if (file.type === 'text/plain' || ext === 'txt') {const reader = new FileReader();reader.onload = e => {setExtractedText(file.name, e.target.result);};reader.readAsText(file);} else if (ext === 'pdf') {const reader = new FileReader();reader.onload = async e => {try {pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js';const pdf = await pdfjsLib.getDocument({ data: new Uint8Array(e.target.result) }).promise;let text = '';for (let i = 1; i <= pdf.numPages; i++) {const page = await pdf.getPage(i);const content = await page.getTextContent();text += content.items.map(item => item.str).join(' ') + '\n';}setExtractedText(file.name, text);} catch (err) {div.innerHTML = `<span>β οΈ</span><span>${file.name} β PDF extraction failed</span>`;document.getElementById('ideaText').value = '';}};reader.readAsArrayBuffer(file);} else if (ext === 'docx') {const reader = new FileReader();reader.onload = async e => {try {const result = await mammoth.extractRawText({ arrayBuffer: e.target.result });setExtractedText(file.name, result.value);} catch (err) {div.innerHTML = `<span>β οΈ</span><span>${file.name} β DOCX extraction failed</span>`;document.getElementById('ideaText').value = '';}};reader.readAsArrayBuffer(file);} else {div.innerHTML = `<span>β οΈ</span><span>${file.name} β unsupported format (use .txt, .pdf, or .docx)</span>`;}}function setExtractedText(filename, text) {const cleaned = text.trim().slice(0, 5000);document.getElementById('ideaText').value = cleaned;const div = document.getElementById('fileAttached');const charCount = cleaned.length;div.innerHTML = `<span>π</span><span>${filename} β ${charCount.toLocaleString()} characters extracted</span>`;}// βββ STEP 1: ANALYZE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββasync function analyzeIdea() {const text = document.getElementById('ideaText').value.trim();57 unmodified linesdocument.getElementById('extractedSection').scrollIntoView({ behavior: 'smooth', block: 'start' });}saveState();btn.disabled = false;btn.innerHTML = 'β¦ Re-analyze';}28 unmodified linesconst idx = state.selectedKeywords.indexOf(kw);if (idx > -1) { state.selectedKeywords.splice(idx, 1); el.classList.remove('selected'); }else { state.selectedKeywords.push(kw); el.classList.add('selected'); }saveState();}function toggleKindCode(code, el) {const idx = state.selectedKindCodes.indexOf(code);if (idx > -1) { state.selectedKindCodes.splice(idx, 1); el.classList.remove('selected'); }else { state.selectedKindCodes.push(code); el.classList.add('selected'); }saveState();}function removeTag(e, type, i) {e.stopPropagation();state.keywords.splice(i, 1);state.selectedKeywords = state.selectedKeywords.filter(k => state.keywords.includes(k));renderKeywords();saveState();}function removeKindCode(e, i) {e.stopPropagation();1 unmodified linestate.kindCodes.splice(i, 1);state.selectedKindCodes = state.selectedKindCodes.filter(c => c !== code);renderKindCodes();saveState();}function addTagOnEnter(e, type) { if (e.key === 'Enter') addTag(type); }function addTag(type) {10 unmodified lines}document.getElementById('kcInput').value = '';}saveState();}// βββ STEP 2: POPULATE SEARCH PANEL βββββββββββββββββββββββββββββββββββββββββββ90 unmodified linesrenderPriorArt();document.getElementById('priorArtResults').style.display = 'block';document.getElementById('priorArtResults').scrollIntoView({ behavior: 'smooth' });saveState();btn.disabled = false;btn.innerHTML = 'β Re-Search';}
eddison-app.html+64-9