-
Notifications
You must be signed in to change notification settings - Fork 1
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
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: islandora-openai-htr | ||
spec: | ||
selector: | ||
app: islandora-openai-htr | ||
ports: | ||
- protocol: TCP | ||
port: 8001 | ||
targetPort: 8080 | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: islandora-openai-htr | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: islandora-openai-htr | ||
template: | ||
metadata: | ||
labels: | ||
app: islandora-openai-htr | ||
spec: | ||
containers: | ||
- name: scyllaridae-tesseract | ||
image: lehighlts/scyllaridae-openai-htr:main | ||
imagePullPolicy: IfNotPresent | ||
env: | ||
- name: OPENAI_API_KEY | ||
valueFrom: | ||
secretKeyRef: | ||
name: openai | ||
key: api-key | ||
resources: | ||
requests: | ||
memory: "128Mi" | ||
cpu: "250m" | ||
limits: | ||
memory: "1Gi" | ||
ports: | ||
- hostPort: 8001 | ||
containerPort: 8080 | ||
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
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,8 @@ | ||
ARG TAG=main | ||
ARG DOCKER_REPOSITORY=lehighlts | ||
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG} | ||
|
||
ENV OPENAI_MODEL=gpt-4o-mini \ | ||
PROMPT="Transcribe this image that contains handwritten text. Include all text you see in the image. In your response, say absolutely nothing except the text from the image" \ | ||
MAX_TOKENS=300 | ||
COPY scyllaridae.yml /app/scyllaridae.yml |
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,14 @@ | ||
# openai-htr | ||
|
||
Use OpenAI ChatGPT to transcribe handwritten text. | ||
|
||
## Secrets | ||
|
||
Requires an environment variable `OPENAI_API_KEY` | ||
|
||
If deploying this in kubernetes, you can create the secret via | ||
|
||
``` | ||
kubectl create secret generic openai \ | ||
--from-literal=api-key=$OPENAI_API_KEY | ||
``` |
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 | ||
|
||
curl https://api.openai.com/v1/chat/completions \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $OPENAI_API_KEY" \ | ||
-d '{ | ||
"model": "'"$OPENAI_MODEL"'", | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": [ | ||
{ | ||
"type": "text", | ||
"text": "'"$PROMPT"'" | ||
}, | ||
{ | ||
"type": "image_url", | ||
"image_url": { | ||
"url": "'"$1"'" | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"max_tokens": '"$MAX_TOKENS"' | ||
}' | jq -r .choices[0].message.content |
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,7 @@ | ||
allowedMimeTypes: | ||
- "image/*" | ||
cmdByMimeType: | ||
default: | ||
cmd: /app/cmd.sh | ||
args: | ||
- "%source-uri" |
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