Skip to content

Commit

Permalink
fix venv
Browse files Browse the repository at this point in the history
  • Loading branch information
ipitio committed Oct 17, 2024
1 parent 5e797d4 commit 44bfa12
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/predict.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Run inference
run: |
docker run \
-v ./src:/ocr2pdf \
-v ./pdf:/ocr2pdf/pdf \
-v ./src:/app \
-v ./pdf:/app/pdf \
ghcr.io/ipitio/ocr-pdf:latest \
bash predict.sh pdf
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you want to skip building an image, just use mine:

```bash
docker run --rm \
-v ./pdf:/ocr2pdf/pdf \
-v ./pdf:/app/pdf \
ghcr.io/ipitio/ocr-pdf:latest \
bash predict.sh pdf [OCRmyPDF options]
```
Expand All @@ -77,7 +77,7 @@ git push
git pull
```

To add OCRmyPDF options, edit the command the `predict.yml` file before committing.
To add OCRmyPDF options, edit the command in the `predict.yml` file before committing.

### Self-hosted

Expand Down
2 changes: 1 addition & 1 deletion colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"# Transform them\n",
"%pip install udocker\n",
"!udocker --allow-root install\n",
"!udocker --allow-root run -v /content/pdf:/ocr2pdf/pdf ghcr.io/ipitio/ocr-pdf bash predict.sh pdf\n",
"!udocker --allow-root run -v /content/pdf:/app/pdf ghcr.io/ipitio/ocr-pdf bash predict.sh pdf\n",
"converted = os.listdir(\"pdf/done\")\n",
"\n",
"# And load\n",
Expand Down
6 changes: 3 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
predict:
container_name: ocr2pdf
build: ./src
command: bash predict.sh pdf -l eng+fra
command: bash predict.sh pdf
volumes:
- ./src:/ocr2pdf
- ./pdf:/ocr2pdf/pdf
- ./src:/app
- ./pdf:/app/pdf
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM jbarlow83/ocrmypdf-ubuntu:v16.5.0
WORKDIR /ocr2pdf
WORKDIR /app
COPY . .
RUN bash predict.sh
ENTRYPOINT []
15 changes: 6 additions & 9 deletions src/predict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@

apt_install() {
# shellcheck disable=SC2068
apt-get install -y python3 python3-pip python3-venv tesseract-ocr poppler-utils git ocrmypdf $@
}

main() {
find . -name requirements.txt -exec pip3 install --user --root-user-action ignore --break-system-packages --no-cache-dir -r {} \;
[ -z "$1" ] || find . -name main.py -exec python3 {} "${@:1}" \;
apt-get install -yqq python3 python3-pip python3-venv tesseract-ocr poppler-utils git ocrmypdf $@
}

langs=$(echo "$*" | grep -oP '(?<=-l )[^ ]+' | tr '+' '\n' | sed 's/^/tesseract-ocr-/' | sort -u | tr '\n' ' ')
if ! apt_install "$langs" 2>/dev/null; then
if ! apt_install "$langs"; then
apt-get update
apt_install "$langs"
fi
Expand All @@ -22,9 +17,11 @@ export OMP_THREAD_LIMIT=1

if [[ -e venv/bin/pip3 ]]; then
source venv/bin/activate
main "${@}"
./venv/bin/pip3 install --no-cache-dir -qr requirements.txt
[ -z "$1" ] || ./venv/bin/python3 main.py "${@:1}"
deactivate
elif [[ -f /.dockerenv ]]; then
[[ ":$PATH:" == *":/root/.local/bin:"* ]] || export PATH=$PATH:/root/.local/bin
main "${@}"
/usr/bin/pip3 install --user --break-system-packages --no-cache-dir -qr requirements.txt
[ -z "$1" ] || /usr/bin/python3 main.py "${@:1}"
fi

0 comments on commit 44bfa12

Please sign in to comment.