Spaces:
Running
Running
Artifact is loading slow plus the buttons still not working
Browse files
script.js
CHANGED
|
@@ -5,11 +5,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 5 |
|
| 6 |
// Camera and storage access variables
|
| 7 |
let cameraStream = null;
|
|
|
|
| 8 |
const cameraVideo = document.getElementById('cameraStream');
|
| 9 |
const captureCanvas = document.getElementById('captureCanvas');
|
| 10 |
const placeholderImage = document.getElementById('placeholderImage');
|
| 11 |
const uploadButton = document.getElementById('uploadButton');
|
| 12 |
const captureButton = document.getElementById('captureButton');
|
|
|
|
| 13 |
|
| 14 |
// Tab switching functionality
|
| 15 |
const tabButtons = document.querySelectorAll('.tab-button');
|
|
@@ -38,18 +40,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 38 |
if (initialTab) {
|
| 39 |
initialTab.classList.add('active');
|
| 40 |
}
|
| 41 |
-
const textPreview = document.querySelector('.text-preview');
|
| 42 |
-
|
| 43 |
// Request camera permission and initialize camera
|
| 44 |
-
async function initializeCamera() {
|
|
|
|
|
|
|
| 45 |
try {
|
| 46 |
cameraStream = await navigator.mediaDevices.getUserMedia({
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
cameraVideo.srcObject = cameraStream;
|
|
|
|
| 53 |
return true;
|
| 54 |
} catch (error) {
|
| 55 |
console.error('Error accessing camera:', error);
|
|
@@ -57,8 +61,7 @@ async function initializeCamera() {
|
|
| 57 |
return false;
|
| 58 |
}
|
| 59 |
}
|
| 60 |
-
|
| 61 |
-
// Capture image from camera
|
| 62 |
function captureImage() {
|
| 63 |
if (!cameraStream) {
|
| 64 |
alert('Please allow camera access first');
|
|
@@ -215,7 +218,6 @@ Due Date: 12/15/2023
|
|
| 215 |
|
| 216 |
fileInput.click();
|
| 217 |
});
|
| 218 |
-
|
| 219 |
// Capture button functionality
|
| 220 |
captureButton.addEventListener('click', async function() {
|
| 221 |
// Request camera permission if not already granted
|
|
@@ -224,13 +226,93 @@ Due Date: 12/15/2023
|
|
| 224 |
captureImage();
|
| 225 |
}
|
| 226 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
// Function to close image preview
|
| 228 |
window.closeImagePreview = function() {
|
| 229 |
const imagePreviewContainer = document.querySelector('.image-preview-container');
|
| 230 |
imagePreviewContainer.style.display = 'none';
|
| 231 |
};
|
| 232 |
});
|
| 233 |
-
|
| 234 |
// Add scanning animation styles
|
| 235 |
const style = document.createElement('style');
|
| 236 |
style.textContent = `
|
|
|
|
| 5 |
|
| 6 |
// Camera and storage access variables
|
| 7 |
let cameraStream = null;
|
| 8 |
+
let isCameraInitialized = false;
|
| 9 |
const cameraVideo = document.getElementById('cameraStream');
|
| 10 |
const captureCanvas = document.getElementById('captureCanvas');
|
| 11 |
const placeholderImage = document.getElementById('placeholderImage');
|
| 12 |
const uploadButton = document.getElementById('uploadButton');
|
| 13 |
const captureButton = document.getElementById('captureButton');
|
| 14 |
+
const textPreview = document.querySelector('.text-preview');
|
| 15 |
|
| 16 |
// Tab switching functionality
|
| 17 |
const tabButtons = document.querySelectorAll('.tab-button');
|
|
|
|
| 40 |
if (initialTab) {
|
| 41 |
initialTab.classList.add('active');
|
| 42 |
}
|
|
|
|
|
|
|
| 43 |
// Request camera permission and initialize camera
|
| 44 |
+
async function initializeCamera() {
|
| 45 |
+
if (isCameraInitialized) return true;
|
| 46 |
+
|
| 47 |
try {
|
| 48 |
cameraStream = await navigator.mediaDevices.getUserMedia({
|
| 49 |
+
video: {
|
| 50 |
+
facingMode: 'environment',
|
| 51 |
+
width: { ideal: 1280 },
|
| 52 |
+
height: { ideal: 720 }
|
| 53 |
+
}
|
| 54 |
+
);
|
| 55 |
cameraVideo.srcObject = cameraStream;
|
| 56 |
+
isCameraInitialized = true;
|
| 57 |
return true;
|
| 58 |
} catch (error) {
|
| 59 |
console.error('Error accessing camera:', error);
|
|
|
|
| 61 |
return false;
|
| 62 |
}
|
| 63 |
}
|
| 64 |
+
// Capture image from camera
|
|
|
|
| 65 |
function captureImage() {
|
| 66 |
if (!cameraStream) {
|
| 67 |
alert('Please allow camera access first');
|
|
|
|
| 218 |
|
| 219 |
fileInput.click();
|
| 220 |
});
|
|
|
|
| 221 |
// Capture button functionality
|
| 222 |
captureButton.addEventListener('click', async function() {
|
| 223 |
// Request camera permission if not already granted
|
|
|
|
| 226 |
captureImage();
|
| 227 |
}
|
| 228 |
});
|
| 229 |
+
|
| 230 |
+
// Upload button functionality
|
| 231 |
+
uploadButton.addEventListener('click', function() {
|
| 232 |
+
// Create file input for upload
|
| 233 |
+
const fileInput = document.createElement('input');
|
| 234 |
+
fileInput.type = 'file';
|
| 235 |
+
fileInput.accept = 'image/*';
|
| 236 |
+
fileInput.style.display = 'none';
|
| 237 |
+
document.body.appendChild(fileInput);
|
| 238 |
+
|
| 239 |
+
fileInput.addEventListener('change', function(e) {
|
| 240 |
+
const file = e.target.files[0];
|
| 241 |
+
if (file) {
|
| 242 |
+
// Show upload processing
|
| 243 |
+
textPreview.innerHTML = `
|
| 244 |
+
<div class="upload-animation">
|
| 245 |
+
<div class="progress-bar">
|
| 246 |
+
<div class="progress"></div>
|
| 247 |
+
</div>
|
| 248 |
+
<p><i class="fas fa-cloud-upload-alt fa-pulse"></i> Processing image...</p>
|
| 249 |
+
</div>
|
| 250 |
+
`;
|
| 251 |
+
|
| 252 |
+
const reader = new FileReader();
|
| 253 |
+
reader.onload = function(event) {
|
| 254 |
+
setTimeout(() => {
|
| 255 |
+
// Show image preview
|
| 256 |
+
const imagePreviewContainer = document.querySelector('.image-preview-container');
|
| 257 |
+
const previewImage = document.getElementById('preview-image');
|
| 258 |
+
previewImage.src = event.target.result;
|
| 259 |
+
imagePreviewContainer.style.display = 'block';
|
| 260 |
+
|
| 261 |
+
// Store and simulate OCR results with sample data
|
| 262 |
+
const result = {
|
| 263 |
+
type: 'document',
|
| 264 |
+
content: 'Invoice #INV-2023-0456\nClient: Acme Corporation\nTotal: $1,245.00\nDue Date: 12/15/2023',
|
| 265 |
+
timestamp: new Date().toISOString(),
|
| 266 |
+
imageData: event.target.result
|
| 267 |
+
};
|
| 268 |
+
scanResults.push(result);
|
| 269 |
+
|
| 270 |
+
// Show results with image preview and processed text
|
| 271 |
+
textPreview.innerHTML = `
|
| 272 |
+
<div class="result-header">
|
| 273 |
+
<div class="result-icon">
|
| 274 |
+
<i class="fas fa-file-alt"></i>
|
| 275 |
+
</div>
|
| 276 |
+
<h4>Document Analysis</h4>
|
| 277 |
+
</div>
|
| 278 |
+
<div class="result-content">
|
| 279 |
+
<p class="ocr-text">Invoice #INV-2023-0456</p>
|
| 280 |
+
<p class="ocr-text">Client: Acme Corporation</p>
|
| 281 |
+
<p class="ocr-text">Total: $1,245.00</p>
|
| 282 |
+
<p class="ocr-text">Due Date: 12/15/2023</p>
|
| 283 |
+
</div>
|
| 284 |
+
<p class="timestamp">Processed at ${new Date().toLocaleTimeString()}</p>
|
| 285 |
+
`;
|
| 286 |
+
|
| 287 |
+
// Add processed text section after results
|
| 288 |
+
const processedTextSection = document.createElement('div');
|
| 289 |
+
processedTextSection.className = 'processed-text-section';
|
| 290 |
+
processedTextSection.innerHTML = `
|
| 291 |
+
<h4>Processed Text</h4>
|
| 292 |
+
<div class="processed-text-content">
|
| 293 |
+
Invoice #INV-2023-0456
|
| 294 |
+
Client: Acme Corporation
|
| 295 |
+
Total: $1,245.00
|
| 296 |
+
Due Date: 12/15/2023
|
| 297 |
+
</div>
|
| 298 |
+
`;
|
| 299 |
+
|
| 300 |
+
textPreview.appendChild(processedTextSection);
|
| 301 |
+
}, 1500);
|
| 302 |
+
};
|
| 303 |
+
reader.readAsDataURL(file);
|
| 304 |
+
}
|
| 305 |
+
});
|
| 306 |
+
|
| 307 |
+
fileInput.click();
|
| 308 |
+
});
|
| 309 |
+
|
| 310 |
// Function to close image preview
|
| 311 |
window.closeImagePreview = function() {
|
| 312 |
const imagePreviewContainer = document.querySelector('.image-preview-container');
|
| 313 |
imagePreviewContainer.style.display = 'none';
|
| 314 |
};
|
| 315 |
});
|
|
|
|
| 316 |
// Add scanning animation styles
|
| 317 |
const style = document.createElement('style');
|
| 318 |
style.textContent = `
|
style.css
CHANGED
|
@@ -613,7 +613,6 @@ input:checked + .slider:before {
|
|
| 613 |
color: var(--primary-color);
|
| 614 |
background: rgba(124, 58, 237, 0.05);
|
| 615 |
}
|
| 616 |
-
|
| 617 |
@keyframes rotate {
|
| 618 |
from { transform: rotate(0deg); }
|
| 619 |
to { transform: rotate(360deg); }
|
|
|
|
| 613 |
color: var(--primary-color);
|
| 614 |
background: rgba(124, 58, 237, 0.05);
|
| 615 |
}
|
|
|
|
| 616 |
@keyframes rotate {
|
| 617 |
from { transform: rotate(0deg); }
|
| 618 |
to { transform: rotate(360deg); }
|