Spaces:
Build error
Build error
Update script.js
Browse files
script.js
CHANGED
|
@@ -8,9 +8,11 @@ async function startCamera() {
|
|
| 8 |
try {
|
| 9 |
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 10 |
video.srcObject = stream;
|
|
|
|
|
|
|
| 11 |
} catch (err) {
|
| 12 |
alert("Camera access denied or unavailable.");
|
| 13 |
-
console.error(err);
|
| 14 |
}
|
| 15 |
}
|
| 16 |
|
|
@@ -24,6 +26,7 @@ document.getElementById("capture").addEventListener("click", () => {
|
|
| 24 |
canvas.toBlob((blob) => {
|
| 25 |
capturedBlob = blob;
|
| 26 |
output.textContent = "Image captured. Ready to extract text.";
|
|
|
|
| 27 |
}, "image/png");
|
| 28 |
});
|
| 29 |
|
|
@@ -46,8 +49,10 @@ document.getElementById("extract").addEventListener("click", async () => {
|
|
| 46 |
|
| 47 |
if (response.ok) {
|
| 48 |
output.textContent = data.extracted_text;
|
|
|
|
| 49 |
} else {
|
| 50 |
output.textContent = `Error: ${data.message}`;
|
|
|
|
| 51 |
}
|
| 52 |
} catch (err) {
|
| 53 |
console.error("Error extracting text:", err);
|
|
@@ -55,5 +60,5 @@ document.getElementById("extract").addEventListener("click", async () => {
|
|
| 55 |
}
|
| 56 |
});
|
| 57 |
|
| 58 |
-
// Start the camera on load
|
| 59 |
startCamera();
|
|
|
|
| 8 |
try {
|
| 9 |
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 10 |
video.srcObject = stream;
|
| 11 |
+
video.play();
|
| 12 |
+
console.log("Camera started successfully.");
|
| 13 |
} catch (err) {
|
| 14 |
alert("Camera access denied or unavailable.");
|
| 15 |
+
console.error("Error accessing camera:", err);
|
| 16 |
}
|
| 17 |
}
|
| 18 |
|
|
|
|
| 26 |
canvas.toBlob((blob) => {
|
| 27 |
capturedBlob = blob;
|
| 28 |
output.textContent = "Image captured. Ready to extract text.";
|
| 29 |
+
console.log("Image captured successfully.");
|
| 30 |
}, "image/png");
|
| 31 |
});
|
| 32 |
|
|
|
|
| 49 |
|
| 50 |
if (response.ok) {
|
| 51 |
output.textContent = data.extracted_text;
|
| 52 |
+
console.log("Text extracted successfully:", data.extracted_text);
|
| 53 |
} else {
|
| 54 |
output.textContent = `Error: ${data.message}`;
|
| 55 |
+
console.error("Error extracting text:", data.message);
|
| 56 |
}
|
| 57 |
} catch (err) {
|
| 58 |
console.error("Error extracting text:", err);
|
|
|
|
| 60 |
}
|
| 61 |
});
|
| 62 |
|
| 63 |
+
// Start the camera on page load
|
| 64 |
startCamera();
|