crazylemonade commited on
Commit
483b3f0
Β·
verified Β·
1 Parent(s): b02123d

Delete Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +0 -157
Dockerfile DELETED
@@ -1,157 +0,0 @@
1
- # ─────────────────────────────────────────────────────────────────────────────
2
- # MinerU OCR Service β€” Hugging Face Docker Space (CPU / pipeline backend)
3
- #
4
- # Optimized for FREE tier: 2 vCPU Β· 16 GB RAM Β· 50 GB Disk Β· No GPU
5
- #
6
- # ── FORENSIC ROOT CAUSE ANALYSIS (2025-06) ───────────────────────────────────
7
- #
8
- # FAILURE: "No module named 'ultralytics'"
9
- #
10
- # ROOT CAUSE 1 β€” [full-cpu] is NOT a valid extra in magic-pdf 1.3.12
11
- # Valid extras: [full], [full_old_linux], [lite]
12
- # When pip receives an unknown extra name it silently installs only the BASE
13
- # package β€” omitting ultralytics, doclayout-yolo, rapid-table, and everything
14
- # else needed for layout detection. Container booted because torch IS in the
15
- # base deps, but doc_analyze crashed at the first layout detection call.
16
- #
17
- # ROOT CAUSE 2 β€” opencv conflict
18
- # doclayout-yolo==0.0.2b1, ultralytics>=8.3.48, and rapid-table>=1.0.5 all
19
- # declare opencv-python (non-headless) as a runtime dep. pip resolves and
20
- # installs the full X11-linked opencv-python, which overwrites the cv2 module
21
- # from our earlier opencv-python-headless install.
22
- # Fix: force-reinstall opencv-python-headless as the LAST pip step so the
23
- # headless cv2 module wins. Runtime import works; pip-check shows warnings
24
- # but they are harmless β€” both packages expose an identical cv2 API.
25
- #
26
- # WHY [lite] / paddlepaddle / paddleocr ARE NOT INSTALLED
27
- # 1. paddlepaddle==3.0.0b1 (pinned by [lite]) does not exist on PyPI.
28
- # Install would fail at the paddlepaddle resolution step.
29
- # 2. paddleocr==2.7.3 requires opencv-python <=4.6.0.66, conflicting with
30
- # ultralytics>=4.6.0 and doclayout-yolo>=4.6.0.
31
- # 3. The pipeline backend NEVER uses paddlepaddle. The OCR engine for the
32
- # pipeline (full) mode is paddleocr2pytorch β€” a self-contained PyTorch
33
- # reimplementation of the PaddleOCR architecture bundled inside the
34
- # magic-pdf wheel itself. No paddlepaddle C library is required.
35
- # Confirmed by reading magic_pdf/model/sub_modules/model_init.py:
36
- # ocr_model = PytorchPaddleOCR(...) # pure torch, NOT from paddleocr pkg
37
- # pp_structure_v2.py (which imports paddleocr) is only loaded in 'lite'
38
- # model mode, which is never used by MINERU_BACKEND=pipeline.
39
- #
40
- # COMPLETE RUNTIME DEPENDENCY GRAPH (pipeline backend, CPU)
41
- # magic-pdf base: torch, torchvision, PyMuPDF, numpy, pydantic, loguru, ...
42
- # magic-pdf[full]: ultralytics, doclayout-yolo==0.0.2b1, rapid-table,
43
- # shapely, pyclipper, omegaconf, matplotlib, ftfy, dill,
44
- # PyYAML, openai, albumentations
45
- # rapid-table: onnxruntime (auto-installed as transitive dep)
46
- # opencv: opencv-python pulled by doclayout-yolo/ultralytics/rapid-table;
47
- # overridden by force-reinstall of opencv-python-headless
48
- # paddleocr2pytorch (bundled in magic-pdf wheel):
49
- # torch, numpy, cv2, pyclipper, shapely, yaml β€” all covered
50
- #
51
- # ── System packages ────────────────────────────────────────────────────────────
52
- # libgl1 β€” OpenCV needs libGL.so.1 for ALL image operations (not just GUI).
53
- # libglib2.0-0 β€” GLib; required by OpenCV and many C extensions.
54
- # libgomp1 β€” OpenMP; required by ONNX Runtime and YOLO inference.
55
- # poppler-utils β€” pdfinfo/pdftoppm; used by MinerU PDF pre-processing.
56
- # ─────────────────────────────────────────────────────────────────────────────
57
-
58
- FROM python:3.10-slim
59
-
60
- ENV PYTHONUNBUFFERED=1
61
- ENV PYTHONDONTWRITEBYTECODE=1
62
- ENV PORT=7860
63
- ENV MINERU_DEVICE_MODE=cpu
64
- ENV MINERU_BACKEND=pipeline
65
-
66
- # ── System dependencies ────────────────────────────────────────────────────────
67
- RUN apt-get update \
68
- && apt-get install -y --no-install-recommends \
69
- libgl1 \
70
- libglib2.0-0 \
71
- libgomp1 \
72
- poppler-utils \
73
- && rm -rf /var/lib/apt/lists/*
74
-
75
- WORKDIR /app
76
-
77
- # ── Layer 1: FastAPI + lightweight runtime deps ───────────────────────────────
78
- # Install opencv-python-headless here as a placeholder. It will be overridden
79
- # in Layer 4 after magic-pdf[full] installs the non-headless opencv-python via
80
- # its transitive deps (doclayout-yolo, ultralytics, rapid-table).
81
- # The force-reinstall in Layer 4 restores the headless build as the winner.
82
- RUN pip install --no-cache-dir --timeout 300 \
83
- "fastapi>=0.115.0" \
84
- "uvicorn[standard]>=0.32.0" \
85
- "python-multipart>=0.0.12" \
86
- "Pillow>=10.0.0" \
87
- "pillow-heif>=0.18.0" \
88
- "huggingface_hub>=0.25.0" \
89
- "opencv-python-headless>=4.8.0"
90
-
91
- # ── Layer 2: CPU-only PyTorch β€” MUST precede magic-pdf ───────────────────────
92
- # PyPI serves the CUDA-enabled torch wheel by default (~2.5 GB).
93
- # Installing from the official CPU wheel index first causes pip to treat the
94
- # already-installed CPU build as satisfying magic-pdf's `torch` requirement,
95
- # skipping the larger CUDA wheel. Saves ~2.5 GB of image size.
96
- RUN pip install --no-cache-dir --timeout 600 \
97
- --index-url https://download.pytorch.org/whl/cpu \
98
- "torch>=2.2.2,!=2.5.0,!=2.5.1,<3" \
99
- "torchvision>=0.15.2"
100
-
101
- # ── Layer 3: magic-pdf with the CORRECT extras ────────────────────────────────
102
- # [full] provides:
103
- # - ultralytics >=8.3.48 YOLO framework (required by doclayout-yolo)
104
- # - doclayout-yolo ==0.0.2b1 layout detection (on myhloli index only)
105
- # - rapid-table >=1.0.5 table structure detection
106
- # - shapely, pyclipper geometry; used by paddleocr2pytorch OCR
107
- # - omegaconf, matplotlib, ftfy, dill, PyYAML, openai, albumentations
108
- #
109
- # Note: doclayout-yolo==0.0.2b1 is only on the myhloli custom index, not PyPI.
110
- # --extra-index-url must be present in this layer.
111
- #
112
- # Note: rapid-table declares onnxruntime>1.17.0 as a required dep; pip will
113
- # resolve and install it automatically here β€” no explicit pin needed.
114
- #
115
- # Note: [lite] is intentionally NOT used.
116
- # - paddlepaddle==3.0.0b1 (pinned by [lite]) does not exist on PyPI.
117
- # - paddleocr==2.7.3 requires opencv-python <=4.6.0.66, incompatible with
118
- # ultralytics and doclayout-yolo (both require >=4.6.0).
119
- # - PaddleOCR is not needed: the pipeline backend uses paddleocr2pytorch,
120
- # a pure-PyTorch OCR engine bundled inside the magic-pdf wheel itself.
121
- RUN pip install --no-cache-dir --timeout 600 \
122
- --extra-index-url https://myhloli.github.io/wheels/ \
123
- "magic-pdf[full]==1.3.12"
124
-
125
- # ── Layer 4: Restore headless OpenCV ─────────────────────────────────────────
126
- # Layer 3 pulled in opencv-python (non-headless) via doclayout-yolo, ultralytics,
127
- # and rapid-table β€” all of which declare `opencv-python` as a required dep.
128
- # The full opencv-python build links against libSM, libXext, libXrender which
129
- # are NOT installed (removed to reduce image size) and would cause ImportError.
130
- # Force-reinstalling opencv-python-headless replaces the cv2 shared object with
131
- # the headless build, which works on this slim container without X11 libs.
132
- # pip-check will show "ultralytics requires opencv-python" warnings β€” these are
133
- # harmless because both packages expose an identical cv2 Python API.
134
- RUN pip install --no-cache-dir --timeout 300 \
135
- --force-reinstall \
136
- "opencv-python-headless>=4.8.0"
137
-
138
- # ── Application code ──────────────────────────────────────────────────────────
139
- COPY download_models.py .
140
- COPY validate.py .
141
- COPY main.py .
142
- COPY entrypoint.sh .
143
- RUN chmod +x entrypoint.sh
144
-
145
- # ── Download models at build time ─────────────────────────────────────────────
146
- # Baked into image = zero cold-start download delay.
147
- # Skip-if-exists logic in download_models.py gives Docker layer-cache reuse:
148
- # code-only rebuilds skip the 15-minute model download entirely.
149
- # MFR (formula recognition, ~1-2 GB) is excluded β€” disabled in config.
150
- RUN python download_models.py
151
-
152
- # Persist config; entrypoint.sh restores it if /root is wiped on restart.
153
- RUN mkdir -p /app/config && cp /root/magic-pdf.json /app/config/magic-pdf.json
154
-
155
- # ── Runtime ───────────────────────────────────────────────────────────────────
156
- EXPOSE 7860
157
- ENTRYPOINT ["/app/entrypoint.sh"]