-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.28 KB
/
index.js
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
import { useState } from 'react';
import scribe from 'scribe.js-ocr';
export default function Home() {
const [ocrText, setOcrText] = useState('');
const [isProcessing, setIsProcessing] = useState(false);
const [uploadMessage, setUploadMessage] = useState('');
const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
performOcr(file);
}
};
const performOcr = (file) => {
setIsProcessing(true);
setUploadMessage('Processing image, please wait...');
scribe.extractText([file]).then((text) => {
setOcrText(text);
setIsProcessing(false);
setUploadMessage('Image processed');
}).catch(error => {
console.error('Error:', error);
setUploadMessage('Failed to process image');
setIsProcessing(false);
});
};
return (
<div>
<h1>OCR with Scribe.js</h1>
<input type="file" onChange={handleFileChange} />
{isProcessing ? (
<p>{uploadMessage}</p>
) : (
<>
<p>{uploadMessage}</p>
<textarea value={ocrText} rows="10" cols="80" readOnly />
</>
)}
</div>
);
}