shaycat commited on
Commit
861b917
·
verified ·
1 Parent(s): 33f7750

integrate OCR in the admin dashboard for records uploading. I found this https://huggingface.co/reducto/RolmOCR option can you integrate this model

Browse files
Files changed (1) hide show
  1. dashboard.html +205 -8
dashboard.html CHANGED
@@ -44,11 +44,11 @@
44
  <i data-feather="map" class="h-4 w-4"></i>
45
  <span>Plot Maps</span>
46
  </a>
47
- <a href="#" class="flex items-center space-x-3 hover:bg-blue-700 px-3 py-2 rounded-md text-sm font-medium">
48
- <i data-feather="upload" class="h-4 w-4"></i>
49
- <span>OCR Import</span>
50
- </a>
51
- <a href="#" class="flex items-center space-x-3 hover:bg-blue-700 px-3 py-2 rounded-md text-sm font-medium">
52
  <i data-feather="users" class="h-4 w-4"></i>
53
  <span>Staff</span>
54
  </a>
@@ -256,9 +256,64 @@
256
  </div>
257
  </div>
258
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
- <!-- Recent Records -->
261
- <div class="bg-white shadow overflow-hidden sm:rounded-lg">
262
  <div class="px-4 py-5 sm:px-6 border-b border-gray-200">
263
  <div class="flex justify-between items-center">
264
  <h3 class="text-lg leading-6 font-medium text-gray-900">Recent Burial Records</h3>
@@ -364,9 +419,151 @@
364
  </main>
365
  </div>
366
  </div>
367
-
368
  <script>
369
  feather.replace();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  </script>
371
  </body>
372
  </html>
 
44
  <i data-feather="map" class="h-4 w-4"></i>
45
  <span>Plot Maps</span>
46
  </a>
47
+ <a href="#ocr-import" class="flex items-center space-x-3 hover:bg-blue-700 px-3 py-2 rounded-md text-sm font-medium">
48
+ <i data-feather="upload" class="h-4 w-4"></i>
49
+ <span>OCR Import</span>
50
+ </a>
51
+ <a href="#" class="flex items-center space-x-3 hover:bg-blue-700 px-3 py-2 rounded-md text-sm font-medium">
52
  <i data-feather="users" class="h-4 w-4"></i>
53
  <span>Staff</span>
54
  </a>
 
256
  </div>
257
  </div>
258
  </div>
259
+ <!-- OCR Import Modal -->
260
+ <div id="ocr-import" class="fixed z-50 inset-0 overflow-y-auto hidden">
261
+ <div class="flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
262
+ <div class="fixed inset-0 transition-opacity" aria-hidden="true">
263
+ <div class="absolute inset-0 bg-gray-500 opacity-75"></div>
264
+ </div>
265
+ <span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
266
+ <div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">
267
+ <div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
268
+ <h3 class="text-lg leading-6 font-medium text-gray-900 mb-4">OCR Document Import</h3>
269
+ <div class="mb-4">
270
+ <label class="block text-sm font-medium text-gray-700 mb-1">Upload Document</label>
271
+ <div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
272
+ <div class="space-y-1 text-center">
273
+ <div class="flex text-sm text-gray-600">
274
+ <label for="file-upload" class="relative cursor-pointer bg-white rounded-md font-medium text-blue-600 hover:text-blue-500 focus-within:outline-none">
275
+ <span>Upload a file</span>
276
+ <input id="file-upload" name="file-upload" type="file" class="sr-only" accept=".pdf,.jpg,.jpeg,.png,.tiff">
277
+ </label>
278
+ <p class="pl-1">or drag and drop</p>
279
+ </div>
280
+ <p class="text-xs text-gray-500">PDF, JPG, PNG, TIFF up to 10MB</p>
281
+ </div>
282
+ </div>
283
+ </div>
284
+ <div class="mb-4">
285
+ <label class="block text-sm font-medium text-gray-700 mb-1">Document Type</label>
286
+ <select id="doc-type" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md">
287
+ <option value="burial">Burial Record</option>
288
+ <option value="plot">Plot Map</option>
289
+ <option value="ledger">Ledger Page</option>
290
+ </select>
291
+ </div>
292
+ <div id="ocr-progress" class="hidden mb-4">
293
+ <div class="flex justify-between mb-1">
294
+ <span class="text-sm font-medium text-gray-700">Processing...</span>
295
+ <span id="progress-percent" class="text-sm font-medium text-blue-600">0%</span>
296
+ </div>
297
+ <div class="w-full bg-gray-200 rounded-full h-2.5">
298
+ <div id="progress-bar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
299
+ </div>
300
+ </div>
301
+ <div id="ocr-result" class="hidden border border-gray-200 rounded-md p-4 bg-gray-50"></div>
302
+ </div>
303
+ <div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
304
+ <button id="process-ocr" type="button" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:ml-3 sm:w-auto sm:text-sm">
305
+ Process Document
306
+ </button>
307
+ <button id="close-ocr" type="button" class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
308
+ Cancel
309
+ </button>
310
+ </div>
311
+ </div>
312
+ </div>
313
+ </div>
314
 
315
+ <!-- Recent Records -->
316
+ <div class="bg-white shadow overflow-hidden sm:rounded-lg">
317
  <div class="px-4 py-5 sm:px-6 border-b border-gray-200">
318
  <div class="flex justify-between items-center">
319
  <h3 class="text-lg leading-6 font-medium text-gray-900">Recent Burial Records</h3>
 
419
  </main>
420
  </div>
421
  </div>
 
422
  <script>
423
  feather.replace();
424
+
425
+ // OCR Modal Handling
426
+ const ocrModal = document.getElementById('ocr-import');
427
+ const closeBtn = document.getElementById('close-ocr');
428
+ const processBtn = document.getElementById('process-ocr');
429
+ const fileInput = document.getElementById('file-upload');
430
+ const ocrProgress = document.getElementById('ocr-progress');
431
+ const progressBar = document.getElementById('progress-bar');
432
+ const progressPercent = document.getElementById('progress-percent');
433
+ const ocrResult = document.getElementById('ocr-result');
434
+
435
+ // Show modal when OCR Import is clicked in sidebar
436
+ document.querySelector('a[href="#ocr-import"]').addEventListener('click', (e) => {
437
+ e.preventDefault();
438
+ ocrModal.classList.remove('hidden');
439
+ });
440
+
441
+ // Close modal
442
+ closeBtn.addEventListener('click', () => {
443
+ ocrModal.classList.add('hidden');
444
+ resetOCRForm();
445
+ });
446
+
447
+ // Reset form
448
+ function resetOCRForm() {
449
+ fileInput.value = '';
450
+ ocrProgress.classList.add('hidden');
451
+ ocrResult.classList.add('hidden');
452
+ ocrResult.innerHTML = '';
453
+ progressBar.style.width = '0%';
454
+ progressPercent.textContent = '0%';
455
+ }
456
+
457
+ // Process OCR
458
+ processBtn.addEventListener('click', async () => {
459
+ const file = fileInput.files[0];
460
+ if (!file) {
461
+ alert('Please select a file first');
462
+ return;
463
+ }
464
+
465
+ ocrProgress.classList.remove('hidden');
466
+ processBtn.disabled = true;
467
+
468
+ // Simulate progress
469
+ let progress = 0;
470
+ const progressInterval = setInterval(() => {
471
+ progress += 10;
472
+ progressBar.style.width = `${progress}%`;
473
+ progressPercent.textContent = `${progress}%`;
474
+
475
+ if (progress >= 100) {
476
+ clearInterval(progressInterval);
477
+ processOCRFile(file);
478
+ }
479
+ }, 300);
480
+ });
481
+
482
+ // Call RolmOCR API
483
+ async function processOCRFile(file) {
484
+ const formData = new FormData();
485
+ formData.append('file', file);
486
+ formData.append('doc_type', document.getElementById('doc-type').value);
487
+
488
+ try {
489
+ const response = await fetch('https://api-inference.huggingface.co/models/reducto/RolmOCR', {
490
+ method: 'POST',
491
+ headers: {
492
+ 'Authorization': 'Bearer YOUR_HUGGINGFACE_API_KEY',
493
+ },
494
+ body: formData
495
+ });
496
+
497
+ const result = await response.json();
498
+
499
+ if (response.ok) {
500
+ displayOCRResults(result);
501
+ } else {
502
+ throw new Error(result.error || 'OCR processing failed');
503
+ }
504
+ } catch (error) {
505
+ console.error('OCR Error:', error);
506
+ alert(`Error processing document: ${error.message}`);
507
+ } finally {
508
+ processBtn.disabled = false;
509
+ }
510
+ }
511
+
512
+ // Display OCR results
513
+ function displayOCRResults(data) {
514
+ ocrResult.classList.remove('hidden');
515
+
516
+ if (data.text) {
517
+ // Simple display - you might want to parse and format this better
518
+ ocrResult.innerHTML = `
519
+ <h4 class="font-medium text-gray-900 mb-2">Extracted Text:</h4>
520
+ <div class="text-sm text-gray-700 whitespace-pre-line">${data.text}</div>
521
+ <div class="mt-4">
522
+ <button class="bg-blue-600 text-white px-3 py-1 rounded text-sm hover:bg-blue-700">
523
+ Import to Records
524
+ </button>
525
+ </div>
526
+ `;
527
+ } else {
528
+ ocrResult.innerHTML = '<p class="text-red-500">No text could be extracted from this document.</p>';
529
+ }
530
+ }
531
+
532
+ // Drag and drop functionality
533
+ const dropArea = document.querySelector('.border-dashed');
534
+
535
+ ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
536
+ dropArea.addEventListener(eventName, preventDefaults, false);
537
+ });
538
+
539
+ function preventDefaults(e) {
540
+ e.preventDefault();
541
+ e.stopPropagation();
542
+ }
543
+
544
+ ['dragenter', 'dragover'].forEach(eventName => {
545
+ dropArea.addEventListener(eventName, highlight, false);
546
+ });
547
+
548
+ ['dragleave', 'drop'].forEach(eventName => {
549
+ dropArea.addEventListener(eventName, unhighlight, false);
550
+ });
551
+
552
+ function highlight() {
553
+ dropArea.classList.add('border-blue-500');
554
+ }
555
+
556
+ function unhighlight() {
557
+ dropArea.classList.remove('border-blue-500');
558
+ }
559
+
560
+ dropArea.addEventListener('drop', handleDrop, false);
561
+
562
+ function handleDrop(e) {
563
+ const dt = e.dataTransfer;
564
+ const files = dt.files;
565
+ fileInput.files = files;
566
+ }
567
  </script>
568
  </body>
569
  </html>