Spaces:
Running
Running
Update index.html
Browse files- index.html +78 -114
index.html
CHANGED
|
@@ -6,37 +6,27 @@
|
|
| 6 |
<title>Educational Assistant</title>
|
| 7 |
|
| 8 |
<!-- Google Font -->
|
| 9 |
-
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"/>
|
| 10 |
|
| 11 |
<!-- Bootstrap 5 -->
|
| 12 |
-
<link
|
| 13 |
-
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
| 14 |
-
rel="stylesheet"
|
| 15 |
-
integrity="sha384-c7DF2uX692G1LB+AU6CtQbmu6Ubfbdr6FLllSVEW9v56MZPPiBYkoQ7RZ2hFOTg1"
|
| 16 |
-
crossorigin="anonymous"
|
| 17 |
-
/>
|
| 18 |
|
| 19 |
<!-- Animate.css -->
|
| 20 |
-
<link
|
| 21 |
-
rel="stylesheet"
|
| 22 |
-
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
|
| 23 |
-
/>
|
| 24 |
|
| 25 |
<!-- AOS -->
|
| 26 |
-
<link
|
| 27 |
-
href="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.css"
|
| 28 |
-
rel="stylesheet"
|
| 29 |
-
/>
|
| 30 |
|
| 31 |
<style>
|
| 32 |
-
/* ========== CSS VARIABLES ========== */
|
| 33 |
:root {
|
| 34 |
-
--clr-primary: #
|
| 35 |
-
--clr-secondary: #
|
| 36 |
-
--clr-bg: #
|
| 37 |
-
--clr-card-bg: rgba(255, 255, 255, 0.
|
| 38 |
-
--clr-
|
| 39 |
-
--
|
|
|
|
|
|
|
| 40 |
--font: 'Poppins', sans-serif;
|
| 41 |
}
|
| 42 |
|
|
@@ -48,164 +38,146 @@
|
|
| 48 |
overflow-x: hidden;
|
| 49 |
}
|
| 50 |
|
| 51 |
-
/* ===== HERO ===== */
|
| 52 |
-
.hero {
|
| 53 |
-
position: relative;
|
| 54 |
-
height: 300px;
|
| 55 |
-
background: linear-gradient(135deg, rgba(108,99,255,0.8), rgba(255,101,132,0.8)),
|
| 56 |
-
url('image.jpeg') center/cover no-repeat;
|
| 57 |
-
}
|
| 58 |
-
.hero h1 {
|
| 59 |
-
position: absolute;
|
| 60 |
-
bottom: 30px;
|
| 61 |
-
left: 30px;
|
| 62 |
-
font-size: 3rem;
|
| 63 |
-
color: #fff;
|
| 64 |
-
text-shadow: 0 3px 10px rgba(0,0,0,0.4);
|
| 65 |
-
margin: 0;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
/* ===== NAVBAR ===== */
|
| 69 |
.navbar {
|
| 70 |
-
background: #
|
| 71 |
-
|
|
|
|
| 72 |
}
|
|
|
|
| 73 |
.navbar-brand {
|
| 74 |
font-weight: 600;
|
| 75 |
color: var(--clr-primary) !important;
|
|
|
|
| 76 |
}
|
|
|
|
| 77 |
.btn-outline-primary {
|
| 78 |
border-color: var(--clr-primary);
|
| 79 |
color: var(--clr-primary);
|
| 80 |
-
transition: var(--transition);
|
| 81 |
}
|
|
|
|
| 82 |
.btn-outline-primary:hover {
|
| 83 |
background: var(--clr-primary);
|
| 84 |
-
color:
|
| 85 |
}
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
border-bottom: 1px solid rgba(0,0,0,0.1);
|
| 93 |
}
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
}
|
| 97 |
|
| 98 |
-
/* ===== CARDS ===== */
|
| 99 |
.card {
|
| 100 |
background: var(--clr-card-bg);
|
| 101 |
-
backdrop-filter: blur(
|
| 102 |
-
border:
|
| 103 |
border-radius: 1rem;
|
|
|
|
| 104 |
transition: var(--transition);
|
| 105 |
}
|
|
|
|
| 106 |
.card:hover {
|
| 107 |
-
transform: translateY(-
|
| 108 |
-
box-shadow: 0
|
| 109 |
}
|
|
|
|
| 110 |
.card-title {
|
| 111 |
-
font-weight: 600;
|
| 112 |
color: var(--clr-primary);
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
-
/* ===== FORM ELEMENTS ===== */
|
| 116 |
.form-control, .form-select {
|
| 117 |
border-radius: 0.75rem;
|
| 118 |
-
|
| 119 |
-
transition: var(--transition);
|
| 120 |
}
|
|
|
|
| 121 |
.form-control:focus, .form-select:focus {
|
| 122 |
border-color: var(--clr-primary);
|
| 123 |
-
box-shadow: 0 0 0 0.
|
| 124 |
}
|
| 125 |
|
| 126 |
-
/* ===== BUTTONS ===== */
|
| 127 |
.btn-primary {
|
| 128 |
-
background: linear-gradient(
|
| 129 |
border: none;
|
| 130 |
border-radius: 0.75rem;
|
| 131 |
transition: var(--transition);
|
| 132 |
}
|
|
|
|
| 133 |
.btn-primary:hover {
|
| 134 |
transform: scale(1.05);
|
| 135 |
-
box-shadow: 0 8px
|
| 136 |
}
|
|
|
|
| 137 |
.btn-success {
|
| 138 |
background: var(--clr-primary);
|
| 139 |
border: none;
|
| 140 |
border-radius: 0.75rem;
|
| 141 |
transition: var(--transition);
|
| 142 |
}
|
|
|
|
| 143 |
.btn-success:hover {
|
| 144 |
background: var(--clr-secondary);
|
| 145 |
transform: translateY(-2px);
|
| 146 |
}
|
| 147 |
|
| 148 |
-
/* ===== RESULT BOX ===== */
|
| 149 |
#result {
|
| 150 |
-
background:
|
| 151 |
padding: 1rem;
|
| 152 |
border-radius: 0.75rem;
|
| 153 |
-
|
| 154 |
-
box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
|
| 155 |
white-space: pre-wrap;
|
|
|
|
| 156 |
}
|
| 157 |
|
| 158 |
-
/* ===== SCROLLBAR ===== */
|
| 159 |
::-webkit-scrollbar {
|
| 160 |
width: 8px;
|
| 161 |
}
|
| 162 |
-
|
| 163 |
-
background: #f1f1f1;
|
| 164 |
-
}
|
| 165 |
::-webkit-scrollbar-thumb {
|
| 166 |
background: var(--clr-primary);
|
| 167 |
border-radius: 4px;
|
| 168 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
</style>
|
| 170 |
</head>
|
| 171 |
<body>
|
| 172 |
<!-- NAVBAR -->
|
| 173 |
<nav class="navbar navbar-light">
|
| 174 |
<div class="container-fluid">
|
| 175 |
-
<button
|
| 176 |
-
class="btn btn-outline-primary"
|
| 177 |
-
type="button"
|
| 178 |
-
data-bs-toggle="offcanvas"
|
| 179 |
-
data-bs-target="#sidebar"
|
| 180 |
-
aria-controls="sidebar"
|
| 181 |
-
>
|
| 182 |
☰ Instructions
|
| 183 |
</button>
|
| 184 |
<span class="navbar-brand mb-0 h1">Educational Assistant</span>
|
| 185 |
</div>
|
| 186 |
</nav>
|
| 187 |
|
| 188 |
-
<!-- OFFCANVAS
|
| 189 |
-
<div
|
| 190 |
-
class="offcanvas offcanvas-start"
|
| 191 |
-
tabindex="-1"
|
| 192 |
-
id="sidebar"
|
| 193 |
-
aria-labelledby="sidebarLabel"
|
| 194 |
-
>
|
| 195 |
<div class="offcanvas-header">
|
| 196 |
<h5 id="sidebarLabel">How to Use</h5>
|
| 197 |
-
<button
|
| 198 |
-
type="button"
|
| 199 |
-
class="btn-close"
|
| 200 |
-
data-bs-dismiss="offcanvas"
|
| 201 |
-
aria-label="Close"
|
| 202 |
-
></button>
|
| 203 |
</div>
|
| 204 |
<div class="offcanvas-body">
|
| 205 |
<ol>
|
| 206 |
<li>Enter your OpenAI API key.</li>
|
| 207 |
<li>Upload a PDF file.</li>
|
| 208 |
-
<li>Select one of:
|
| 209 |
<ul>
|
| 210 |
<li>Generate Summary</li>
|
| 211 |
<li>Generate Quiz</li>
|
|
@@ -220,12 +192,14 @@
|
|
| 220 |
</div>
|
| 221 |
|
| 222 |
<!-- HERO -->
|
| 223 |
-
<section class="hero animate__animated animate__fadeIn"
|
|
|
|
|
|
|
| 224 |
|
| 225 |
<!-- MAIN -->
|
| 226 |
<div class="container my-5" data-aos="fade-up">
|
| 227 |
<div class="row g-4">
|
| 228 |
-
<!--
|
| 229 |
<div class="col-lg-4">
|
| 230 |
<div class="card p-4">
|
| 231 |
<div class="mb-3">
|
|
@@ -254,7 +228,8 @@
|
|
| 254 |
</div>
|
| 255 |
</div>
|
| 256 |
</div>
|
| 257 |
-
|
|
|
|
| 258 |
<div class="col-lg-8">
|
| 259 |
<div class="card p-4">
|
| 260 |
<h5 class="card-title">Result</h5>
|
|
@@ -268,11 +243,7 @@
|
|
| 268 |
</div>
|
| 269 |
|
| 270 |
<!-- SCRIPTS -->
|
| 271 |
-
<script
|
| 272 |
-
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
|
| 273 |
-
integrity="sha384-E6mRv7/D+K0PtPpK0O1J3DRgIh+tp3loX3f7ogf20+RskmIOrthyxU2048gASBZd"
|
| 274 |
-
crossorigin="anonymous"
|
| 275 |
-
></script>
|
| 276 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js"></script>
|
| 277 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
| 278 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.js"></script>
|
|
@@ -280,18 +251,13 @@
|
|
| 280 |
<script>
|
| 281 |
AOS.init();
|
| 282 |
const pdfjsLib = window['pdfjs-dist/build/pdf'];
|
| 283 |
-
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
| 284 |
-
'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js';
|
| 285 |
-
|
| 286 |
let pdfText = '';
|
| 287 |
|
| 288 |
-
// Toggle question field
|
| 289 |
document.getElementById('optionSelect').addEventListener('change', (e) => {
|
| 290 |
-
document.getElementById('questionGroup')
|
| 291 |
-
.classList.toggle('d-none', e.target.value !== 'Ask a Question');
|
| 292 |
});
|
| 293 |
|
| 294 |
-
// Load PDF text
|
| 295 |
document.getElementById('pdfUpload').addEventListener('change', async (e) => {
|
| 296 |
const file = e.target.files[0];
|
| 297 |
if (!file) return;
|
|
@@ -301,13 +267,12 @@
|
|
| 301 |
for (let i = 1; i <= pdf.numPages; i++) {
|
| 302 |
const page = await pdf.getPage(i);
|
| 303 |
const content = await page.getTextContent();
|
| 304 |
-
text += content.items.map((it) => it.str).join(' ') + '
|
| 305 |
}
|
| 306 |
pdfText = text.trim();
|
| 307 |
alert(`PDF loaded: ${pdf.numPages} pages`);
|
| 308 |
});
|
| 309 |
|
| 310 |
-
// Generate & download
|
| 311 |
document.getElementById('generateBtn').addEventListener('click', async () => {
|
| 312 |
const key = document.getElementById('apiKey').value.trim();
|
| 313 |
if (!key) return alert('Please enter your OpenAI API key.');
|
|
@@ -323,14 +288,14 @@
|
|
| 323 |
sys = 'You are a smart assistant. Answer the user’s question based on the PDF.';
|
| 324 |
const q = document.getElementById('questionInput').value.trim();
|
| 325 |
if (!q) return alert('Please type your question.');
|
| 326 |
-
user += '
|
| 327 |
} else {
|
| 328 |
sys = 'You are a smart assistant. Generate a balanced 7-day study plan dividing PDF content into 7 topics.';
|
| 329 |
}
|
| 330 |
|
| 331 |
-
// Call OpenAI
|
| 332 |
const resDiv = document.getElementById('result');
|
| 333 |
resDiv.textContent = 'Generating…';
|
|
|
|
| 334 |
const resp = await fetch('https://api.openai.com/v1/chat/completions', {
|
| 335 |
method: 'POST',
|
| 336 |
headers: {
|
|
@@ -349,7 +314,6 @@
|
|
| 349 |
const text = data.choices[0].message.content.trim();
|
| 350 |
resDiv.textContent = text;
|
| 351 |
|
| 352 |
-
// Prepare PDF
|
| 353 |
const { jsPDF } = window.jspdf;
|
| 354 |
const doc = new jsPDF();
|
| 355 |
const lines = doc.splitTextToSize(text, 180);
|
|
|
|
| 6 |
<title>Educational Assistant</title>
|
| 7 |
|
| 8 |
<!-- Google Font -->
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet" />
|
| 10 |
|
| 11 |
<!-- Bootstrap 5 -->
|
| 12 |
+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
<!-- Animate.css -->
|
| 15 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
<!-- AOS -->
|
| 18 |
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.css" rel="stylesheet" />
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
<style>
|
|
|
|
| 21 |
:root {
|
| 22 |
+
--clr-primary: #6c63ff;
|
| 23 |
+
--clr-secondary: #ff6584;
|
| 24 |
+
--clr-bg: linear-gradient(135deg, #e0e7ff, #fef6ff);
|
| 25 |
+
--clr-card-bg: rgba(255, 255, 255, 0.7);
|
| 26 |
+
--clr-glass: rgba(255, 255, 255, 0.15);
|
| 27 |
+
--clr-border: rgba(255, 255, 255, 0.3);
|
| 28 |
+
--clr-text: #2d2d2d;
|
| 29 |
+
--transition: all 0.3s ease-in-out;
|
| 30 |
--font: 'Poppins', sans-serif;
|
| 31 |
}
|
| 32 |
|
|
|
|
| 38 |
overflow-x: hidden;
|
| 39 |
}
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
.navbar {
|
| 42 |
+
background: #ffffffdd;
|
| 43 |
+
backdrop-filter: blur(10px);
|
| 44 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
| 45 |
}
|
| 46 |
+
|
| 47 |
.navbar-brand {
|
| 48 |
font-weight: 600;
|
| 49 |
color: var(--clr-primary) !important;
|
| 50 |
+
font-size: 1.4rem;
|
| 51 |
}
|
| 52 |
+
|
| 53 |
.btn-outline-primary {
|
| 54 |
border-color: var(--clr-primary);
|
| 55 |
color: var(--clr-primary);
|
|
|
|
| 56 |
}
|
| 57 |
+
|
| 58 |
.btn-outline-primary:hover {
|
| 59 |
background: var(--clr-primary);
|
| 60 |
+
color: white;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
.hero {
|
| 64 |
+
height: 300px;
|
| 65 |
+
background: linear-gradient(135deg, rgba(108, 99, 255, 0.7), rgba(255, 101, 132, 0.6)),
|
| 66 |
+
url('image.jpeg') center/cover no-repeat;
|
| 67 |
+
position: relative;
|
|
|
|
| 68 |
}
|
| 69 |
+
|
| 70 |
+
.hero h1 {
|
| 71 |
+
position: absolute;
|
| 72 |
+
bottom: 30px;
|
| 73 |
+
left: 30px;
|
| 74 |
+
font-size: 3.5rem;
|
| 75 |
+
color: white;
|
| 76 |
+
text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
| 77 |
}
|
| 78 |
|
|
|
|
| 79 |
.card {
|
| 80 |
background: var(--clr-card-bg);
|
| 81 |
+
backdrop-filter: blur(16px);
|
| 82 |
+
border: 1px solid var(--clr-border);
|
| 83 |
border-radius: 1rem;
|
| 84 |
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
|
| 85 |
transition: var(--transition);
|
| 86 |
}
|
| 87 |
+
|
| 88 |
.card:hover {
|
| 89 |
+
transform: translateY(-6px);
|
| 90 |
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
|
| 91 |
}
|
| 92 |
+
|
| 93 |
.card-title {
|
|
|
|
| 94 |
color: var(--clr-primary);
|
| 95 |
+
font-weight: 600;
|
| 96 |
}
|
| 97 |
|
|
|
|
| 98 |
.form-control, .form-select {
|
| 99 |
border-radius: 0.75rem;
|
| 100 |
+
border: 1px solid #ddd;
|
|
|
|
| 101 |
}
|
| 102 |
+
|
| 103 |
.form-control:focus, .form-select:focus {
|
| 104 |
border-color: var(--clr-primary);
|
| 105 |
+
box-shadow: 0 0 0 0.25rem rgba(108, 99, 255, 0.25);
|
| 106 |
}
|
| 107 |
|
|
|
|
| 108 |
.btn-primary {
|
| 109 |
+
background: linear-gradient(to right, var(--clr-primary), var(--clr-secondary));
|
| 110 |
border: none;
|
| 111 |
border-radius: 0.75rem;
|
| 112 |
transition: var(--transition);
|
| 113 |
}
|
| 114 |
+
|
| 115 |
.btn-primary:hover {
|
| 116 |
transform: scale(1.05);
|
| 117 |
+
box-shadow: 0 8px 18px rgba(108, 99, 255, 0.3);
|
| 118 |
}
|
| 119 |
+
|
| 120 |
.btn-success {
|
| 121 |
background: var(--clr-primary);
|
| 122 |
border: none;
|
| 123 |
border-radius: 0.75rem;
|
| 124 |
transition: var(--transition);
|
| 125 |
}
|
| 126 |
+
|
| 127 |
.btn-success:hover {
|
| 128 |
background: var(--clr-secondary);
|
| 129 |
transform: translateY(-2px);
|
| 130 |
}
|
| 131 |
|
|
|
|
| 132 |
#result {
|
| 133 |
+
background: white;
|
| 134 |
padding: 1rem;
|
| 135 |
border-radius: 0.75rem;
|
| 136 |
+
box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
|
|
|
|
| 137 |
white-space: pre-wrap;
|
| 138 |
+
min-height: 200px;
|
| 139 |
}
|
| 140 |
|
|
|
|
| 141 |
::-webkit-scrollbar {
|
| 142 |
width: 8px;
|
| 143 |
}
|
| 144 |
+
|
|
|
|
|
|
|
| 145 |
::-webkit-scrollbar-thumb {
|
| 146 |
background: var(--clr-primary);
|
| 147 |
border-radius: 4px;
|
| 148 |
}
|
| 149 |
+
|
| 150 |
+
.offcanvas {
|
| 151 |
+
backdrop-filter: blur(6px);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.offcanvas-header {
|
| 155 |
+
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
| 156 |
+
}
|
| 157 |
</style>
|
| 158 |
</head>
|
| 159 |
<body>
|
| 160 |
<!-- NAVBAR -->
|
| 161 |
<nav class="navbar navbar-light">
|
| 162 |
<div class="container-fluid">
|
| 163 |
+
<button class="btn btn-outline-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
☰ Instructions
|
| 165 |
</button>
|
| 166 |
<span class="navbar-brand mb-0 h1">Educational Assistant</span>
|
| 167 |
</div>
|
| 168 |
</nav>
|
| 169 |
|
| 170 |
+
<!-- OFFCANVAS -->
|
| 171 |
+
<div class="offcanvas offcanvas-start" tabindex="-1" id="sidebar" aria-labelledby="sidebarLabel">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
<div class="offcanvas-header">
|
| 173 |
<h5 id="sidebarLabel">How to Use</h5>
|
| 174 |
+
<button type="button" class="btn-close" data-bs-dismiss="offcanvas"></button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
</div>
|
| 176 |
<div class="offcanvas-body">
|
| 177 |
<ol>
|
| 178 |
<li>Enter your OpenAI API key.</li>
|
| 179 |
<li>Upload a PDF file.</li>
|
| 180 |
+
<li>Select one of the following:
|
| 181 |
<ul>
|
| 182 |
<li>Generate Summary</li>
|
| 183 |
<li>Generate Quiz</li>
|
|
|
|
| 192 |
</div>
|
| 193 |
|
| 194 |
<!-- HERO -->
|
| 195 |
+
<section class="hero animate__animated animate__fadeIn">
|
| 196 |
+
<h1>Welcome to Your Study Buddy</h1>
|
| 197 |
+
</section>
|
| 198 |
|
| 199 |
<!-- MAIN -->
|
| 200 |
<div class="container my-5" data-aos="fade-up">
|
| 201 |
<div class="row g-4">
|
| 202 |
+
<!-- LEFT PANEL -->
|
| 203 |
<div class="col-lg-4">
|
| 204 |
<div class="card p-4">
|
| 205 |
<div class="mb-3">
|
|
|
|
| 228 |
</div>
|
| 229 |
</div>
|
| 230 |
</div>
|
| 231 |
+
|
| 232 |
+
<!-- RIGHT PANEL -->
|
| 233 |
<div class="col-lg-8">
|
| 234 |
<div class="card p-4">
|
| 235 |
<h5 class="card-title">Result</h5>
|
|
|
|
| 243 |
</div>
|
| 244 |
|
| 245 |
<!-- SCRIPTS -->
|
| 246 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js"></script>
|
| 248 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
| 249 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.js"></script>
|
|
|
|
| 251 |
<script>
|
| 252 |
AOS.init();
|
| 253 |
const pdfjsLib = window['pdfjs-dist/build/pdf'];
|
| 254 |
+
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js';
|
|
|
|
|
|
|
| 255 |
let pdfText = '';
|
| 256 |
|
|
|
|
| 257 |
document.getElementById('optionSelect').addEventListener('change', (e) => {
|
| 258 |
+
document.getElementById('questionGroup').classList.toggle('d-none', e.target.value !== 'Ask a Question');
|
|
|
|
| 259 |
});
|
| 260 |
|
|
|
|
| 261 |
document.getElementById('pdfUpload').addEventListener('change', async (e) => {
|
| 262 |
const file = e.target.files[0];
|
| 263 |
if (!file) return;
|
|
|
|
| 267 |
for (let i = 1; i <= pdf.numPages; i++) {
|
| 268 |
const page = await pdf.getPage(i);
|
| 269 |
const content = await page.getTextContent();
|
| 270 |
+
text += content.items.map((it) => it.str).join(' ') + '\n\n';
|
| 271 |
}
|
| 272 |
pdfText = text.trim();
|
| 273 |
alert(`PDF loaded: ${pdf.numPages} pages`);
|
| 274 |
});
|
| 275 |
|
|
|
|
| 276 |
document.getElementById('generateBtn').addEventListener('click', async () => {
|
| 277 |
const key = document.getElementById('apiKey').value.trim();
|
| 278 |
if (!key) return alert('Please enter your OpenAI API key.');
|
|
|
|
| 288 |
sys = 'You are a smart assistant. Answer the user’s question based on the PDF.';
|
| 289 |
const q = document.getElementById('questionInput').value.trim();
|
| 290 |
if (!q) return alert('Please type your question.');
|
| 291 |
+
user += '\n\nUser question: ' + q;
|
| 292 |
} else {
|
| 293 |
sys = 'You are a smart assistant. Generate a balanced 7-day study plan dividing PDF content into 7 topics.';
|
| 294 |
}
|
| 295 |
|
|
|
|
| 296 |
const resDiv = document.getElementById('result');
|
| 297 |
resDiv.textContent = 'Generating…';
|
| 298 |
+
|
| 299 |
const resp = await fetch('https://api.openai.com/v1/chat/completions', {
|
| 300 |
method: 'POST',
|
| 301 |
headers: {
|
|
|
|
| 314 |
const text = data.choices[0].message.content.trim();
|
| 315 |
resDiv.textContent = text;
|
| 316 |
|
|
|
|
| 317 |
const { jsPDF } = window.jspdf;
|
| 318 |
const doc = new jsPDF();
|
| 319 |
const lines = doc.splitTextToSize(text, 180);
|