Spaces:
Running
Running
Sammy commited on
Commit ยท
13d2389
1
Parent(s): 629e93e
Deploy latest BabelDOC kernel
Browse files- Dockerfile +90 -3
- README.md +13 -5
Dockerfile
CHANGED
|
@@ -1,8 +1,95 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
EXPOSE 7860
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
CMD ["pdf2zh", "--gui"]
|
|
|
|
| 1 |
+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
|
| 2 |
|
| 3 |
+
ARG GBABELDOCUI_REF=main
|
| 4 |
+
ARG BABELDOC_VERSION=0.6.3
|
| 5 |
+
ARG PYMUPDF_MIN_VERSION=1.26.7
|
| 6 |
|
| 7 |
+
ENV PDF2ZH_WEB_UI=1 \
|
| 8 |
+
PYTHONUNBUFFERED=1 \
|
| 9 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 10 |
+
GRADIO_SERVER_PORT=7860 \
|
| 11 |
+
BABELDOC_VERSION=${BABELDOC_VERSION} \
|
| 12 |
+
PYMUPDF_MIN_VERSION=${PYMUPDF_MIN_VERSION}
|
| 13 |
+
|
| 14 |
+
WORKDIR /app
|
| 15 |
EXPOSE 7860
|
| 16 |
|
| 17 |
+
RUN apt-get update && \
|
| 18 |
+
apt-get install --no-install-recommends -y \
|
| 19 |
+
ca-certificates \
|
| 20 |
+
curl \
|
| 21 |
+
build-essential \
|
| 22 |
+
libgl1 \
|
| 23 |
+
libglib2.0-0 \
|
| 24 |
+
libxext6 \
|
| 25 |
+
libsm6 \
|
| 26 |
+
libxrender1 && \
|
| 27 |
+
rm -rf /var/lib/apt/lists/*
|
| 28 |
+
|
| 29 |
+
# Keep the GBabelDocUI frontend, but rebuild it from source so the BabelDOC
|
| 30 |
+
# runtime is not trapped inside the stale eaiu/gbabeldocwebui:latest image.
|
| 31 |
+
RUN curl -fsSL "https://github.com/eaiu/GBabelDocUI/archive/${GBABELDOCUI_REF}.tar.gz" \
|
| 32 |
+
-o /tmp/gbabeldocui.tar.gz && \
|
| 33 |
+
tar -xzf /tmp/gbabeldocui.tar.gz --strip-components=1 -C /app && \
|
| 34 |
+
rm /tmp/gbabeldocui.tar.gz
|
| 35 |
+
|
| 36 |
+
# GBabelDocUI still declares the old BabelDOC 0.5 line. Patch only the package
|
| 37 |
+
# constraints, then let the normal project install build the same UI entrypoints.
|
| 38 |
+
RUN python - <<'PY'
|
| 39 |
+
from pathlib import Path
|
| 40 |
+
import os
|
| 41 |
+
|
| 42 |
+
pyproject = Path("pyproject.toml")
|
| 43 |
+
text = pyproject.read_text()
|
| 44 |
+
replacements = {
|
| 45 |
+
'"pymupdf<1.25.3"': f'"pymupdf>={os.environ["PYMUPDF_MIN_VERSION"]}"',
|
| 46 |
+
'"babeldoc>=0.5.20,<0.6.0"': f'"babeldoc=={os.environ["BABELDOC_VERSION"]}"',
|
| 47 |
+
}
|
| 48 |
+
for old, new in replacements.items():
|
| 49 |
+
if old not in text:
|
| 50 |
+
raise SystemExit(f"Expected dependency constraint not found: {old}")
|
| 51 |
+
text = text.replace(old, new)
|
| 52 |
+
pyproject.write_text(text)
|
| 53 |
+
PY
|
| 54 |
+
|
| 55 |
+
RUN uv pip install --system --no-cache --compile-bytecode .
|
| 56 |
+
|
| 57 |
+
# Build-time proof: fail the Space build if the deployed kernel is not the
|
| 58 |
+
# requested BabelDOC line or if PyMuPDF is still on the old incompatible line.
|
| 59 |
+
RUN python - <<'PY'
|
| 60 |
+
from importlib.metadata import version, PackageNotFoundError
|
| 61 |
+
import os
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def parse_version(value: str) -> tuple[int, ...]:
|
| 65 |
+
parts = []
|
| 66 |
+
for token in value.replace('-', '.').split('.'):
|
| 67 |
+
if token.isdigit():
|
| 68 |
+
parts.append(int(token))
|
| 69 |
+
else:
|
| 70 |
+
digits = ''.join(ch for ch in token if ch.isdigit())
|
| 71 |
+
if digits:
|
| 72 |
+
parts.append(int(digits))
|
| 73 |
+
break
|
| 74 |
+
return tuple(parts)
|
| 75 |
+
|
| 76 |
+
required = os.environ["BABELDOC_VERSION"]
|
| 77 |
+
actual = version("babeldoc")
|
| 78 |
+
if actual != required:
|
| 79 |
+
raise SystemExit(f"BabelDOC mismatch: expected {required}, got {actual}")
|
| 80 |
+
|
| 81 |
+
pymupdf_actual = version("pymupdf")
|
| 82 |
+
pymupdf_min = os.environ["PYMUPDF_MIN_VERSION"]
|
| 83 |
+
if parse_version(pymupdf_actual) < parse_version(pymupdf_min):
|
| 84 |
+
raise SystemExit(f"PyMuPDF too old: expected >= {pymupdf_min}, got {pymupdf_actual}")
|
| 85 |
+
|
| 86 |
+
for pkg in ["pdf2zh-gbabeldocui", "babeldoc", "pymupdf", "cryptography", "onnx"]:
|
| 87 |
+
try:
|
| 88 |
+
print(f"{pkg}=={version(pkg)}")
|
| 89 |
+
except PackageNotFoundError:
|
| 90 |
+
print(f"{pkg}=not-installed")
|
| 91 |
+
PY
|
| 92 |
+
|
| 93 |
+
RUN babeldoc --version && babeldoc --warmup && pdf2zh --version
|
| 94 |
+
|
| 95 |
CMD ["pdf2zh", "--gui"]
|
README.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: agpl-3.0
|
| 9 |
-
short_description: GBabelDocUI
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: GBabelDocUI Latest BabelDOC
|
| 3 |
+
emoji: ๐
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: agpl-3.0
|
| 9 |
+
short_description: GBabelDocUI rebuilt with BabelDOC 0.6.3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
GBabelDocUI frontend rebuilt from source with BabelDOC pinned to the current verified latest release.
|
| 13 |
+
|
| 14 |
+
Current deployment target:
|
| 15 |
+
|
| 16 |
+
- BabelDOC: `0.6.3`
|
| 17 |
+
- PyMuPDF: `>=1.26.7`
|
| 18 |
+
- Python: `3.13`
|
| 19 |
+
|
| 20 |
+
The Docker build prints package versions and fails if `babeldoc` is not the requested version.
|