File size: 41,868 Bytes
10aaf2c
 
 
 
 
b171689
10aaf2c
 
 
 
 
dbda7b0
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9aef14
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e32a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbda7b0
10aaf2c
 
dbda7b0
 
 
 
 
 
 
 
 
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
69abcd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
b171689
10aaf2c
 
b171689
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b171689
 
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e32a60
 
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e32a60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34cedd8
 
dbda7b0
 
 
 
 
34cedd8
 
 
 
 
 
dbda7b0
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbda7b0
 
 
 
 
 
 
 
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
 
dbda7b0
34cedd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbda7b0
 
 
 
10aaf2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34cedd8
10aaf2c
 
 
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
<!DOCTYPE html>
<html lang="en" class="h-full">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OCR Time Capsule</title>
    
    <!-- External Dependencies -->
    <script src="https://unpkg.com/[email protected]"></script>
    <script src="https://unpkg.com/[email protected]/dist/cdn.min.js" defer></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    
    <!-- Tailwind Config -->
    <script>
        tailwind.config = {
            darkMode: 'class',
            theme: {
                extend: {
                    animation: {
                        'fade-in': 'fadeIn 0.3s ease-in-out',
                    },
                    keyframes: {
                        fadeIn: {
                            '0%': { opacity: '0' },
                            '100%': { opacity: '1' },
                        }
                    }
                }
            }
        }
    </script>
    
    <!-- Custom Styles -->
    <link rel="stylesheet" href="css/styles.css">
</head>
<body class="h-full bg-gray-50 dark:bg-gray-900" x-data="ocrExplorer">
    <!-- Header -->
    <header class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700">
        <div class="px-4 sm:px-6 lg:px-8 py-4">
            <div class="flex items-center justify-between">
                <div class="flex-1">
                    <div class="flex items-center space-x-4">
                        <h1 class="text-xl font-semibold text-gray-900 dark:text-white">
                            πŸ“¦ OCR Time Capsule
                        </h1>
                        <span class="text-sm text-gray-600 dark:text-gray-400 hidden sm:inline">
                            Compare original and AI-improved OCR text from historical documents
                        </span>
                    </div>
                    <div class="flex items-center space-x-2 mt-3">
                        <input 
                            type="text" 
                            x-model="datasetId"
                            @keyup.enter="loadDataset()"
                            class="px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:border-gray-600 dark:text-white"
                            placeholder="Dataset ID (e.g., username/dataset-name)"
                            style="width: 300px;"
                        >
                        <button 
                            @click="loadDataset()"
                            class="px-4 py-1.5 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500"
                        >
                            Load
                        </button>
                        
                        <!-- Example Dataset Selector -->
                        <div class="relative group">
                            <button class="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200 border border-gray-300 dark:border-gray-600 rounded-md flex items-center space-x-1">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path>
                                </svg>
                                <span>Examples</span>
                            </button>
                            <div class="absolute left-0 mt-1 w-72 bg-white dark:bg-gray-800 rounded-md shadow-lg border border-gray-200 dark:border-gray-700 hidden group-hover:block z-50">
                                <template x-for="dataset in exampleDatasets" :key="dataset.id">
                                    <button 
                                        @click="selectDataset(dataset.id)"
                                        class="block w-full text-left px-4 py-3 hover:bg-gray-50 dark:hover:bg-gray-700 border-b border-gray-100 dark:border-gray-600 last:border-b-0"
                                    >
                                        <div class="font-medium text-sm text-gray-900 dark:text-gray-100" x-text="dataset.name"></div>
                                        <div class="text-xs text-gray-500 dark:text-gray-400 mt-1" x-text="dataset.description"></div>
                                    </button>
                                </template>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- Settings -->
                <div class="flex items-center space-x-4">
                    <button
                        @click="showAbout = !showAbout"
                        class="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-200"
                        title="About this tool"
                    >
                        <svg class="w-5 h-5 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                        <span class="hidden sm:inline">About</span>
                    </button>
                    
                    <button
                        @click="darkMode = !darkMode"
                        class="p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
                        title="Toggle dark mode"
                    >
                        <svg x-show="!darkMode" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
                        </svg>
                        <svg x-show="darkMode" class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path>
                        </svg>
                    </button>
                    
                    <select
                        x-model="diffMode"
                        class="px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
                    >
                        <option value="char">Character Diff</option>
                        <option value="word">Word Diff</option>
                        <option value="line">Line Diff</option>
                        <option value="markdown" x-show="hasMarkdown">Markdown Diff</option>
                    </select>
                    
                    <button
                        x-show="hasMarkdown"
                        @click="renderMarkdown = !renderMarkdown"
                        :class="renderMarkdown ? 'bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300' : 'text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200'"
                        class="p-2 rounded-md transition-colors"
                        title="Toggle markdown rendering"
                    >
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                        </svg>
                    </button>
                    
                    <button
                        @click="exportComparison()"
                        class="p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
                        title="Export comparison"
                    >
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                        </svg>
                    </button>
                    
                    <!-- Copy Link Button -->
                    <div class="relative">
                        <button
                            @click="copyShareLink()"
                            class="p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
                            title="Copy shareable link"
                        >
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"></path>
                            </svg>
                        </button>
                        
                        <!-- Success Toast -->
                        <div
                            x-show="showShareSuccess"
                            x-transition
                            class="absolute right-0 top-12 bg-green-600 text-white px-3 py-2 rounded-md shadow-lg whitespace-nowrap z-50"
                        >
                            <div class="flex items-center gap-2">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                                </svg>
                                <span class="text-sm">Link copied!</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>
    
    <!-- About Panel -->
    <div x-show="showAbout" x-transition class="bg-blue-50 dark:bg-blue-950/30 border-b border-blue-200 dark:border-blue-800">
        <div class="px-4 sm:px-6 lg:px-8 py-6">
            <div class="max-w-4xl">
                <h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-3">About OCR Time Capsule</h2>
                <div class="prose prose-sm dark:prose-invert text-gray-700 dark:text-gray-300">
                    <p class="mb-3">
                        OCR Time Capsule helps researchers and digital humanities professionals compare original OCR text 
                        with AI-improved versions from historical documents. This tool is designed for browsing pre-processed 
                        OCR improvements stored in HuggingFace datasets.
                    </p>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                        <div>
                            <h3 class="font-medium mb-2">🎯 Use Cases</h3>
                            <ul class="list-disc list-inside space-y-1 text-sm">
                                <li>Review OCR corrections from historical newspapers</li>
                                <li>Quality assessment of digitization projects</li>
                                <li>Training data validation for OCR models</li>
                                <li>Accessibility improvements for scanned texts</li>
                            </ul>
                        </div>
                        <div>
                            <h3 class="font-medium mb-2">⚑ Key Features</h3>
                            <ul class="list-disc list-inside space-y-1 text-sm">
                                <li>Side-by-side text comparison</li>
                                <li>Character, word, and line-level diffs</li>
                                <li>Keyboard navigation (J/K or arrows)</li>
                                <li>Direct HuggingFace dataset integration</li>
                            </ul>
                        </div>
                    </div>
                    <p class="text-sm">
                        πŸ’‘ <strong>Tip:</strong> For live OCR processing with vision-language models, check out 
                        <a href="https://huggingface.co/spaces/davanstrien/ocr-time-machine" class="text-blue-600 dark:text-blue-400 underline">OCR Time Machine</a>.
                        OCR Time Capsule focuses on exploring already-processed datasets for faster navigation and analysis.
                    </p>
                </div>
                <button 
                    @click="showAbout = false"
                    class="mt-4 text-sm text-blue-600 dark:text-blue-400 hover:underline"
                >
                    Close
                </button>
            </div>
        </div>
    </div>
    
    <!-- Main Content -->
    <main class="h-full flex">
        <!-- Loading State -->
        <div x-show="loading" class="flex-1 flex items-center justify-center">
            <div class="text-center">
                <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
                <p class="mt-4 text-gray-600 dark:text-gray-400">Loading dataset...</p>
            </div>
        </div>
        
        <!-- Error State -->
        <div x-show="error" class="flex-1 flex items-center justify-center p-8">
            <div class="max-w-md w-full bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-6">
                <h3 class="text-lg font-medium text-red-800 dark:text-red-400 mb-2">Error</h3>
                <p class="text-red-600 dark:text-red-300" x-text="error"></p>
                <button 
                    @click="error = null; loadDataset()"
                    class="mt-4 px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700"
                >
                    Try Again
                </button>
            </div>
        </div>
        
        <!-- Content Area -->
        <div x-show="!loading && !error && currentSample" class="flex-1 flex h-full">
            <!-- Image Panel -->
            <div class="w-1/3 bg-gray-100 dark:bg-gray-800 p-4 overflow-y-auto border-r border-gray-200 dark:border-gray-700">
                <div>
                    <div class="bg-white dark:bg-gray-700 rounded-lg shadow-sm overflow-hidden">
                        <img 
                            :src="getImageSrc()" 
                            :alt="`Page ${currentIndex + 1}`"
                            class="w-full h-auto"
                            @error="handleImageError"
                        >
                        <div class="p-3 border-t border-gray-200 dark:border-gray-600">
                            <p class="text-sm text-gray-600 dark:text-gray-400">
                                <span x-text="`Page ${currentIndex + 1} of ${totalSamples || '?'}`"></span>
                                <span x-show="getImageDimensions()" class="ml-2">
                                    β€’ <span x-text="getImageDimensions()"></span>
                                </span>
                            </p>
                        </div>
                    </div>
                    
                    <!-- Model Info Panel -->
                    <div x-show="modelInfo" x-transition class="mt-4 bg-white dark:bg-gray-700 rounded-lg shadow-sm p-4">
                        <h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3 flex items-center">
                            <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                            </svg>
                            Model Information
                        </h3>
                        <div class="space-y-2 text-xs">
                            <div class="flex justify-between items-center">
                                <span class="text-gray-600 dark:text-gray-400">Model</span>
                                <span class="font-medium text-gray-900 dark:text-gray-100" x-text="modelInfo?.modelName || '-'"></span>
                            </div>
                            <div x-show="modelInfo?.processingDate" class="flex justify-between items-center">
                                <span class="text-gray-600 dark:text-gray-400">Processed</span>
                                <span class="text-gray-900 dark:text-gray-100" x-text="modelInfo?.processingDate || '-'"></span>
                            </div>
                            <div x-show="modelInfo?.batchSize" class="flex justify-between items-center">
                                <span class="text-gray-600 dark:text-gray-400">Batch Size</span>
                                <span class="text-gray-900 dark:text-gray-100" x-text="modelInfo?.batchSize || '-'"></span>
                            </div>
                            <div x-show="modelInfo?.maxTokens" class="flex justify-between items-center">
                                <span class="text-gray-600 dark:text-gray-400">Max Tokens</span>
                                <span class="text-gray-900 dark:text-gray-100" x-text="modelInfo?.maxTokens?.toLocaleString() || '-'"></span>
                            </div>
                            <div x-show="modelInfo?.scriptUrl" class="mt-2 pt-2 border-t border-gray-200 dark:border-gray-600">
                                <a :href="modelInfo?.scriptUrl" 
                                   target="_blank"
                                   class="text-blue-600 dark:text-blue-400 hover:underline flex items-center">
                                    <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
                                    </svg>
                                    View Script
                                </a>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Statistics Panel -->
                    <div class="mt-4 bg-white dark:bg-gray-700 rounded-lg shadow-sm p-4">
                        <h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">OCR Quality Metrics</h3>
                        <div class="space-y-2">
                            <div class="flex justify-between items-center">
                                <span class="text-xs text-gray-600 dark:text-gray-400">Similarity</span>
                                <span class="text-xs font-medium text-gray-900 dark:text-gray-100" x-text="`${similarity}%`"></span>
                            </div>
                            <div class="w-full bg-gray-200 dark:bg-gray-600 rounded-full h-2">
                                <div class="bg-blue-600 h-2 rounded-full transition-all duration-300" :style="`width: ${similarity}%`"></div>
                            </div>
                            
                            <div class="grid grid-cols-3 gap-2 mt-3">
                                <div class="text-center">
                                    <div class="text-lg font-semibold text-gray-900 dark:text-gray-100" x-text="charStats.total || '-'"></div>
                                    <div class="text-xs text-gray-600 dark:text-gray-400">Characters</div>
                                </div>
                                <div class="text-center">
                                    <div class="text-lg font-semibold text-green-600 dark:text-green-400" x-text="charStats.added || '0'"></div>
                                    <div class="text-xs text-gray-600 dark:text-gray-400">Added</div>
                                </div>
                                <div class="text-center">
                                    <div class="text-lg font-semibold text-red-600 dark:text-red-400" x-text="charStats.removed || '0'"></div>
                                    <div class="text-xs text-gray-600 dark:text-gray-400">Removed</div>
                                </div>
                            </div>
                            
                            <div class="mt-3 pt-3 border-t border-gray-200 dark:border-gray-600">
                                <div class="flex justify-between text-xs">
                                    <span class="text-gray-600 dark:text-gray-400">Words</span>
                                    <span class="text-gray-900 dark:text-gray-100">
                                        <span x-text="wordStats.original || '-'"></span> β†’ <span x-text="wordStats.improved || '-'"></span>
                                    </span>
                                </div>
                                <div class="mt-2 flex items-center justify-center space-x-2">
                                    <span x-show="hasMarkdown" class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-900 text-purple-800 dark:text-purple-200">
                                        <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                                        </svg>
                                        Markdown Detected
                                    </span>
                                    <span x-show="hasReasoningTrace" class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200">
                                        <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
                                        </svg>
                                        Reasoning Trace
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Text Comparison Panel -->
            <div class="flex-1 bg-white dark:bg-gray-900 overflow-hidden">
                <!-- Tab Navigation -->
                <div class="border-b border-gray-200 dark:border-gray-700">
                    <nav class="flex -mb-px">
                        <button
                            @click="activeTab = 'comparison'"
                            :class="activeTab === 'comparison' ? 'border-blue-500 text-blue-600 dark:text-blue-400' : 'border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200'"
                            class="px-6 py-3 border-b-2 font-medium text-sm transition-colors"
                        >
                            Side by Side
                        </button>
                        <button
                            @click="activeTab = 'diff'"
                            :class="activeTab === 'diff' ? 'border-blue-500 text-blue-600 dark:text-blue-400' : 'border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200'"
                            class="px-6 py-3 border-b-2 font-medium text-sm transition-colors"
                        >
                            Inline Diff
                        </button>
                        <button
                            @click="activeTab = 'improved'"
                            :class="activeTab === 'improved' ? 'border-blue-500 text-blue-600 dark:text-blue-400' : 'border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200'"
                            class="px-6 py-3 border-b-2 font-medium text-sm transition-colors"
                        >
                            Improved Only
                        </button>
                    </nav>
                </div>
                
                <!-- Tab Content -->
                <div class="p-6 overflow-y-auto" style="height: calc(100% - 49px);">
                    <!-- Side by Side Comparison -->
                    <div x-show="activeTab === 'comparison'" class="grid grid-cols-2 gap-6">
                        <div>
                            <h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Original OCR</h3>
                            <div class="prose prose-sm dark:prose-invert max-w-none">
                                <pre class="whitespace-pre-wrap font-mono text-xs bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 p-4 rounded-lg" x-text="getOriginalText()"></pre>
                            </div>
                        </div>
                        <div>
                            <h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
                                Improved OCR
                                <span x-show="renderMarkdown && hasMarkdown" class="ml-2 text-xs bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 px-2 py-1 rounded">
                                    Markdown
                                </span>
                            </h3>
                            <div class="max-w-none">
                                <div x-show="!renderMarkdown">
                                    <pre class="whitespace-pre-wrap font-mono text-xs bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 p-4 rounded-lg" x-text="getImprovedText()"></pre>
                                </div>
                                <div x-show="renderMarkdown" x-html="getImprovedTextRendered()" class="markdown-content"></div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Inline Diff -->
                    <div x-show="activeTab === 'diff'" class="prose prose-sm dark:prose-invert max-w-none">
                        <div x-html="diffHtml" class="diff-content"></div>
                    </div>
                    
                    <!-- Improved Only -->
                    <div x-show="activeTab === 'improved'" class="max-w-none">
                        <!-- Reasoning Trace Panel -->
                        <div x-show="hasReasoningTrace" class="mb-4">
                            <div class="bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg">
                                <button 
                                    @click="showReasoning = !showReasoning"
                                    class="w-full px-4 py-3 flex items-center justify-between text-left hover:bg-blue-100 dark:hover:bg-blue-950/40 transition-colors rounded-t-lg"
                                >
                                    <div class="flex items-center space-x-2">
                                        <svg class="w-5 h-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
                                        </svg>
                                        <span class="font-medium text-gray-900 dark:text-gray-100">Model Reasoning</span>
                                        <span class="text-sm text-gray-600 dark:text-gray-400" x-show="reasoningStats">
                                            (<span x-text="reasoningStats?.reasoningWords"></span> words, <span x-text="reasoningStats?.reasoningRatio"></span>% of output)
                                        </span>
                                    </div>
                                    <svg 
                                        class="w-5 h-5 text-gray-500 dark:text-gray-400 transition-transform"
                                        :class="showReasoning ? 'rotate-180' : ''"
                                        fill="none" stroke="currentColor" viewBox="0 0 24 24"
                                    >
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                                    </svg>
                                </button>
                                
                                <div x-show="showReasoning" x-collapse class="px-4 pb-4">
                                    <div class="bg-white dark:bg-gray-800 rounded-lg p-4 mt-2">
                                        <template x-if="formattedReasoning && formattedReasoning.steps.length > 0">
                                            <div class="space-y-3">
                                                <template x-for="(step, index) in formattedReasoning.steps" :key="index">
                                                    <div class="pl-4 border-l-2 border-gray-200 dark:border-gray-700">
                                                        <div class="font-medium text-sm text-gray-900 dark:text-gray-100 mb-1">
                                                            <span class="inline-block w-6 h-6 bg-blue-100 dark:bg-blue-900 text-blue-600 dark:text-blue-400 rounded-full text-center text-xs leading-6 mr-2" x-text="step.number || (index + 1)"></span>
                                                            <span x-text="step.title"></span>
                                                        </div>
                                                        <div class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap" x-text="step.content"></div>
                                                    </div>
                                                </template>
                                            </div>
                                        </template>
                                        
                                        <template x-if="!formattedReasoning || formattedReasoning.steps.length === 0">
                                            <pre class="whitespace-pre-wrap font-mono text-xs text-gray-700 dark:text-gray-300" x-text="reasoningContent"></pre>
                                        </template>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- Final Answer Content -->
                        <div x-show="hasReasoningTrace" class="mb-2">
                            <div class="flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-400 mb-2">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <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"></path>
                                </svg>
                                <span>Final Output</span>
                            </div>
                        </div>
                        
                        <div x-show="!renderMarkdown">
                            <pre class="whitespace-pre-wrap font-mono text-xs bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 p-4 rounded-lg" x-text="getImprovedText()"></pre>
                        </div>
                        <div x-show="renderMarkdown" x-html="getImprovedTextRendered()" class="markdown-content"></div>
                    </div>
                </div>
            </div>
        </div>
    </main>
    
    <!-- Navigation Footer -->
    <footer x-show="!loading && !error && currentSample" class="fixed bottom-0 left-0 right-0">
        <!-- Enhanced Visual Page Browser -->
        <div x-show="showDock" 
             x-transition:enter="transition ease-out duration-300"
             x-transition:enter-start="transform translate-y-full opacity-0"
             x-transition:enter-end="transform translate-y-0 opacity-100"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="transform translate-y-0 opacity-100"
             x-transition:leave-end="transform translate-y-full opacity-0"
             @mouseenter="showDockPreview()"
             @mouseleave="hideDockPreview()"
             class="bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 shadow-lg">
            <div class="relative px-16 py-4">
                <!-- Left scroll button -->
                <button @click="scrollDockLeft()"
                        :disabled="dockStartIndex <= 0"
                        class="absolute left-2 top-1/2 -translate-y-1/2 p-2 rounded-full bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed transition-all">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                    </svg>
                </button>
                
                <!-- Thumbnails container -->
                <div class="flex items-center justify-center space-x-3 overflow-hidden">
                    <template x-for="item in dockItems" :key="item.index">
                        <div @click="jumpToDockPage(item.index)"
                             class="relative cursor-pointer transition-all duration-200 hover:scale-105 flex-shrink-0"
                             :class="item.index === currentIndex ? 'ring-2 ring-blue-500 scale-105' : ''">
                            <img :src="item.imageSrc" 
                                 :alt="`Page ${item.index + 1}`"
                                 class="w-32 h-44 object-cover rounded shadow-lg"
                                 @error="handleFlowImageError($event, item.index)">
                            <div class="absolute bottom-0 inset-x-0 bg-gradient-to-t from-black/80 to-transparent p-2 rounded-b">
                                <p class="text-sm text-white font-medium text-center" x-text="`${item.index + 1}`"></p>
                            </div>
                        </div>
                    </template>
                </div>
                
                <!-- Right scroll button -->
                <button @click="scrollDockRight()"
                        :disabled="dockStartIndex >= totalSamples - dockVisibleCount"
                        class="absolute right-2 top-1/2 -translate-y-1/2 p-2 rounded-full bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed transition-all">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                    </svg>
                </button>
                
                <!-- Position indicator -->
                <div class="absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center space-x-2">
                    <div class="w-32 h-1 bg-gray-200 dark:bg-gray-600 rounded-full overflow-hidden">
                        <div class="h-full bg-blue-500 transition-all duration-300"
                             :style="`width: ${((dockStartIndex + Math.floor(dockVisibleCount/2)) / (totalSamples - 1)) * 100}%`"></div>
                    </div>
                    <span class="text-xs text-gray-500 dark:text-gray-400" 
                          x-text="`${dockStartIndex + 1}-${Math.min(dockStartIndex + dockVisibleCount, totalSamples)} of ${totalSamples}`"></span>
                </div>
            </div>
        </div>
        
        <!-- Navigation controls -->
        <div class="bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 px-6 py-3">
            <div class="flex items-center justify-between">
            <div class="flex items-center space-x-4">
                <button 
                    @click="previousSample()"
                    :disabled="currentIndex <= 0"
                    class="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-300 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
                >
                    ← Previous
                </button>
                
                <!-- Interactive Page Counter with Dock Trigger -->
                <div class="relative">
                    <div @mouseenter="showDockPreview()"
                         @mouseleave="hideDockPreview()"
                         class="flex items-center space-x-2 px-4 py-2 rounded-md cursor-pointer transition-all duration-200 hover:bg-gray-100 dark:hover:bg-gray-700">
                        <div class="flex items-center space-x-2">
                            <span class="text-sm font-medium text-gray-700 dark:text-gray-300">
                                Page <span x-text="currentIndex + 1"></span> of <span x-text="totalSamples || '?'"></span>
                            </span>
                            <svg class="w-4 h-4 text-gray-400 transition-transform duration-200"
                                 :class="showDock ? 'rotate-180' : ''"
                                 fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path>
                            </svg>
                        </div>
                        <!-- Visual progress bar -->
                        <div class="w-32 h-1 bg-gray-200 dark:bg-gray-600 rounded-full overflow-hidden">
                            <div class="h-full bg-blue-500 transition-all duration-300"
                                 :style="`width: ${(currentIndex / (totalSamples - 1)) * 100}%`"></div>
                        </div>
                    </div>
                </div>
                
                <div class="flex items-center space-x-1">
                    <input 
                        type="number" 
                        x-model.number="jumpToPage"
                        @keyup.enter="jumpToSample()"
                        :min="1"
                        :max="totalSamples"
                        class="w-20 px-2 py-1 text-sm border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-transparent dark:bg-gray-700 dark:border-gray-600 dark:text-white"
                        placeholder="Go to"
                    >
                    <button 
                        @click="jumpToSample()"
                        class="px-2 py-1 text-sm bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500"
                    >
                        Go
                    </button>
                </div>
                
                <button 
                    @click="nextSample()"
                    :disabled="currentIndex >= (totalSamples - 1)"
                    class="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-300 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
                >
                    Next β†’
                </button>
            </div>
            
            <div class="text-sm text-gray-500 dark:text-gray-400">
                Press <kbd class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded">J</kbd> / <kbd class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded">K</kbd> or <kbd class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded">←</kbd> / <kbd class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded">β†’</kbd> to navigate | <kbd class="px-2 py-1 bg-gray-100 dark:bg-gray-700 rounded">V</kbd> for visual browser
            </div>
        </div>
    </footer>
    
    <!-- Local Scripts -->
    <script src="js/diff-utils.js"></script>
    <script src="js/dataset-api.js"></script>
    <script src="js/reasoning-parser.js"></script>
    <script src="js/app.js"></script>
</body>
</html>