-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
445 lines (398 loc) · 20 KB
/
Copy pathindex.html
File metadata and controls
445 lines (398 loc) · 20 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folio — AI PDF Cleaner</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;1,400&family=DM+Mono:wght@300;400&family=Instrument+Sans:wght@400;500&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf-lib/1.17.1/pdf-lib.min.js"></script>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js"></script>
<script src="https://unpkg.com/compromise"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<a class="logo" href="#"><em>Folio</em> — PDF Cleaner</a>
<span class="header-tag">AI-powered blank page removal</span>
</header>
<section class="hero">
<div>
<p class="hero-label">Document Intelligence</p>
<h1>Remove <em>empty pages</em><br>from scanned PDFs</h1>
<p class="hero-sub">Upload a scanned document. An AI vision model examines every page — handling scan noise, dust, faint artifacts — and rebuilds a clean PDF with only the pages that matter.</p>
</div>
<div class="hero-aside">
<div class="aside-stat">
<div class="aside-stat-num">3</div>
<div class="aside-stat-label">AI Providers</div>
</div>
<div class="aside-stat">
<div class="aside-stat-num">100%</div>
<div class="aside-stat-label">Client-side processing</div>
</div>
<div class="aside-stat">
<div class="aside-stat-num">∞</div>
<div class="aside-stat-label">Pages supported</div>
</div>
</div>
</section>
<div class="view-nav">
<button class="view-btn active" id="view-manual-btn" type="button" onclick="switchView('manual')">Manual Flow</button>
<button class="view-btn" id="view-automate-btn" type="button" onclick="switchView('automate')">Automate (Drive to Drive)</button>
</div>
<div id="manual-view" class="page-view active">
<div class="rule"></div>
<main>
<div>
<div class="section-label"><span>01 — Upload</span></div>
<div id="drop-zone"
onclick="document.getElementById('file-input').click()"
ondragover="event.preventDefault(); this.classList.add('drag-over')"
ondragleave="this.classList.remove('drag-over')"
ondrop="handleDrop(event)">
<div class="drop-icon">PDF</div>
<div class="drop-title">Drop your documents here</div>
<div class="drop-sub">or click to browse · multiple .pdf files supported</div>
<input type="file" id="file-input" accept=".pdf" multiple onchange="handleFile(this.files)">
</div>
<div id="file-info">
<div class="file-icon">📋</div>
<div class="file-meta">
<div class="file-name" id="file-name-display"></div>
<div class="file-size" id="file-size-display"></div>
<ul class="file-list" id="file-list"></ul>
</div>
<button class="btn-ghost" onclick="resetAll()">Remove</button>
</div>
<div class="section-label" style="margin-top:1.5rem"><span>02 — Configure</span></div>
<div class="field">
<label class="field-label">Engine & Model</label>
<div class="field-row">
<select id="provider-select" onchange="onProviderChange()">
<option value="anthropic">Anthropic</option>
<option value="openai">OpenAI</option>
<option value="openrouter">OpenRouter</option>
<option value="groq">Groq</option>
<option value="gemini">Google Gemini</option>
<option value="local">Local Non-AI</option>
</select>
<select id="model-select"></select>
</div>
</div>
<div class="field">
<label class="field-label">API Key (not required for Local mode)</label>
<div class="api-key-row">
<input type="password" id="api-key" placeholder="sk-ant-..." autocomplete="off" spellcheck="false">
<button class="toggle-vis" onclick="toggleKeyVis()">Show</button>
</div>
</div>
<div class="field">
<label class="field-label">Detection Sensitivity</label>
<div class="sens-track">
<button class="sens-btn" data-v="1" onclick="setSens(1)">Conservative</button>
<button class="sens-btn active" data-v="2" onclick="setSens(2)">Balanced</button>
<button class="sens-btn" data-v="3" onclick="setSens(3)">Aggressive</button>
</div>
</div>
<div class="field">
<label class="field-label">Google Drive Auto Upload</label>
<div class="field-row" style="margin-bottom:0.5rem;">
<input type="text" id="google-client-id" placeholder="Google OAuth Client ID">
<button class="btn-secondary" type="button" onclick="connectGoogleAccount()">Connect Google</button>
</div>
<div class="field-row" style="margin-bottom:0.5rem;">
<input type="text" id="drive-folder-id" placeholder="Drive folder ID (or create below)" onchange="syncDriveFolderId()">
<button class="btn-secondary" type="button" onclick="createDriveFolder()">Create Folder</button>
</div>
<div class="toggle-row">
<input type="checkbox" id="auto-upload-toggle">
<label for="auto-upload-toggle">Auto-upload every cleaned PDF to selected folder</label>
</div>
<div class="note-mini">Folder creation uses your Google account directly from the browser. No intermediate server is used.</div>
<div class="drive-status" id="drive-auth-status"></div>
</div>
<div id="error-box"></div>
<button id="run-btn" disabled onclick="runAgent()">Analyze & clean document →</button>
<button id="cancel-btn" class="btn-secondary" type="button" style="display:none; width:100%; margin-top:0.55rem;" onclick="cancelProcessing()">Cancel current run</button>
<button class="btn-ghost" type="button" style="width:100%; margin-top:0.55rem; text-align:center; padding: 0.6rem 0;" onclick="openMetadataStage(false)">Go to question-paper table</button>
<!-- PROGRESS -->
<div id="progress-section">
<div class="section-label" style="margin-top:2.5rem">
<span>Processing</span>
<span id="progress-count"></span>
</div>
<div class="progress-header">
<span class="progress-label" id="progress-label">Initializing…</span>
</div>
<div class="progress-rail">
<div class="progress-fill" id="progress-fill"></div>
</div>
<div class="page-chips" id="page-chips"></div>
</div>
<!-- RESULTS -->
<div id="result-section">
<div class="section-label" style="margin-top:2.5rem"><span>03 — Result</span></div>
<div class="stats-row">
<div class="stat-cell">
<div class="stat-num" id="stat-total">—</div>
<div class="stat-lbl">Total pages</div>
</div>
<div class="stat-cell">
<div class="stat-num removed" id="stat-removed">—</div>
<div class="stat-lbl">Removed</div>
</div>
<div class="stat-cell">
<div class="stat-num kept" id="stat-kept">—</div>
<div class="stat-lbl">Kept</div>
</div>
<div class="stat-cell">
<div class="stat-num" id="stat-credits">—</div>
<div class="stat-lbl">Credits used</div>
</div>
</div>
<div class="field">
<label class="field-label">Output filename</label>
<div class="output-name-wrapper">
<input type="text" id="output-name" placeholder="cleaned-document">
<span class="output-ext">.pdf</span>
</div>
</div>
<div class="action-row">
<button class="btn-primary" onclick="downloadPDF()">Download Latest</button>
<button class="btn-secondary" onclick="downloadAllPDFs()">Download All</button>
</div>
<button class="btn-secondary" onclick="downloadProcessingReport()" style="width:100%; margin-bottom:0.5rem;">Download processing report (CSV)</button>
<button class="btn-secondary" onclick="uploadLatestToDrive()" style="width:100%; margin-bottom:0.5rem;">Upload latest to Google Drive now</button>
<button class="btn-secondary" onclick="openMetadataStage(true)" style="width:100%; margin-bottom:0.5rem;">Continue to question-paper table →</button>
<div class="drive-status" id="drive-status"></div>
<div class="result-list" id="result-list"></div>
<button class="btn-ghost" onclick="resetAll()" style="width:100%; margin-top:1.5rem; text-align:center; padding: 0.6rem 0;">Process another document</button>
</div>
</div>
<!-- SIDEBAR -->
<aside class="sidebar">
<div class="section-label"><span>How it works</span></div>
<div class="sidebar-block">
<div class="sidebar-title">1. Vision analysis</div>
<div class="sidebar-body">Each page is rendered to an image. You can use either AI vision providers or a local non-AI detector that combines text-layer checks with adaptive pixel-density and connected-component analysis for strong blank-page detection.</div>
</div>
<div class="sidebar-block">
<div class="sidebar-title">2. Sensitivity modes</div>
<div class="sidebar-body">
<strong>Conservative</strong> — only truly blank pages with nothing at all.<br><br>
<strong>Balanced</strong> — blank + scan noise, dust, edge smears, faint artifacts.<br><br>
<strong>Aggressive</strong> — also removes near-empty pages: lone page numbers, stray headers, light watermarks.
</div>
</div>
<div class="sidebar-block">
<div class="sidebar-title">3. Supported providers</div>
<div class="sidebar-body">
Your API key goes directly to the provider. It is never stored, logged, or sent elsewhere.
<br><br>
<span class="provider-pill">Anthropic Claude</span>
<span class="provider-pill">OpenAI GPT-4o</span>
<span class="provider-pill">OpenRouter</span>
<span class="provider-pill">Groq</span>
<span class="provider-pill">Google Gemini</span>
<span class="provider-pill">Local Non-AI</span>
</div>
</div>
<div class="sidebar-block">
<div class="sidebar-title">Privacy</div>
<div class="sidebar-body">Your PDF is processed entirely in-browser using PDF.js and pdf-lib. Page images are sent to your chosen AI provider's API. No file ever touches an intermediary server.</div>
</div>
</aside>
</main>
</div>
<section id="automate-view" class="page-view">
<div class="rule"></div>
<div class="automate-wrap">
<div class="auto-card">
<div class="section-label"><span>Automate Setup</span></div>
<div class="auto-title">One click, full pipeline</div>
<div class="auto-sub">Connect Google, pick source and destination folders, then run a sequential pipeline that cleans pages, extracts titles, builds CSV, and uploads outputs automatically.</div>
<div class="auto-form">
<div class="auto-grid-2">
<input type="text" id="auto-google-client-id" placeholder="Google OAuth Client ID">
<button class="btn-secondary" type="button" onclick="connectGoogleAccountAuto()">Connect Google</button>
</div>
<div class="auto-grid-2">
<input type="text" id="auto-source-folder-id" placeholder="Source Drive folder ID (input PDFs)">
<button class="btn-secondary" type="button" onclick="previewSourceFolder()">Preview source</button>
</div>
<div class="auto-grid-2">
<input type="text" id="auto-destination-folder-id" placeholder="Destination Drive folder ID (outputs)">
<button class="btn-secondary" type="button" onclick="createAutoDestinationFolder()">Create destination</button>
</div>
</div>
<div class="section-label" style="margin-top:1rem"><span>Smart Mapping (Optional)</span></div>
<div class="auto-sub">Upload an Excel/CSV to auto-fill metadata and organize files into folders.</div>
<div class="field" style="margin-bottom: 0.75rem;">
<input type="file" id="auto-excel-input" accept=".xlsx, .xls, .csv" style="display:none" onchange="handleExcelUpload(this.files)">
<button class="btn-secondary" style="width:100%; border-style:dashed;" type="button" onclick="document.getElementById('auto-excel-input').click()">Upload Excel / CSV</button>
</div>
<div id="excel-mapping-zone" style="display:none">
<div class="mapping-grid">
<div class="field">
<label class="field-label">Paper Title</label>
<select id="map-title" class="map-select"><option value="">-- Skip --</option></select>
</div>
<div class="field">
<label class="field-label">Subject Code</label>
<select id="map-code" class="map-select"><option value="">-- Skip --</option></select>
</div>
<div class="field">
<label class="field-label">Year</label>
<select id="map-year" class="map-select"><option value="">-- Skip --</option></select>
</div>
<div class="field">
<label class="field-label">Department</label>
<select id="map-dept" class="map-select"><option value="">-- Skip --</option></select>
</div>
</div>
<div class="toggle-row" style="margin-top: -0.5rem; margin-bottom: 1rem;">
<input type="checkbox" id="auto-folder-logic" checked>
<label for="auto-folder-logic">Auto-create Year/Dept/Subject subfolders</label>
</div>
</div>
<div class="auto-phases">
<div class="field" style="margin-bottom: 1.25rem;">
<div class="field-row-spread">
<div class="field-label" style="color: var(--accent); font-weight: 500;">Phase 1: Page Cleaning (Vision)</div>
<div class="toggle-row-mini">
<input type="checkbox" id="auto-skip-clean">
<label for="auto-skip-clean">Skip Cleaning</label>
</div>
</div>
<div class="field-row">
<select id="auto-clean-provider" onchange="onAutoProviderChange('clean')">
<option value="local">Local (Heuristic - Free)</option>
<option value="openai">OpenAI (Vision)</option>
<option value="anthropic" selected>Anthropic (Vision)</option>
<option value="gemini">Google Gemini (Vision)</option>
<option value="groq">Groq (Vision)</option>
<option value="openrouter">OpenRouter</option>
</select>
<select id="auto-clean-model"></select>
</div>
</div>
<div class="field" style="margin-bottom: 1.25rem;">
<div class="field-row-spread">
<div class="field-label" style="color: var(--accent); font-weight: 500;">Phase 2: Metadata Extraction (Intelligence)</div>
<div class="toggle-row-mini">
<input type="checkbox" id="auto-skip-meta">
<label for="auto-skip-meta">Skip Extraction</label>
</div>
</div>
<div class="field-row">
<select id="auto-meta-provider" onchange="onAutoProviderChange('meta')">
<option value="local" selected>Local (NLP + OCR - Free)</option>
<option value="openai">OpenAI (Vision)</option>
<option value="anthropic">Anthropic (Vision)</option>
<option value="gemini">Google Gemini (Vision)</option>
<option value="groq">Groq (Vision)</option>
<option value="openrouter">OpenRouter</option>
</select>
<select id="auto-meta-model"></select>
</div>
</div>
</div>
<div class="field" style="margin-bottom: 0.75rem;">
<label class="field-label">Common API Key (Anthropic/OpenAI/etc.)</label>
<input type="password" id="auto-api-key" placeholder="sk-..." autocomplete="off" spellcheck="false">
</div>
<div class="drive-status" id="auto-drive-status"></div>
<button class="btn-primary" style="width:100%;" type="button" id="auto-run-btn" onclick="runAutomatePipeline()">Automate now</button>
<button class="btn-secondary" style="width:100%; margin-top:0.5rem;" type="button" id="auto-cancel-btn" onclick="cancelAutomatePipeline()">Cancel</button>
<div class="section-label" style="margin-top:1rem"><span>Pipeline Steps</span></div>
<ul class="auto-steps" id="auto-steps-list">
<li id="auto-step-1">1. Read PDFs from source folder</li>
<li id="auto-step-2">2. Remove empty pages in each PDF</li>
<li id="auto-step-3">3. Extract title from cleaned papers</li>
<li id="auto-step-4">4. Build downloadable CSV table</li>
<li id="auto-step-5">5. Upload cleaned PDFs + CSV to destination folder</li>
</ul>
</div>
<div class="auto-card">
<div class="section-label"><span>Live Run Log</span></div>
<div class="auto-log" id="auto-log"></div>
<div class="section-label" style="margin-top:1rem"><span>Output Table</span></div>
<div class="auto-results">
<table class="auto-table">
<thead>
<tr>
<th>Source PDF</th>
<th>Match</th>
<th>Sem</th>
<th>Code</th>
<th>Subject</th>
<th>School</th>
<th>Dept</th>
<th>Month</th>
<th>Year</th>
<th>Link</th>
</tr>
</thead>
<tbody id="auto-table-body">
<tr><td colspan="10" class="meta-empty">Run automation to populate this table.</td></tr>
</tbody>
</table>
</div>
<div class="auto-actions">
<button class="btn-secondary" type="button" onclick="downloadAutomateExcel()">Download Excel Report</button>
<button class="btn-secondary" type="button" onclick="downloadAllAutomatePdfs()">Download all cleaned PDFs</button>
</div>
</div>
</div>
</section>
<section id="metadata-stage">
<div class="section-label"><span>04 — Question Paper Table</span></div>
<div class="meta-shell">
<div class="meta-panel">
<div class="meta-title">Paper Metadata Studio</div>
<div class="meta-sub">Extract structured fields from the first page of each question paper and build a clean table.</div>
<div class="meta-stack">
<button class="btn-secondary" type="button" onclick="openMetadataStage(true)">Use cleaned PDFs from step 03</button>
<button class="btn-secondary" type="button" onclick="document.getElementById('metadata-file-input').click()">Upload question papers</button>
<input type="file" id="metadata-file-input" accept=".pdf" multiple style="display:none" onchange="handleMetadataUpload(this.files)">
<button class="btn-primary" type="button" onclick="extractMetadataTable()">Read first pages & build table</button>
<button class="btn-secondary" type="button" onclick="downloadMetadataCsv()">Download table CSV</button>
</div>
<div class="meta-papers" id="meta-papers"></div>
</div>
<div class="meta-main">
<div class="meta-toolbar">
<div class="meta-status" id="meta-status">No papers selected yet.</div>
</div>
<div class="meta-table-wrap">
<table class="meta-table" id="meta-table">
<thead>
<tr>
<th>School</th>
<th>Department(s)</th>
<th>Subject code</th>
<th>Subject</th>
<th>Month</th>
<th>Year</th>
<th>Source file</th>
</tr>
</thead>
<tbody id="meta-table-body">
<tr><td colspan="7" class="meta-empty">Run extraction to populate this table.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<footer>
<span class="footer-note">Folio — AI PDF Cleaner · All processing is client-side</span>
<span class="footer-note">Keys are never stored or shared</span>
</footer>
<script src="script.js"></script>
</body>
</html>