-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathencrypt_run_ocr.mjs
54 lines (45 loc) · 1.49 KB
/
encrypt_run_ocr.mjs
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
import {
Cape
} from "@capeprivacy/cape-sdk";
import * as fs from "fs";
import * as crypto from "crypto";
import * as pkijs from "pkijs";
// If you run this script from a node environment
// set the engine to "nodeEngine"
const name = "nodeEngine";
pkijs.setEngine(
name,
new pkijs.CryptoEngine({
name,
crypto: crypto.webcrypto
})
);
// Load your PDF
const pdf = fs.readFileSync("./Claude_Shannon.pdf");
// Get a personal access token from the UI or the CLI with
// cape token create --name ocr
const authToken = process.env.CAPE_AUTH_TOKEN;
// Instantiate a Cape object with your auth token and the URL
// "wss://ocr.capeprivacy.com". Setting the URL to wss://ocr.capeprivacy.com"
// will guarantee the OCR model is deployed to larger instances with required
// dependencies.
const cape = new Cape({
authToken,
enclaveUrl: "wss://ocr.capeprivacy.com",
});
try {
// Encrypt your PDF with cape.encrypt. When invoking this method, by default,
// the SDK will retrieve the public encryption key associated with
// your account
const encryptedPdf = await cape.encrypt(pdf);
// Invoke the OCR service on your encrypted PDF by setting the function ID to
// "capedocs/ocr-doctr-onnx-1.0"
const result = await cape.run({
id: "capedocs/ocr-doctr-onnx-1.0",
data: encryptedPdf,
});
// Print OCR transcript
console.log(JSON.parse(result).ocr_transcript);
} catch (error) {
console.error("Something went wrong", error);
}