-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_ocr.py
35 lines (25 loc) · 1.01 KB
/
run_ocr.py
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
import os
import json
from pycape import Cape
auth_token_env = os.environ.get("CAPE_AUTH_TOKEN")
user_name_env = os.environ.get("USERNAME")
# Load your PDF
with open("Claude_Shannon.pdf", "rb") as f:
pdf = f.read()
# Instantiate a Cape object with the URL "wss://ocr.capeprivacy.com".
# Setting the URL to "wss://ocr.capeprivacy.com.com" will guarantee the OCR model is
# deployed to larger instances with required dependencies.
cape = Cape(url="wss://ocr.capeprivacy.com")
# Get a personal access token from the UI or the CLI with
# cape token create --name ocr
t = cape.token(auth_token_env)
# Select the Cape function you would like to invoke.
# Since we want invoke the ocr service, set the function ID
# to "capedocs/ocr-doctr-onnx-1.0"
f = cape.function("capedocs/ocr-doctr-onnx-1.0")
# Invoke the OCR service
result = cape.run(f, t, pdf)
# Print the transcript
print(f"OCR transcript: {json.loads(result)['ocr_transcript']}")
# Print the bounding boxes
print(f"OCR records: {json.loads(result)['ocr_records']}")