Skip to content

Commit 60e1127

Browse files
authored
Merge pull request #44 from SAFEHR-data/paul/refactor-forwarding-api
Refactor forwarding API
2 parents 5aabcf9 + 86a894d commit 60e1127

File tree

17 files changed

+66
-157
lines changed

17 files changed

+66
-157
lines changed

docker-compose-postgres.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ services:
185185

186186
ocr-forwarding-api:
187187
build:
188-
context: src/api
188+
context: packages/api
189189
dockerfile: Dockerfile
190190
args:
191191
<<: *build-args-common
@@ -199,7 +199,6 @@ services:
199199
ports:
200200
- "${OCR_FORWARDING_API_PORT}:${OCR_FORWARDING_API_PORT}"
201201
volumes:
202-
- ./src/api/app:/app
203202
- ${PWD}/${DATA_FOLDER}:/data
204203
networks:
205204
- pyonb_ocr_api

packages/api/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm AS app
2+
3+
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]
4+
5+
WORKDIR /app
6+
ENV PYTHONDONTWRITEBYTECODE=1
7+
ENV PYTHONUNBUFFERED=1
8+
9+
COPY ./pyproject.toml .
10+
COPY ./README.md .
11+
COPY ./src src/
12+
13+
RUN uv venv
14+
RUN --mount=type=cache,target=/root/.cache/uv,sharing=locked uv sync --no-editable --no-dev
15+
16+
# make uvicorn etc available
17+
ENV PATH="/app/.venv/bin:$PATH"
18+
19+
CMD uvicorn pyonb_api.main:app --host 0.0.0.0 --port "$OCR_FORWARDING_API_PORT" --workers 4 --use-colors

packages/api/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `pyonb` forwarding API
2+
3+
The forwarding API is used to send documents to an OCR service for processing. It provides a consistent
4+
interface for using the various OCR tools supported by `pyonb`.
5+
6+
## Usage
7+
8+
You will need to define the `OCR_FORWARDING_API_PORT` in a `.env` file.
9+
10+
Then, spin up the `ocr-forwarding-api` servicer, along with the OCR service you wish to use.
11+
For example, if you would like to use `kreuzberg`, run the following from the top-level `pyonb` directory:
12+
13+
```shell
14+
docker-compose --profile kreuzberg up --build --detach
15+
```
16+
17+
You can then use `curl` to send a PDF to the forwarding API:
18+
19+
```shell
20+
curl -v -X POST http://127.0.0.1:8110/kreuzberg-ocr/inference_single \
21+
-F "file_upload=@document.pdf" \
22+
-H "accept: application/json"
23+
```
24+
25+
Note, this assumes you have set `OCR_FORWARDING_API_PORT` to `8110`.

packages/api/pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = ["hatchling"]
4+
5+
[project]
6+
dependencies = [
7+
"aiohttp",
8+
"fastapi[standard]",
9+
"requests",
10+
"uvicorn",
11+
]
12+
description = "pyonb forwarding API"
13+
name = "pyonb-api"
14+
readme = "README.md"
15+
requires-python = ">=3.11"
16+
version = "0.1.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)