Skip to content

Instantly share code, notes, and snippets.

@seidtgeist
Last active July 19, 2023 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seidtgeist/019a811ef41fa0288d418657ea6067d7 to your computer and use it in GitHub Desktop.
Save seidtgeist/019a811ef41fa0288d418657ea6067d7 to your computer and use it in GitHub Desktop.
#!/bin/zsh
set -euo pipefail
SYSTEM_PROMPT=$(cat <<EOF
You're given text extracted from a PDF or OCRed from an image.
It's relating to a payment.
Analyze it step by step:
1. Summarize the text
2. Extract the following information:
- Document langauge
- Payee name
- Payee IBAN: First if multiple
- Amount
- Reference: Order/invoice/reference number
- Purpose: Short summary translated to document language
3. Respond with the following template and fill in the extracted information:
BCD
002
1
SCT
\$PAYEE_NAME
\$PAYEE_IBAN
EUR\$AMOUNT
CHAR
\$REFERENCE
\$PURPOSE
EOF
)
# 1. Extract text
# 2. Feed text into GPT4 with system prompt
# 3. Tee output to stderr for progress
# 4. Ignore stdout until beginning of EPC QR code content
# 5. Pipe EPC QR code into qr for scannable ASCII QR code output
pipx run pypdfium2 extract-text $1 | pipx run llm -m4 -s $SYSTEM_PROMPT | tee /dev/stderr | awk '/BCD/,EOF' | pipx run --spec qrcode qr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment