-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: islandora-ocrpdf | ||
spec: | ||
selector: | ||
app: islandora-ocrpdf | ||
ports: | ||
- protocol: TCP | ||
port: 8886 | ||
targetPort: 8080 | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: islandora-ocrpdf | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: islandora-ocrpdf | ||
template: | ||
metadata: | ||
labels: | ||
app: islandora-ocrpdf | ||
spec: | ||
containers: | ||
- name: scyllaridae-ocrpdf | ||
image: lehighlts/scyllaridae-ocrpdf:main | ||
imagePullPolicy: IfNotPresent | ||
resources: | ||
requests: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
limits: | ||
memory: "1Gi" | ||
ports: | ||
- containerPort: 8080 | ||
hostPort: 8886 | ||
readinessProbe: | ||
httpGet: | ||
path: /healthcheck | ||
port: 8080 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ARG TAG=main | ||
ARG DOCKER_REPOSITORY=local | ||
FROM ${DOCKER_REPOSITORY}/scyllaridae-imagemagick:${TAG} AS scyllaridae | ||
|
||
RUN apk update && \ | ||
apk add --no-cache \ | ||
ghostscript==10.04.0-r0 \ | ||
jq==1.7.1-r0 \ | ||
leptonica-dev==1.84.1-r0 \ | ||
tesseract-ocr==5.3.4-r0 \ | ||
tesseract-ocr-data-eng==5.3.4-r0 \ | ||
tesseract-ocr-data-fra==5.3.4-r0 \ | ||
tesseract-ocr-data-spa==5.3.4-r0 \ | ||
tesseract-ocr-data-ita==5.3.4-r0 \ | ||
tesseract-ocr-data-por==5.3.4-r0 \ | ||
tesseract-ocr-data-hin==5.3.4-r0 \ | ||
tesseract-ocr-data-deu==5.3.4-r0 \ | ||
tesseract-ocr-data-jpn==5.3.4-r0 \ | ||
tesseract-ocr-data-rus==5.3.4-r0 \ | ||
poppler-utils==24.02.0-r1 | ||
|
||
COPY . /app | ||
|
||
ENTRYPOINT ["/app/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ocrpdf | ||
|
||
Add OCR to PDF with no OCR | ||
|
||
## Install | ||
|
||
### Deploy microservice | ||
|
||
|
||
#### docker-compose | ||
|
||
Add the microservice to your docker compose | ||
|
||
``` | ||
ocrpdf-dev: &ocrpdf | ||
<<: [*dev, *common] | ||
image: lehighlts/scyllaridae-ocrpdf:main | ||
networks: | ||
default: | ||
aliases: | ||
- ocrpdf | ||
ocrpdf-prod: | ||
<<: [*prod, *ocrpdf] | ||
``` | ||
|
||
#### kubernetes | ||
|
||
See [service/deployment manifest in scyllaridae repo](https://github.com/lehigh-university-libraries/scyllaridae/blob/main/ci/k8s/ocrpdf.yaml) | ||
|
||
|
||
### Configure alpaca | ||
|
||
You'll also need to add `ocrpdf` to `derivative.systems.installed` in your `alpaca.properties` by adding that string to the `ALPACA_DERIVATIVE_SYSTEMS` environment variable in your alpaca service. | ||
|
||
``` | ||
ALPACA_DERIVATIVE_SYSTEMS=ocrpdf | ||
``` | ||
|
||
You'll also need to define the service in alpaca.properties.tmpl | ||
|
||
``` | ||
derivative.whisper.enabled=true | ||
derivative.whisper.in.stream=queue:islandora-connector-ocrpdf | ||
# this url may be different if deploying via kubernetes | ||
derivative.whisper.service.url=http://ocrpdf:8080 | ||
derivative.whisper.concurrent-consumers=1 | ||
derivative.whisper.max-concurrent-consumers=-1 | ||
derivative.whisper.async-consumer=true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eou pipefail | ||
|
||
TMP_DIR=$(mktemp -d) | ||
|
||
cd "$TMP_DIR" | ||
|
||
# split pdf into PNG files | ||
pdftoppm -r 300 - page -png | ||
|
||
# add OCR to each PNG | ||
for i in page-*.png; do | ||
tesseract "$i" "${i%.png}" --dpi 300 pdf | ||
done | ||
|
||
# put the PDF back together | ||
pdfunite page-*.pdf output.pdf | ||
|
||
# make sure the PDF is legit | ||
pdfinfo output.pdf > /dev/null || exit 1 | ||
|
||
# print the results to stdout | ||
cat output.pdf | ||
|
||
# cleanup | ||
cd /app | ||
rm -rf "$TMP_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
allowedMimeTypes: | ||
- "application/pdf" | ||
cmdByMimeType: | ||
default: | ||
cmd: /app/cmd.sh |