now how can i connect it with my back end to give real results ?
Browse files- index.html +93 -84
index.html
CHANGED
|
@@ -410,96 +410,78 @@
|
|
| 410 |
feather.replace();
|
| 411 |
}
|
| 412 |
}
|
| 413 |
-
|
| 414 |
-
function extractInformation() {
|
| 415 |
-
// Simulate extraction (in a real app, this would be an API call)
|
| 416 |
emptyState.classList.add('hidden');
|
| 417 |
resultsContainer.classList.remove('hidden');
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
}
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
if (ext === 'pdf') {
|
| 436 |
-
return `PDF document preview for ${filename}. This would show the first page of the PDF in a real implementation.\n\nSample content:\n\nCONFIDENTIAL\nBusiness Proposal for Acme Corp\n\nPrepared by: John Smith\nEmail: john.smith@example.com\nPhone: (555) 123-4567\n\nAttachments:\n- Financial_Projections.xlsx\n- Market_Analysis.docx`;
|
| 437 |
-
} else if (ext === 'msg') {
|
| 438 |
-
return `Email content preview for ${filename}\n\nFrom: sarah.johnson@business.com\nTo: jane.doe@example.com\nSubject: Meeting about partnership\n\nHi Jane,\n\nI wanted to follow up on our conversation about the potential partnership between Johnson & Associates and your company. Let me know when you'd be available for a call next week.\n\nBest regards,\nSarah Johnson\nCEO, Johnson & Associates\nPhone: (555) 987-6543`;
|
| 439 |
-
} else if (ext === 'txt') {
|
| 440 |
-
return `Text file content for ${filename}\n\nCustomer Information:\nName: Michael Brown\nCompany: Brown Technologies\nAddress: 123 Business Ave, Suite 400, New York, NY 10001\nPhone: (212) 555-6789\nEmail: michael@browntech.com\n\nProject Details:\n- Budget: $50,000\n- Timeline: 3 months\n- Key Contacts: Alice Wilson (Project Manager)`;
|
| 441 |
-
} else if (ext === 'xlsx' || ext === 'xls') {
|
| 442 |
-
return `Spreadsheet preview for ${filename}\n\nThis would show a table of data in a real implementation.\n\nSample data:\n\nName,Position,Company,Email,Phone\nJohn Smith,Director,Acme Corp,john.smith@example.com,555-123-4567\nJane Doe,Manager,Globex Inc,jane.doe@globex.com,555-987-6543\nRobert Johnson,CEO,Johnson & Associates,robert@johnson.com,555-456-7890`;
|
| 443 |
-
} else {
|
| 444 |
-
return `Document content for ${filename}\n\nThis would show the actual document content in a real implementation.`;
|
| 445 |
}
|
|
|
|
|
|
|
| 446 |
}
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
// Generate mock entities based on document type
|
| 450 |
-
const entities = {
|
| 451 |
-
people: [],
|
| 452 |
-
companies: [],
|
| 453 |
-
emails: [],
|
| 454 |
-
phones: [],
|
| 455 |
-
addresses: [],
|
| 456 |
-
custom: []
|
| 457 |
-
};
|
| 458 |
-
|
| 459 |
-
// Always add some basic entities
|
| 460 |
-
entities.people.push(
|
| 461 |
-
{ name: 'John Smith', context: 'mentioned as Director of Acme Corp' },
|
| 462 |
-
{ name: 'Sarah Johnson', context: 'CEO of Johnson & Associates' },
|
| 463 |
-
{ name: 'Michael Brown', context: 'customer from Brown Technologies' }
|
| 464 |
-
);
|
| 465 |
-
|
| 466 |
-
entities.companies.push(
|
| 467 |
-
{ name: 'Acme Corp', context: 'mentioned in business proposal' },
|
| 468 |
-
{ name: 'Johnson & Associates', context: 'potential partner' },
|
| 469 |
-
{ name: 'Brown Technologies', context: 'customer company' }
|
| 470 |
-
);
|
| 471 |
|
| 472 |
-
|
| 473 |
-
{ value: 'john.smith@example.com', context: 'contact for Acme Corp' },
|
| 474 |
-
{ value: 'sarah.johnson@business.com', context: 'CEO email' },
|
| 475 |
-
{ value: 'michael@browntech.com', context: 'customer email' }
|
| 476 |
-
);
|
| 477 |
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
{ value: '(555) 987-6543', context: 'Sarah Johnson\'s phone' },
|
| 481 |
-
{ value: '(212) 555-6789', context: 'Michael Brown\'s office' }
|
| 482 |
-
);
|
| 483 |
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
);
|
| 487 |
|
| 488 |
-
//
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
for (let i = 0; i < randomCount; i++) {
|
| 492 |
-
entities.custom.push({
|
| 493 |
-
keyword: keyword,
|
| 494 |
-
context: `found in ${filename} related to ${['project', 'meeting', 'proposal', 'contract'][Math.floor(Math.random() * 4)]}`
|
| 495 |
-
});
|
| 496 |
-
}
|
| 497 |
-
});
|
| 498 |
|
| 499 |
-
|
|
|
|
| 500 |
}
|
| 501 |
-
|
| 502 |
-
function updateDocumentView() {
|
| 503 |
if (extractionResults.length === 0) return;
|
| 504 |
|
| 505 |
const currentDoc = extractionResults[currentDocIndex];
|
|
@@ -634,12 +616,39 @@
|
|
| 634 |
emptyState.classList.remove('hidden');
|
| 635 |
resultsContainer.classList.add('hidden');
|
| 636 |
}
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
}
|
| 642 |
-
|
| 643 |
</script>
|
| 644 |
</body>
|
| 645 |
</html>
|
|
|
|
| 410 |
feather.replace();
|
| 411 |
}
|
| 412 |
}
|
| 413 |
+
async function extractInformation() {
|
|
|
|
|
|
|
| 414 |
emptyState.classList.add('hidden');
|
| 415 |
resultsContainer.classList.remove('hidden');
|
| 416 |
+
extractBtn.disabled = true;
|
| 417 |
+
extractBtn.innerHTML = '<i data-feather="loader" class="w-5 h-5 mr-2 animate-spin"></i> Processing...';
|
| 418 |
+
feather.replace();
|
| 419 |
+
|
| 420 |
+
try {
|
| 421 |
+
// Create FormData to send files
|
| 422 |
+
const formData = new FormData();
|
| 423 |
+
files.forEach(file => formData.append('documents', file));
|
| 424 |
+
|
| 425 |
+
// Add extraction options
|
| 426 |
+
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
|
| 427 |
+
const entitiesToExtract = Array.from(checkboxes).map(cb => cb.nextElementSibling.textContent);
|
| 428 |
+
formData.append('entities', JSON.stringify(entitiesToExtract));
|
| 429 |
+
|
| 430 |
+
// Add custom keywords if any
|
| 431 |
+
if (customKeywords.length > 0) {
|
| 432 |
+
formData.append('keywords', JSON.stringify(customKeywords));
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// Call your backend API (replace with your actual endpoint)
|
| 436 |
+
const response = await fetch('/api/extract', {
|
| 437 |
+
method: 'POST',
|
| 438 |
+
body: formData
|
| 439 |
+
});
|
| 440 |
+
|
| 441 |
+
if (!response.ok) {
|
| 442 |
+
throw new Error(`Error: ${response.status}`);
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
extractionResults = await response.json();
|
| 446 |
+
currentDocIndex = 0;
|
| 447 |
+
updateDocumentView();
|
| 448 |
+
|
| 449 |
+
} catch (error) {
|
| 450 |
+
console.error('Extraction failed:', error);
|
| 451 |
+
alert('Extraction failed. Please try again.');
|
| 452 |
+
} finally {
|
| 453 |
+
extractBtn.disabled = false;
|
| 454 |
+
extractBtn.innerHTML = '<i data-feather="search" class="w-5 h-5 mr-2"></i> Extract Information';
|
| 455 |
+
feather.replace();
|
| 456 |
+
}
|
| 457 |
}
|
| 458 |
+
function generateDocumentPreview(content) {
|
| 459 |
+
// If content is a string (from backend), use it directly
|
| 460 |
+
if (typeof content === 'string') {
|
| 461 |
+
return content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
}
|
| 463 |
+
// Fallback if no preview content is available
|
| 464 |
+
return `Preview not available for this document. Extracted entities are shown below.`;
|
| 465 |
}
|
| 466 |
+
function updateDocumentView() {
|
| 467 |
+
if (extractionResults.length === 0) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
+
const currentDoc = extractionResults[currentDocIndex];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
+
// Update document preview
|
| 472 |
+
documentPreview.textContent = generateDocumentPreview(currentDoc.preview || currentDoc.content);
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
+
// Update document counter
|
| 475 |
+
docCounter.textContent = `${currentDocIndex + 1}/${extractionResults.length}`;
|
|
|
|
| 476 |
|
| 477 |
+
// Update navigation buttons
|
| 478 |
+
prevDocBtn.disabled = currentDocIndex === 0;
|
| 479 |
+
nextDocBtn.disabled = currentDocIndex === extractionResults.length - 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
+
// Update extracted entities (assumes backend returns entities in same format)
|
| 482 |
+
updateEntitiesDisplay(currentDoc.entities || {});
|
| 483 |
}
|
| 484 |
+
function updateDocumentView() {
|
|
|
|
| 485 |
if (extractionResults.length === 0) return;
|
| 486 |
|
| 487 |
const currentDoc = extractionResults[currentDocIndex];
|
|
|
|
| 616 |
emptyState.classList.remove('hidden');
|
| 617 |
resultsContainer.classList.add('hidden');
|
| 618 |
}
|
| 619 |
+
async function exportResults() {
|
| 620 |
+
try {
|
| 621 |
+
const response = await fetch('/api/export', {
|
| 622 |
+
method: 'POST',
|
| 623 |
+
headers: {
|
| 624 |
+
'Content-Type': 'application/json',
|
| 625 |
+
},
|
| 626 |
+
body: JSON.stringify({
|
| 627 |
+
results: extractionResults,
|
| 628 |
+
format: 'csv' // or 'json' based on user selection
|
| 629 |
+
})
|
| 630 |
+
});
|
| 631 |
+
|
| 632 |
+
if (!response.ok) {
|
| 633 |
+
throw new Error(`Export failed: ${response.status}`);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
const blob = await response.blob();
|
| 637 |
+
const url = window.URL.createObjectURL(blob);
|
| 638 |
+
const a = document.createElement('a');
|
| 639 |
+
a.href = url;
|
| 640 |
+
a.download = `extracted_data_${new Date().toISOString().slice(0,10)}.csv`;
|
| 641 |
+
document.body.appendChild(a);
|
| 642 |
+
a.click();
|
| 643 |
+
window.URL.revokeObjectURL(url);
|
| 644 |
+
a.remove();
|
| 645 |
+
|
| 646 |
+
} catch (error) {
|
| 647 |
+
console.error('Export failed:', error);
|
| 648 |
+
alert('Export failed. Please try again.');
|
| 649 |
+
}
|
| 650 |
}
|
| 651 |
+
});
|
| 652 |
</script>
|
| 653 |
</body>
|
| 654 |
</html>
|