pdf / index.html
Godsmiler-69's picture
Add 2 files
2a49eb8 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF Insight - AI-Powered Document Analysis</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.dropzone {
border: 3px dashed #9CA3AF;
transition: all 0.3s ease;
}
.dropzone.active {
border-color: #3B82F6;
background-color: #EFF6FF;
}
.pdf-container {
position: relative;
min-height: 100vh;
}
.pdf-viewer {
width: 70%;
height: 100vh;
overflow-y: auto;
position: relative;
}
.annotation-sidebar {
width: 30%;
height: 100vh;
overflow-y: auto;
border-left: 1px solid #E5E7EB;
background-color: #F9FAFB;
}
.pdf-page {
margin-bottom: 2rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
position: relative;
}
.highlight {
background-color: rgba(255, 255, 0, 0.3);
cursor: pointer;
transition: all 0.2s ease;
}
.highlight:hover {
background-color: rgba(255, 255, 0, 0.5);
}
.annotation-marker {
position: absolute;
right: -15px;
top: 50%;
transform: translateY(-50%);
width: 10px;
height: 10px;
background-color: #3B82F6;
border-radius: 50%;
cursor: pointer;
}
.annotation-popup {
position: absolute;
right: -320px;
width: 300px;
background-color: white;
border: 1px solid #E5E7EB;
border-radius: 0.5rem;
padding: 1rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
z-index: 10;
}
.loading-bar {
height: 4px;
background-color: #3B82F6;
width: 0%;
transition: width 0.3s ease;
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.pulse {
animation: pulse 2s infinite;
}
</style>
</head>
<body class="bg-gray-50">
<div class="loading-bar"></div>
<div id="app" class="min-h-screen">
<!-- Header -->
<header class="bg-white shadow-sm">
<div class="max-w-7xl mx-auto px-4 py-4 sm:px-6 lg:px-8 flex justify-between items-center">
<div class="flex items-center">
<i class="fas fa-brain text-blue-500 text-2xl mr-3"></i>
<h1 class="text-xl font-bold text-gray-800">PDF Insight</h1>
</div>
<div class="flex items-center space-x-4">
<button id="uploadBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-md flex items-center">
<i class="fas fa-upload mr-2"></i> Upload PDF
</button>
<input type="file" id="fileInput" class="hidden" accept=".pdf">
<button id="analyzeBtn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md flex items-center hidden">
<i class="fas fa-robot mr-2"></i> Analyze Document
</button>
</div>
</div>
</header>
<!-- Main Content -->
<main class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<!-- Dropzone Section (shown when no PDF is loaded) -->
<div id="dropzoneSection" class="flex flex-col items-center justify-center py-20">
<div class="dropzone w-full max-w-3xl rounded-xl p-12 text-center cursor-pointer" id="dropzone">
<div class="flex flex-col items-center justify-center">
<i class="fas fa-file-pdf text-5xl text-gray-400 mb-4"></i>
<h2 class="text-2xl font-semibold text-gray-700 mb-2">Drag & Drop your PDF here</h2>
<p class="text-gray-500 mb-6">or click to browse files</p>
<div class="bg-blue-50 text-blue-700 px-4 py-2 rounded-md inline-flex items-center">
<i class="fas fa-info-circle mr-2"></i>
<span>Supported: PDF files up to 50MB</span>
</div>
</div>
</div>
<div class="mt-8 text-center max-w-2xl">
<h3 class="text-lg font-medium text-gray-700 mb-3">How it works</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-white p-4 rounded-lg shadow-sm">
<div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
<i class="fas fa-upload"></i>
</div>
<h4 class="font-medium mb-1">Upload PDF</h4>
<p class="text-sm text-gray-500">Drag & drop or select your document</p>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
<i class="fas fa-microchip"></i>
</div>
<h4 class="font-medium mb-1">AI Processing</h4>
<p class="text-sm text-gray-500">We analyze text with OCR and AI</p>
</div>
<div class="bg-white p-4 rounded-lg shadow-sm">
<div class="bg-blue-100 text-blue-600 w-12 h-12 rounded-full flex items-center justify-center mb-3 mx-auto">
<i class="fas fa-comment-dots"></i>
</div>
<h4 class="font-medium mb-1">Get Insights</h4>
<p class="text-sm text-gray-500">View AI annotations in the margins</p>
</div>
</div>
</div>
</div>
<!-- PDF Viewer Section (shown after PDF is loaded) -->
<div id="pdfViewerSection" class="hidden">
<div class="flex justify-between items-center mb-6">
<div>
<h2 id="pdfTitle" class="text-xl font-semibold text-gray-800 truncate max-w-md"></h2>
<p id="pdfInfo" class="text-sm text-gray-500"></p>
</div>
<div class="flex space-x-3">
<button id="downloadBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-4 py-2 rounded-md flex items-center">
<i class="fas fa-download mr-2"></i> Download
</button>
<button id="newDocumentBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-4 py-2 rounded-md flex items-center">
<i class="fas fa-file mr-2"></i> New Document
</button>
</div>
</div>
<div class="pdf-container flex">
<div class="pdf-viewer bg-white p-6" id="pdfViewer">
<!-- PDF pages will be rendered here -->
<div class="flex items-center justify-center h-full">
<div class="text-center">
<div class="pulse">
<i class="fas fa-spinner fa-spin text-4xl text-blue-500 mb-4"></i>
</div>
<h3 class="text-lg font-medium text-gray-700">Processing PDF...</h3>
<p class="text-gray-500 mt-2">This may take a few moments</p>
</div>
</div>
</div>
<div class="annotation-sidebar p-6" id="annotationSidebar">
<div class="flex items-center justify-between mb-6">
<h3 class="text-lg font-semibold text-gray-800">AI Annotations</h3>
<div class="flex items-center space-x-2">
<div class="relative">
<button id="filterBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md flex items-center text-sm">
<i class="fas fa-filter mr-2"></i> Filter
</button>
<div id="filterDropdown" class="absolute right-0 mt-2 w-48 bg-white rounded-md shadow-lg z-10 hidden">
<div class="py-1">
<label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
<input type="checkbox" class="mr-2" checked> Key Terms
</label>
<label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
<input type="checkbox" class="mr-2" checked> Definitions
</label>
<label class="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer">
<input type="checkbox" class="mr-2" checked> References
</label>
</div>
</div>
</div>
<button id="exportAnnotationsBtn" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md flex items-center text-sm">
<i class="fas fa-file-export mr-2"></i> Export
</button>
</div>
</div>
<div id="annotationsList">
<div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-4 rounded">
<div class="flex justify-between items-start">
<div>
<h4 class="font-medium text-blue-800">Document Summary</h4>
<p class="text-sm text-gray-600 mt-1">Upload a PDF to see AI-generated annotations appear here.</p>
</div>
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">Summary</span>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<!-- Processing Modal -->
<div id="processingModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg p-6 max-w-md w-full">
<div class="text-center">
<div class="pulse mb-4">
<i class="fas fa-robot text-5xl text-blue-500"></i>
</div>
<h3 class="text-xl font-medium text-gray-800 mb-2">Analyzing Document</h3>
<p class="text-gray-600 mb-4">Our AI is reading your document and generating insights. This may take a moment...</p>
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4">
<div id="progressBar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
<p id="processingStatus" class="text-sm text-gray-500">Initializing OCR processing...</p>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const dropzone = document.getElementById('dropzone');
const fileInput = document.getElementById('fileInput');
const uploadBtn = document.getElementById('uploadBtn');
const analyzeBtn = document.getElementById('analyzeBtn');
const dropzoneSection = document.getElementById('dropzoneSection');
const pdfViewerSection = document.getElementById('pdfViewerSection');
const pdfViewer = document.getElementById('pdfViewer');
const pdfTitle = document.getElementById('pdfTitle');
const pdfInfo = document.getElementById('pdfInfo');
const annotationsList = document.getElementById('annotationsList');
const newDocumentBtn = document.getElementById('newDocumentBtn');
const processingModal = document.getElementById('processingModal');
const progressBar = document.getElementById('progressBar');
const processingStatus = document.getElementById('processingStatus');
const loadingBar = document.querySelector('.loading-bar');
const filterBtn = document.getElementById('filterBtn');
const filterDropdown = document.getElementById('filterDropdown');
// Event Listeners
uploadBtn.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', handleFileSelect);
dropzone.addEventListener('dragover', handleDragOver);
dropzone.addEventListener('dragleave', handleDragLeave);
dropzone.addEventListener('drop', handleDrop);
analyzeBtn.addEventListener('click', analyzeDocument);
newDocumentBtn.addEventListener('click', resetDocument);
filterBtn.addEventListener('click', toggleFilterDropdown);
// Close filter dropdown when clicking outside
document.addEventListener('click', (e) => {
if (!filterBtn.contains(e.target) && !filterDropdown.contains(e.target)) {
filterDropdown.classList.add('hidden');
}
});
// Functions
function handleDragOver(e) {
e.preventDefault();
e.stopPropagation();
dropzone.classList.add('active');
}
function handleDragLeave(e) {
e.preventDefault();
e.stopPropagation();
dropzone.classList.remove('active');
}
function handleDrop(e) {
e.preventDefault();
e.stopPropagation();
dropzone.classList.remove('active');
const files = e.dataTransfer.files;
if (files.length) {
handleFile(files[0]);
}
}
function handleFileSelect(e) {
if (e.target.files.length) {
handleFile(e.target.files[0]);
}
}
function handleFile(file) {
if (file.type !== 'application/pdf') {
showToast('Please upload a PDF file', 'error');
return;
}
if (file.size > 50 * 1024 * 1024) { // 50MB limit
showToast('File size exceeds 50MB limit', 'error');
return;
}
// Show loading state
loadingBar.style.width = '30%';
// Simulate file processing
setTimeout(() => {
loadingBar.style.width = '100%';
// Display PDF info
pdfTitle.textContent = file.name;
pdfInfo.textContent = `${(file.size / 1024 / 1024).toFixed(2)} MB • Uploaded ${new Date().toLocaleDateString()}`;
// Show the PDF viewer section
dropzoneSection.classList.add('hidden');
pdfViewerSection.classList.remove('hidden');
analyzeBtn.classList.remove('hidden');
// Simulate PDF rendering
setTimeout(() => {
renderSamplePDF();
loadingBar.style.width = '0%';
}, 500);
}, 1000);
}
function renderSamplePDF() {
// In a real app, you would use PDF.js or similar to render the actual PDF
// Here we're just creating a sample representation
pdfViewer.innerHTML = '';
// Create 3 sample pages
for (let i = 1; i <= 3; i++) {
const page = document.createElement('div');
page.className = 'pdf-page bg-white p-8 relative';
// Page header
const pageHeader = document.createElement('div');
pageHeader.className = 'flex justify-between items-center mb-6 pb-2 border-b border-gray-200';
pageHeader.innerHTML = `
<span class="text-sm font-medium text-gray-500">Page ${i}</span>
<span class="text-xs bg-gray-100 text-gray-600 px-2 py-1 rounded">${i}/3</span>
`;
page.appendChild(pageHeader);
// Page content
const pageContent = document.createElement('div');
pageContent.className = 'text-gray-800 leading-relaxed';
// Add sample text with highlights
const paragraphs = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.",
"The concept of artificial intelligence (AI) refers to the simulation of human intelligence in machines. These systems are designed to think like humans and mimic their actions.",
"Machine learning is a subset of AI that focuses on building systems that learn—or improve performance—based on the data they consume. Deep learning is a further subset that uses neural networks with many layers."
];
paragraphs.forEach((text, idx) => {
const p = document.createElement('p');
p.className = 'mb-4';
// Add highlights to some words
if (i === 1 && idx === 1) {
p.innerHTML = text.replace('artificial intelligence (AI)', '<span class="highlight" data-term="AI" data-page="1">artificial intelligence (AI)</span>');
// Add annotation marker
const marker = document.createElement('div');
marker.className = 'annotation-marker';
marker.setAttribute('data-term', 'AI');
marker.addEventListener('click', () => showAnnotationPopup(marker, 'AI'));
p.appendChild(marker);
}
else if (i === 2 && idx === 2) {
p.innerHTML = text.replace('Machine learning', '<span class="highlight" data-term="Machine Learning" data-page="2">Machine learning</span>')
.replace('Deep learning', '<span class="highlight" data-term="Deep Learning" data-page="2">Deep learning</span>');
// Add annotation markers
const mlMarker = document.createElement('div');
mlMarker.className = 'annotation-marker';
mlMarker.setAttribute('data-term', 'Machine Learning');
mlMarker.addEventListener('click', () => showAnnotationPopup(mlMarker, 'Machine Learning'));
p.appendChild(mlMarker);
const dlMarker = document.createElement('div');
dlMarker.className = 'annotation-marker';
dlMarker.style.top = '70%';
dlMarker.setAttribute('data-term', 'Deep Learning');
dlMarker.addEventListener('click', () => showAnnotationPopup(dlMarker, 'Deep Learning'));
p.appendChild(dlMarker);
}
else {
p.textContent = text;
}
pageContent.appendChild(p);
});
page.appendChild(pageContent);
pdfViewer.appendChild(page);
}
// Add click handlers for highlights
document.querySelectorAll('.highlight').forEach(highlight => {
highlight.addEventListener('click', function() {
const term = this.getAttribute('data-term');
showAnnotationPopup(this, term);
});
});
}
function analyzeDocument() {
// Show processing modal
processingModal.classList.remove('hidden');
// Simulate processing steps
const steps = [
"Extracting text with OCR...",
"Identifying key terms and concepts...",
"Analyzing document structure...",
"Generating AI insights...",
"Finalizing annotations..."
];
let currentStep = 0;
const interval = setInterval(() => {
if (currentStep < steps.length) {
const progress = ((currentStep + 1) / steps.length) * 100;
progressBar.style.width = `${progress}%`;
processingStatus.textContent = steps[currentStep];
currentStep++;
} else {
clearInterval(interval);
// Simulate completion
setTimeout(() => {
processingModal.classList.add('hidden');
showToast('Analysis complete!', 'success');
populateAnnotations();
}, 1000);
}
}, 1500);
}
function populateAnnotations() {
// In a real app, this would come from the AI analysis
const annotations = [
{
id: 1,
term: "AI",
page: 1,
type: "definition",
content: "Artificial Intelligence (AI) refers to machines designed to perform tasks that typically require human intelligence, such as visual perception, speech recognition, and decision-making.",
confidence: 0.92
},
{
id: 2,
term: "Machine Learning",
page: 2,
type: "definition",
content: "Machine Learning is a subset of AI that enables systems to automatically learn and improve from experience without being explicitly programmed.",
confidence: 0.95
},
{
id: 3,
term: "Deep Learning",
page: 2,
type: "definition",
content: "Deep Learning uses artificial neural networks with multiple layers to progressively extract higher-level features from raw input, mimicking how the human brain processes information.",
confidence: 0.89
},
{
id: 4,
term: "Document Summary",
page: "all",
type: "summary",
content: "This document discusses fundamental concepts in artificial intelligence, including machine learning and deep learning. It provides definitions and explains the relationships between these technologies.",
confidence: 0.87
}
];
// Clear existing annotations
annotationsList.innerHTML = '';
// Add new annotations
annotations.forEach(annotation => {
const annotationEl = document.createElement('div');
annotationEl.className = `bg-white border border-gray-200 p-4 mb-4 rounded-lg shadow-sm hover:shadow-md transition-shadow cursor-pointer`;
annotationEl.innerHTML = `
<div class="flex justify-between items-start mb-2">
<div>
<h4 class="font-medium text-gray-800">${annotation.term}</h4>
<span class="text-xs text-gray-500">Page ${annotation.page}</span>
</div>
<span class="text-xs px-2 py-1 rounded-full ${
annotation.type === 'definition' ? 'bg-blue-100 text-blue-800' :
annotation.type === 'summary' ? 'bg-green-100 text-green-800' :
'bg-purple-100 text-purple-800'
}">
${annotation.type.charAt(0).toUpperCase() + annotation.type.slice(1)}
</span>
</div>
<p class="text-gray-600 text-sm mb-2">${annotation.content}</p>
<div class="flex justify-between items-center">
<span class="text-xs text-gray-400">AI Confidence: ${Math.round(annotation.confidence * 100)}%</span>
<button class="text-xs text-blue-500 hover:text-blue-700" data-term="${annotation.term}">
<i class="fas fa-location-arrow mr-1"></i> Locate in document
</button>
</div>
`;
// Add click handler to locate term in document
annotationEl.querySelector('button').addEventListener('click', function(e) {
e.stopPropagation();
const term = this.getAttribute('data-term');
scrollToTerm(term);
});
annotationsList.appendChild(annotationEl);
});
}
function showAnnotationPopup(element, term) {
// Remove any existing popups
document.querySelectorAll('.annotation-popup').forEach(el => el.remove());
// In a real app, this would fetch the actual annotation data
const annotationData = {
"AI": {
content: "Artificial Intelligence (AI) refers to machines designed to perform tasks that typically require human intelligence.",
type: "definition",
confidence: 0.92
},
"Machine Learning": {
content: "Machine Learning is a subset of AI that enables systems to automatically learn and improve from experience.",
type: "definition",
confidence: 0.95
},
"Deep Learning": {
content: "Deep Learning uses artificial neural networks with multiple layers to extract higher-level features from raw input.",
type: "definition",
confidence: 0.89
}
};
if (!annotationData[term]) return;
const popup = document.createElement('div');
popup.className = 'annotation-popup';
popup.innerHTML = `
<div class="flex justify-between items-start mb-2">
<h4 class="font-medium text-gray-800">${term}</h4>
<span class="text-xs px-2 py-1 rounded-full ${
annotationData[term].type === 'definition' ? 'bg-blue-100 text-blue-800' : 'bg-purple-100 text-purple-800'
}">
${annotationData[term].type.charAt(0).toUpperCase() + annotationData[term].type.slice(1)}
</span>
</div>
<p class="text-gray-600 text-sm mb-3">${annotationData[term].content}</p>
<div class="flex justify-between items-center text-xs">
<span class="text-gray-400">AI Confidence: ${Math.round(annotationData[term].confidence * 100)}%</span>
<button class="text-blue-500 hover:text-blue-700">
<i class="fas fa-bookmark mr-1"></i> Save
</button>
</div>
`;
// Position the popup next to the element
const rect = element.getBoundingClientRect();
popup.style.top = `${rect.top + window.scrollY}px`;
// Add to document
document.body.appendChild(popup);
// Close popup when clicking outside
setTimeout(() => {
const clickHandler = (e) => {
if (!popup.contains(e.target) && !element.contains(e.target)) {
popup.remove();
document.removeEventListener('click', clickHandler);
}
};
document.addEventListener('click', clickHandler);
}, 10);
}
function scrollToTerm(term) {
// Find the first highlight with this term and scroll to it
const highlight = document.querySelector(`.highlight[data-term="${term}"]`);
if (highlight) {
highlight.scrollIntoView({ behavior: 'smooth', block: 'center' });
// Add temporary highlight effect
highlight.style.backgroundColor = 'rgba(255, 255, 0, 0.7)';
setTimeout(() => {
highlight.style.backgroundColor = 'rgba(255, 255, 0, 0.3)';
}, 2000);
}
}
function resetDocument() {
// Reset the UI
fileInput.value = '';
dropzoneSection.classList.remove('hidden');
pdfViewerSection.classList.add('hidden');
analyzeBtn.classList.add('hidden');
annotationsList.innerHTML = `
<div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-4 rounded">
<div class="flex justify-between items-start">
<div>
<h4 class="font-medium text-blue-800">Document Summary</h4>
<p class="text-sm text-gray-600 mt-1">Upload a PDF to see AI-generated annotations appear here.</p>
</div>
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded-full">Summary</span>
</div>
</div>
`;
}
function toggleFilterDropdown() {
filterDropdown.classList.toggle('hidden');
}
function showToast(message, type) {
const toast = document.createElement('div');
toast.className = `fixed bottom-4 right-4 px-6 py-3 rounded-md shadow-md text-white ${
type === 'error' ? 'bg-red-500' : 'bg-green-500'
}`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Godsmiler-69/pdf" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>