File size: 25,617 Bytes
f844d21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Research Paper Summarizer</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pdf-lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/openai.browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
}
.gradient-bg {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.card {
backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.18);
transition: all 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.3);
}
.file-upload {
border: 2px dashed #667eea;
transition: all 0.3s ease;
}
.file-upload:hover {
border-color: #764ba2;
background: rgba(118, 75, 162, 0.05);
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
transition: all 0.3s ease;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
.loading-dots {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.loading-dots span {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #667eea;
margin: 0 5px;
animation: bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) {
animation-delay: -0.32s;
}
.loading-dots span:nth-child(2) {
animation-delay: -0.16s;
}
@keyframes bounce {
0%, 80%, 100% {
transform: scale(0);
}
40% {
transform: scale(1);
}
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.result-card {
background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(245, 247, 250, 0.9) 100%);
border-left: 5px solid #667eea;
}
</style>
</head>
<body class="min-h-screen flex flex-col">
<!-- Header -->
<header class="gradient-bg text-white py-8 shadow-lg">
<div class="container mx-auto px-4 text-center">
<h1 class="text-4xl font-bold mb-2 animate__animated animate__fadeInDown">Research Paper Summarizer</h1>
<p class="text-xl opacity-90 animate__animated animate__fadeIn animate__delay-1s">Transform complex research into concise summaries with AI</p>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow container mx-auto px-4 py-8">
<div class="max-w-3xl mx-auto">
<!-- Upload Section -->
<div class="card p-6 mb-8 animate__animated animate__fadeIn animate__delay-1s">
<h2 class="text-2xl font-semibold mb-4 text-gray-800">Upload Your Research Paper</h2>
<div class="mb-6">
<label for="api-key" class="block text-sm font-medium text-gray-700 mb-2">OpenAI API Key</label>
<input type="password" id="api-key" class="w-full px-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-purple-500" placeholder="Enter your OpenAI API key">
<p class="text-xs text-gray-500 mt-1">Your API key is used only for processing and is not stored.</p>
</div>
<div class="file-upload p-8 rounded-lg text-center cursor-pointer mb-4" id="drop-area">
<input type="file" id="file-input" class="hidden" accept=".pdf">
<div class="flex flex-col items-center justify-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-purple-500 mb-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
<p class="text-lg font-medium text-gray-700 mb-1">Drag & drop your PDF here</p>
<p class="text-sm text-gray-500">or click to browse files</p>
</div>
</div>
<p id="file-name" class="text-sm text-gray-600 text-center hidden"></p>
<div class="flex justify-center mt-6">
<button id="process-btn" class="btn-primary text-white font-medium py-2 px-6 rounded-lg flex items-center disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<span>Process Paper</span>
<svg id="process-spinner" class="hidden animate-spin ml-2 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</button>
</div>
</div>
<!-- Results Section -->
<div id="results-section" class="hidden animate__animated animate__fadeIn">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-semibold text-gray-800">Summary Results</h2>
<button id="download-btn" class="btn-primary text-white font-medium py-2 px-4 rounded-lg flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
Download Summary
</button>
</div>
<!-- Summary Card -->
<div class="result-card p-6 rounded-lg shadow-sm mb-6 fade-in">
<div class="flex items-center mb-4">
<div class="bg-purple-100 p-2 rounded-full mr-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-purple-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<h3 class="text-xl font-medium text-gray-800">Summary</h3>
</div>
<div id="summary-content" class="text-gray-700">
<div class="loading-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
<!-- Topic Card -->
<div class="result-card p-6 rounded-lg shadow-sm fade-in">
<div class="flex items-center mb-4">
<div class="bg-purple-100 p-2 rounded-full mr-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-purple-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 20l4-16m2 16l4-16M6 9h14M4 15h14" />
</svg>
</div>
<h3 class="text-xl font-medium text-gray-800">Predicted Main Topic</h3>
</div>
<div id="topic-content" class="text-gray-700">
<div class="loading-dots">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
</div>
<!-- Error Section -->
<div id="error-section" class="hidden bg-red-50 border-l-4 border-red-500 p-4 mb-6 rounded-r-lg">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800" id="error-title">Error</h3>
<div class="mt-2 text-sm text-red-700" id="error-message">
<p>An error occurred while processing your request.</p>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-white py-6 shadow-inner">
<div class="container mx-auto px-4 text-center text-gray-600">
<p>© 2023 Research Paper Summarizer. All rights reserved.</p>
</div>
</footer>
<script>
// Initialize variables
let selectedFile = null;
let summaryText = '';
let topicText = '';
let originalFileName = '';
// Set up event listeners
document.addEventListener('DOMContentLoaded', function() {
const fileInput = document.getElementById('file-input');
const dropArea = document.getElementById('drop-area');
const fileNameDisplay = document.getElementById('file-name');
const processBtn = document.getElementById('process-btn');
const apiKeyInput = document.getElementById('api-key');
const resultsSection = document.getElementById('results-section');
const errorSection = document.getElementById('error-section');
// Handle file selection via click
dropArea.addEventListener('click', () => fileInput.click());
// Handle file selection via input
fileInput.addEventListener('change', (e) => {
if (e.target.files.length) {
handleFileSelection(e.target.files[0]);
}
});
// Handle drag and drop
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropArea.classList.add('bg-purple-50');
}
function unhighlight() {
dropArea.classList.remove('bg-purple-50');
}
dropArea.addEventListener('drop', (e) => {
const dt = e.dataTransfer;
const file = dt.files[0];
if (file && file.type === 'application/pdf') {
handleFileSelection(file);
}
});
// Handle file selection
function handleFileSelection(file) {
if (file.type !== 'application/pdf') {
showError('Invalid File Type', 'Please upload a PDF file.');
return;
}
selectedFile = file;
originalFileName = file.name;
fileNameDisplay.textContent = `Selected: ${file.name}`;
fileNameDisplay.classList.remove('hidden');
dropArea.innerHTML = `
<div class="flex items-center justify-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-green-500 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span class="text-gray-700">${file.name}</span>
</div>
`;
// Enable process button if API key is present
if (apiKeyInput.value.trim() !== '') {
processBtn.disabled = false;
}
}
// Enable process button when API key is entered
apiKeyInput.addEventListener('input', () => {
if (apiKeyInput.value.trim() !== '' && selectedFile) {
processBtn.disabled = false;
} else {
processBtn.disabled = true;
}
});
// Process button click handler
processBtn.addEventListener('click', async () => {
if (!selectedFile || !apiKeyInput.value.trim()) return;
// Show loading state
processBtn.disabled = true;
document.getElementById('process-spinner').classList.remove('hidden');
processBtn.innerHTML = '<span>Processing</span>' + processBtn.innerHTML.split('<span>')[1];
// Hide any previous errors
errorSection.classList.add('hidden');
try {
// Extract text from PDF
const text = await extractTextFromPDF(selectedFile);
if (text.length < 1000) {
throw new Error('The document is too short for meaningful analysis.');
}
// Show results section
resultsSection.classList.remove('hidden');
// Process with OpenAI using fetch API
const summary = await callOpenAI(apiKeyInput.value.trim(), text, "summarize");
summaryText = ensureFullStop(summary);
document.getElementById('summary-content').innerHTML = `<p class="whitespace-pre-line">${summaryText}</p>`;
const topic = await callOpenAI(apiKeyInput.value.trim(), text, "topic");
topicText = ensureFullStop(topic);
document.getElementById('topic-content').innerHTML = `<p class="whitespace-pre-line">${topicText}</p>`;
} catch (error) {
console.error('Error:', error);
showError('Processing Error', error.message || 'An error occurred while processing your request.');
resultsSection.classList.add('hidden');
} finally {
// Reset button state
processBtn.disabled = false;
document.getElementById('process-spinner').classList.add('hidden');
processBtn.innerHTML = '<span>Process Paper</span>' + processBtn.innerHTML.split('<span>')[1];
}
});
// Download button click handler
document.getElementById('download-btn').addEventListener('click', async () => {
if (!summaryText || !topicText) return;
try {
// Create PDF
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Add title
doc.setFontSize(18);
doc.text('Research Paper Summary', 105, 20, { align: 'center' });
// Add original filename
doc.setFontSize(12);
doc.setTextColor(100);
doc.text(`Original: ${originalFileName}`, 105, 30, { align: 'center' });
// Add summary section
doc.setFontSize(14);
doc.setTextColor(0);
doc.text('Summary', 14, 45);
doc.setFontSize(12);
const summaryLines = doc.splitTextToSize(summaryText, 180);
doc.text(summaryLines, 14, 55);
// Add topic section
const summaryHeight = summaryLines.length * 7;
doc.setFontSize(14);
doc.text('Predicted Main Topic', 14, 60 + summaryHeight);
doc.setFontSize(12);
const topicLines = doc.splitTextToSize(topicText, 180);
doc.text(topicLines, 14, 70 + summaryHeight);
// Add footer
doc.setFontSize(10);
doc.setTextColor(100);
doc.text('Generated by Research Paper Summarizer', 105, 285, { align: 'center' });
// Save the PDF
const pdfBlob = doc.output('blob');
const pdfUrl = URL.createObjectURL(pdfBlob);
// Create download link
const downloadLink = document.createElement('a');
downloadLink.href = pdfUrl;
downloadLink.download = `${originalFileName.replace('.pdf', '')}_summary.pdf`;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
URL.revokeObjectURL(pdfUrl);
} catch (error) {
console.error('Error generating PDF:', error);
showError('PDF Generation Error', 'Failed to generate PDF download.');
}
});
});
// Helper function to call OpenAI API using fetch
async function callOpenAI(apiKey, text, type) {
let prompt = "";
if (type === "summarize") {
prompt = `Summarize the following research paper in 3-5 paragraphs, focusing on key findings, methodology, and conclusions:\n\n${text}`;
} else {
prompt = `What is the main topic or research question of the following paper? Respond with a concise 1-2 sentence answer:\n\n${text}`;
}
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: type === "summarize"
? "You are a helpful research assistant that summarizes academic papers."
: "You are a helpful research assistant that identifies key topics in academic papers."
},
{
role: "user",
content: prompt
}
],
max_tokens: type === "summarize" ? 800 : 100,
temperature: type === "summarize" ? 0.5 : 0.3
})
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error?.message || "Failed to process request with OpenAI");
}
const data = await response.json();
return data.choices[0].message.content;
}
// Helper function to extract text from PDF
async function extractTextFromPDF(file) {
return new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.onload = async function() {
try {
// Initialize PDF.js
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.worker.min.js';
const typedArray = new Uint8Array(this.result);
const pdf = await pdfjsLib.getDocument(typedArray).promise;
let fullText = '';
// Extract text from each page
for (let i = 1; i <= pdf.numPages; i++) {
const page = await pdf.getPage(i);
const textContent = await page.getTextContent();
const textItems = textContent.items.map(item => item.str);
fullText += textItems.join(' ') + '\n';
}
resolve(fullText);
} catch (error) {
reject(error);
}
};
fileReader.onerror = reject;
fileReader.readAsArrayBuffer(file);
});
}
// Ensure text ends with punctuation
function ensureFullStop(text) {
text = text.trim();
if (!text.endsWith('.') && !text.endsWith('!') && !text.endsWith('?')) {
text += '.';
}
return text;
}
// Show error message
function showError(title, message) {
document.getElementById('error-title').textContent = title;
document.getElementById('error-message').innerHTML = `<p>${message}</p>`;
document.getElementById('error-section').classList.remove('hidden');
}
</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=shukdevdatta123/research-paper-summarizer-web" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |