diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..1e7c73e2e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,49 @@ +# This is the final, recommended configuration. +# It builds a single, self-contained image with all dependencies. + +services: + pdf2zh: + build: + context: . + # All the setup steps are now part of a one-time build process. + dockerfile_inline: | + FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim + + WORKDIR /app + + # 1. Install system-level dependencies FIRST. + # This is what solves the "libGL.so.1 not found" error. + RUN apt-get update && \ + apt-get install --no-install-recommends -y libgl1 libglib2.0-0 libxext6 libsm6 libxrender1 && \ + rm -rf /var/lib/apt/lists/* + + # 2. Copy only the dependency file and install Python packages. + # This layer is cached and only re-runs if pyproject.toml changes. + COPY pyproject.toml . + RUN uv pip install --system --no-cache -r pyproject.toml + + # 3. Copy the rest of your application code. + COPY . . + + # 4. Install the local package and perform final updates/warmups. + RUN uv pip install --system --no-cache . && \ + uv pip install --system --no-cache -U "babeldoc<0.3.0" "pymupdf<1.25.3" "pdfminer-six==20250416" && \ + babeldoc --warmup + + # The rest of the configuration is for RUNNING the built image. + ports: + - "7860:7860" + + environment: + - PYTHONUNBUFFERED=1 + # The UV_LINK_MODE warning happens during build, so we can set it there if needed, + # but it's generally harmless. + + command: ["pdf2zh", "-i"] + + # Optional: Mount a volume for persistent data I/O if needed + # volumes: + # - ./data:/app/data + + stdin_open: true + tty: true \ No newline at end of file diff --git a/pdf2zh/__init__.py b/pdf2zh/__init__.py index 634a3274c..80eedd451 100644 --- a/pdf2zh/__init__.py +++ b/pdf2zh/__init__.py @@ -3,6 +3,6 @@ log = logging.getLogger(__name__) -__version__ = "1.9.9" +__version__ = "1.9.10" __author__ = "Byaidu" __all__ = ["translate", "translate_stream"] diff --git a/pdf2zh/high_level.py b/pdf2zh/high_level.py index 69cb28583..b52ff8292 100644 --- a/pdf2zh/high_level.py +++ b/pdf2zh/high_level.py @@ -126,7 +126,7 @@ def translate_patch( callback(progress) page.pageno = pageno pix = doc_zh[page.pageno].get_pixmap() - image = np.fromstring(pix.samples, np.uint8).reshape( + image = np.frombuffer(pix.samples, np.uint8).reshape( pix.height, pix.width, 3 )[:, :, ::-1] page_layout = model.predict(image, imgsz=int(pix.height / 32) * 32)[0] diff --git a/pyproject.toml b/pyproject.toml index bf94fa7a1..0c40aff58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pdf2zh" -version = "1.9.9" +version = "1.9.10" description = "Latex PDF Translator" authors = [{ name = "Byaidu", email = "byaidux@gmail.com" }] license = "AGPL-3.0" @@ -77,7 +77,7 @@ max-line-length = 88 [bumpver] -current_version = "1.9.9" +current_version = "1.9.10" version_pattern = "MAJOR.MINOR.PATCH[.PYTAGNUM]" [bumpver.file_patterns]