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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en" data-bs-theme="light">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6 |
+
<title>Educational Assistant</title>
|
7 |
+
<!-- Bootstrap 5 -->
|
8 |
+
<link
|
9 |
+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
10 |
+
rel="stylesheet"
|
11 |
+
integrity="sha384-c7DF2uX692G1LB+AU6CtQbmu6Ubfbdr6FLllSVEW9v56MZPPiBYkoQ7RZ2hFOTg1"
|
12 |
+
crossorigin="anonymous"
|
13 |
+
/>
|
14 |
+
<!-- Animate.css -->
|
15 |
+
<link
|
16 |
+
rel="stylesheet"
|
17 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
|
18 |
+
/>
|
19 |
+
<!-- AOS -->
|
20 |
+
<link
|
21 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.css"
|
22 |
+
rel="stylesheet"
|
23 |
+
/>
|
24 |
+
<style>
|
25 |
+
body {
|
26 |
+
background: #f8f9fa;
|
27 |
+
}
|
28 |
+
.hero {
|
29 |
+
background: url('image.jpeg') center/cover no-repeat;
|
30 |
+
height: 300px;
|
31 |
+
position: relative;
|
32 |
+
}
|
33 |
+
.hero h1 {
|
34 |
+
position: absolute;
|
35 |
+
bottom: 20px;
|
36 |
+
left: 20px;
|
37 |
+
color: white;
|
38 |
+
text-shadow: 0 0 10px rgba(0,0,0,0.7);
|
39 |
+
}
|
40 |
+
.offcanvas-body {
|
41 |
+
padding-top: 1rem;
|
42 |
+
}
|
43 |
+
</style>
|
44 |
+
</head>
|
45 |
+
<body>
|
46 |
+
<!-- Navbar with sidebar toggle -->
|
47 |
+
<nav class="navbar navbar-light bg-white shadow-sm">
|
48 |
+
<div class="container-fluid">
|
49 |
+
<button
|
50 |
+
class="btn btn-outline-primary"
|
51 |
+
type="button"
|
52 |
+
data-bs-toggle="offcanvas"
|
53 |
+
data-bs-target="#sidebar"
|
54 |
+
aria-controls="sidebar"
|
55 |
+
>
|
56 |
+
☰ Instructions
|
57 |
+
</button>
|
58 |
+
<span class="navbar-brand mb-0 h1">Educational Assistant</span>
|
59 |
+
</div>
|
60 |
+
</nav>
|
61 |
+
|
62 |
+
<!-- Offcanvas Sidebar -->
|
63 |
+
<div
|
64 |
+
class="offcanvas offcanvas-start"
|
65 |
+
tabindex="-1"
|
66 |
+
id="sidebar"
|
67 |
+
aria-labelledby="sidebarLabel"
|
68 |
+
>
|
69 |
+
<div class="offcanvas-header">
|
70 |
+
<h5 id="sidebarLabel">Instructions</h5>
|
71 |
+
<button
|
72 |
+
type="button"
|
73 |
+
class="btn-close text-reset"
|
74 |
+
data-bs-dismiss="offcanvas"
|
75 |
+
aria-label="Close"
|
76 |
+
></button>
|
77 |
+
</div>
|
78 |
+
<div class="offcanvas-body">
|
79 |
+
<ol>
|
80 |
+
<li>Enter your OpenAI API key below (password field).</li>
|
81 |
+
<li>Upload a PDF via the “Upload PDF” button.</li>
|
82 |
+
<li>Select one:
|
83 |
+
<ul>
|
84 |
+
<li>Generate Summary</li>
|
85 |
+
<li>Generate Quiz</li>
|
86 |
+
<li>Ask a Question</li>
|
87 |
+
<li>Generate Study Plan</li>
|
88 |
+
</ul>
|
89 |
+
</li>
|
90 |
+
<li>If asking a question, type it in.</li>
|
91 |
+
<li>Click “Generate” and then download your result as PDF.</li>
|
92 |
+
</ol>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
+
|
96 |
+
<!-- Hero Section -->
|
97 |
+
<section class="hero mb-4">
|
98 |
+
<h1 class="animate__animated animate__fadeInDown">Study Smarter</h1>
|
99 |
+
</section>
|
100 |
+
|
101 |
+
<!-- Main Content -->
|
102 |
+
<div class="container" data-aos="fade-up">
|
103 |
+
<div class="row g-4">
|
104 |
+
<!-- Controls Column -->
|
105 |
+
<div class="col-lg-4">
|
106 |
+
<div class="card shadow-sm">
|
107 |
+
<div class="card-body">
|
108 |
+
<div class="mb-3">
|
109 |
+
<label for="apiKey" class="form-label">OpenAI API Key</label>
|
110 |
+
<input
|
111 |
+
type="password"
|
112 |
+
class="form-control"
|
113 |
+
id="apiKey"
|
114 |
+
placeholder="sk-..."
|
115 |
+
/>
|
116 |
+
</div>
|
117 |
+
<div class="mb-3">
|
118 |
+
<label for="pdfUpload" class="form-label">Upload PDF</label>
|
119 |
+
<input
|
120 |
+
class="form-control"
|
121 |
+
type="file"
|
122 |
+
id="pdfUpload"
|
123 |
+
accept="application/pdf"
|
124 |
+
/>
|
125 |
+
</div>
|
126 |
+
<div class="mb-3">
|
127 |
+
<label class="form-label">Option</label>
|
128 |
+
<select class="form-select" id="optionSelect">
|
129 |
+
<option>Generate Summary</option>
|
130 |
+
<option>Generate Quiz</option>
|
131 |
+
<option>Ask a Question</option>
|
132 |
+
<option>Generate Study Plan</option>
|
133 |
+
</select>
|
134 |
+
</div>
|
135 |
+
<div class="mb-3 d-none" id="questionGroup">
|
136 |
+
<label for="questionInput" class="form-label">Your Question</label>
|
137 |
+
<input
|
138 |
+
type="text"
|
139 |
+
class="form-control"
|
140 |
+
id="questionInput"
|
141 |
+
placeholder="Type your question..."
|
142 |
+
/>
|
143 |
+
</div>
|
144 |
+
<div class="d-grid">
|
145 |
+
<button class="btn btn-primary" id="generateBtn">
|
146 |
+
Generate
|
147 |
+
</button>
|
148 |
+
</div>
|
149 |
+
</div>
|
150 |
+
</div>
|
151 |
+
</div>
|
152 |
+
|
153 |
+
<!-- Output Column -->
|
154 |
+
<div class="col-lg-8">
|
155 |
+
<div class="card shadow-sm">
|
156 |
+
<div class="card-body">
|
157 |
+
<h5 class="card-title">Result</h5>
|
158 |
+
<div id="result" style="white-space: pre-wrap; min-height: 200px;">
|
159 |
+
<!-- AI response appears here -->
|
160 |
+
</div>
|
161 |
+
<div class="mt-3 text-end">
|
162 |
+
<button
|
163 |
+
class="btn btn-success d-none"
|
164 |
+
id="downloadBtn"
|
165 |
+
>
|
166 |
+
Download as PDF
|
167 |
+
</button>
|
168 |
+
</div>
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
</div>
|
172 |
+
</div>
|
173 |
+
</div>
|
174 |
+
|
175 |
+
<!-- Scripts -->
|
176 |
+
<!-- Bootstrap JS & dependencies -->
|
177 |
+
<script
|
178 |
+
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
|
179 |
+
integrity="sha384-E6mRv7/D+K0PtPpK0O1J3DRgIh+tp3loX3f7ogf20+RskmIOrthyxU2048gASBZd"
|
180 |
+
crossorigin="anonymous"
|
181 |
+
></script>
|
182 |
+
<!-- PDF.js -->
|
183 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.min.js"></script>
|
184 |
+
<!-- jsPDF -->
|
185 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
|
186 |
+
<!-- AOS -->
|
187 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.js"></script>
|
188 |
+
|
189 |
+
<script>
|
190 |
+
AOS.init();
|
191 |
+
const pdfjsLib = window['pdfjs-dist/build/pdf'];
|
192 |
+
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
193 |
+
'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.4.120/pdf.worker.min.js';
|
194 |
+
|
195 |
+
let pdfText = '';
|
196 |
+
|
197 |
+
// Show/hide question input
|
198 |
+
document
|
199 |
+
.getElementById('optionSelect')
|
200 |
+
.addEventListener('change', (e) => {
|
201 |
+
const qg = document.getElementById('questionGroup');
|
202 |
+
qg.classList.toggle(
|
203 |
+
'd-none',
|
204 |
+
e.target.value !== 'Ask a Question'
|
205 |
+
);
|
206 |
+
});
|
207 |
+
|
208 |
+
// Load PDF and extract text
|
209 |
+
document
|
210 |
+
.getElementById('pdfUpload')
|
211 |
+
.addEventListener('change', async (e) => {
|
212 |
+
const file = e.target.files[0];
|
213 |
+
if (!file) return;
|
214 |
+
const arrayBuffer = await file.arrayBuffer();
|
215 |
+
const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
|
216 |
+
let fullText = '';
|
217 |
+
for (let i = 1; i <= pdf.numPages; i++) {
|
218 |
+
const page = await pdf.getPage(i);
|
219 |
+
const txt = await page.getTextContent();
|
220 |
+
fullText += txt.items.map((it) => it.str).join(' ') + '\n\n';
|
221 |
+
}
|
222 |
+
pdfText = fullText.trim();
|
223 |
+
alert('PDF loaded: ' + pdf.numPages + ' pages');
|
224 |
+
});
|
225 |
+
|
226 |
+
// Generate & display, then prepare PDF download
|
227 |
+
document
|
228 |
+
.getElementById('generateBtn')
|
229 |
+
.addEventListener('click', async () => {
|
230 |
+
const key = document.getElementById('apiKey').value.trim();
|
231 |
+
if (!key) return alert('Enter your OpenAI API key.');
|
232 |
+
if (!pdfText) return alert('Please upload a PDF first.');
|
233 |
+
const option = document.getElementById('optionSelect').value;
|
234 |
+
let systemPrompt = '';
|
235 |
+
let userPrompt = pdfText;
|
236 |
+
if (option === 'Generate Summary') {
|
237 |
+
systemPrompt = 'You are a smart assistant. Give a summary of the PDF.';
|
238 |
+
} else if (option === 'Generate Quiz') {
|
239 |
+
systemPrompt =
|
240 |
+
'You are a smart assistant. Generate 10 multiple-choice quiz questions with 4 options each (include the correct answer).';
|
241 |
+
} else if (option === 'Ask a Question') {
|
242 |
+
systemPrompt = 'You are a smart assistant. Answer the user’s question based on the PDF.';
|
243 |
+
const q = document.getElementById('questionInput').value.trim();
|
244 |
+
if (!q) return alert('Type your question.');
|
245 |
+
userPrompt += '\n\nUser question: ' + q;
|
246 |
+
} else if (option === 'Generate Study Plan') {
|
247 |
+
systemPrompt =
|
248 |
+
'You are a smart assistant. Generate a balanced 7-day study plan dividing PDF content into 7 topics.';
|
249 |
+
}
|
250 |
+
|
251 |
+
// Call OpenAI
|
252 |
+
const responseDiv = document.getElementById('result');
|
253 |
+
responseDiv.textContent = 'Generating…';
|
254 |
+
const resp = await fetch('https://api.openai.com/v1/chat/completions', {
|
255 |
+
method: 'POST',
|
256 |
+
headers: {
|
257 |
+
'Content-Type': 'application/json',
|
258 |
+
Authorization: 'Bearer ' + key,
|
259 |
+
},
|
260 |
+
body: JSON.stringify({
|
261 |
+
model: 'gpt-4o-mini',
|
262 |
+
messages: [
|
263 |
+
{ role: 'system', content: systemPrompt },
|
264 |
+
{ role: 'user', content: userPrompt },
|
265 |
+
],
|
266 |
+
}),
|
267 |
+
});
|
268 |
+
const data = await resp.json();
|
269 |
+
const text = data.choices[0].message.content.trim();
|
270 |
+
responseDiv.textContent = text;
|
271 |
+
|
272 |
+
// Generate PDF with jsPDF
|
273 |
+
const { jsPDF } = window.jspdf;
|
274 |
+
const doc = new jsPDF();
|
275 |
+
const lines = doc.splitTextToSize(text, 180);
|
276 |
+
doc.setFontSize(12);
|
277 |
+
doc.text(lines, 10, 10);
|
278 |
+
// Show download button
|
279 |
+
const dl = document.getElementById('downloadBtn');
|
280 |
+
dl.classList.remove('d-none');
|
281 |
+
dl.onclick = () => doc.save(`${option.replace(/ /g, '_')}.pdf`);
|
282 |
+
});
|
283 |
+
</script>
|
284 |
+
</body>
|
285 |
+
</html>
|