crazylemonade commited on
Commit
bb6c6fa
·
verified ·
1 Parent(s): 9c8e9b1

Delete Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +0 -166
Dockerfile DELETED
@@ -1,166 +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
- # ── OCR ROUTING ARCHITECTURE ──────────────────────────────────────────────────
7
- #
8
- # FAST PATH (images: jpg/png/webp/bmp/heic/etc)
9
- # rapidocr-onnxruntime ≥ 1.3.22
10
- # - Pure ONNX inference — no PaddleOCR / paddlepaddle needed
11
- # - Models bundled in the pip wheel (~50 MB); no first-use download
12
- # - Target latency: 1–5 s on CPU
13
- # Multi-pass: if RapidOCR confidence < 0.65 → MinerU fallback automatically
14
- #
15
- # HEAVY PATH (PDFs, multi-page, forms with layout)
16
- # MinerU (magic-pdf pipeline backend)
17
- # - Layout detection (doclayout_yolo)
18
- # - OCR (paddleocr2pytorch — PyTorch reimplementation bundled in wheel)
19
- # - Markdown reconstruction
20
- # - Target latency: 5–30 s on CPU
21
- #
22
- # ── ROOT CAUSE HISTORY ────────────────────────────────────────────────────────
23
- #
24
- # FAILURE 1: [full-cpu] is NOT a valid extra → pip silently installs base only
25
- # Fix: magic-pdf[full]==1.3.12
26
- #
27
- # FAILURE 2: opencv non-headless conflict
28
- # Fix: Layer 4 force-reinstall of opencv-python-headless
29
- #
30
- # FAILURE 3: ch_PP-OCRv3_det_infer.pth not in HF repo (repo updated to v5)
31
- # Fix: Layer 3.5 patches models_config.yml inside installed wheel:
32
- # ch_PP-OCRv3_det → ch_PP-OCRv5_det (all ch* langs)
33
- # en_PP-OCRv3_det → Multilingual_PP-OCRv3_det (en, latin)
34
- # Arch safety: both replacement stems verified in arch_config.yaml
35
- #
36
- # ── System packages ────────────────────────────────────────────────────────────
37
- # libgl1 — OpenCV needs libGL.so.1 for ALL image operations (not just GUI)
38
- # libglib2.0-0 — GLib; required by OpenCV and many C extensions
39
- # libgomp1 — OpenMP; required by ONNX Runtime and YOLO inference
40
- # poppler-utils — pdfinfo/pdftoppm; used by MinerU PDF pre-processing
41
- # ─────────────────────────────────────────────────────────────────────────────
42
-
43
- FROM python:3.10-slim
44
-
45
- ENV PYTHONUNBUFFERED=1
46
- ENV PYTHONDONTWRITEBYTECODE=1
47
- ENV PORT=7860
48
- ENV MINERU_DEVICE_MODE=cpu
49
- ENV MINERU_BACKEND=pipeline
50
-
51
- # ── System dependencies ────────────────────────────────────────────────────────
52
- RUN apt-get update \
53
- && apt-get install -y --no-install-recommends \
54
- libgl1 \
55
- libglib2.0-0 \
56
- libgomp1 \
57
- poppler-utils \
58
- && rm -rf /var/lib/apt/lists/*
59
-
60
- WORKDIR /app
61
-
62
- # ── Layer 1: FastAPI + lightweight runtime deps ───────────────────────────────
63
- # rapidocr-onnxruntime: ONNX-based fast OCR engine; models bundled in wheel.
64
- # - requires onnxruntime (will be auto-resolved or overridden by magic-pdf deps)
65
- # - requires numpy, pyclipper, shapely — all covered by magic-pdf[full]
66
- # - ~50 MB wheel; zero first-use model download needed
67
- # opencv-python-headless: placeholder; will be force-reinstalled in Layer 4
68
- RUN pip install --no-cache-dir --timeout 300 \
69
- "fastapi>=0.115.0" \
70
- "uvicorn[standard]>=0.32.0" \
71
- "python-multipart>=0.0.12" \
72
- "Pillow>=10.0.0" \
73
- "pillow-heif>=0.18.0" \
74
- "huggingface_hub>=0.25.0" \
75
- "opencv-python-headless>=4.8.0" \
76
- "rapidocr-onnxruntime>=1.3.22" \
77
- "python-docx>=1.1.0" \
78
- "python-pptx>=0.6.23" \
79
- "openpyxl>=3.1.0"
80
-
81
- # ── Layer 2: CPU-only PyTorch — MUST precede magic-pdf ───────────────────────
82
- # PyPI serves the CUDA-enabled torch wheel by default (~2.5 GB).
83
- # Installing from the official CPU wheel index first causes pip to treat the
84
- # already-installed CPU build as satisfying magic-pdf's torch requirement.
85
- RUN pip install --no-cache-dir --timeout 600 \
86
- --index-url https://download.pytorch.org/whl/cpu \
87
- "torch>=2.2.2,!=2.5.0,!=2.5.1,<3" \
88
- "torchvision>=0.15.2"
89
-
90
- # ── Layer 3: magic-pdf with the CORRECT extras ────────────────────────────────
91
- # [full] provides ultralytics, doclayout-yolo==0.0.2b1, rapid-table, shapely,
92
- # pyclipper, omegaconf, matplotlib, ftfy, dill, PyYAML, openai, albumentations.
93
- # doclayout-yolo==0.0.2b1 is ONLY on the myhloli index — not on PyPI.
94
- # onnxruntime resolved automatically as transitive dep of rapid-table.
95
- RUN pip install --no-cache-dir --timeout 600 \
96
- --extra-index-url https://myhloli.github.io/wheels/ \
97
- "magic-pdf[full]==1.3.12"
98
-
99
- # ── Layer 3.5: Patch OCR model config ────────────────────────────────────────
100
- # HF repo opendatalab/PDF-Extract-Kit-1.0 was updated to v5 det models.
101
- # magic-pdf 1.3.12 models_config.yml still references v3 det files (absent).
102
- # This patch runs at build time so download_models.py fetches correct files.
103
- RUN python3 - <<'PYEOF'
104
- import sys, yaml
105
- from pathlib import Path
106
- import magic_pdf
107
-
108
- pkg = Path(magic_pdf.__file__).parent
109
- cfg_path = pkg / 'model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/models_config.yml'
110
- arch_path = pkg / 'model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/arch_config.yaml'
111
-
112
- print(f"Patching: {cfg_path}")
113
-
114
- with open(cfg_path) as f:
115
- config = yaml.safe_load(f)
116
- with open(arch_path) as f:
117
- arch_text = f.read()
118
-
119
- DET_MAP = {
120
- 'ch_PP-OCRv3_det_infer.pth': 'ch_PP-OCRv5_det_infer.pth',
121
- 'en_PP-OCRv3_det_infer.pth': 'Multilingual_PP-OCRv3_det_infer.pth',
122
- }
123
-
124
- patched = 0
125
- for lang, files in config['lang'].items():
126
- old = files.get('det', '')
127
- if old in DET_MAP:
128
- new = DET_MAP[old]
129
- arch_key = new[:-4]
130
- if (arch_key + ':') not in arch_text:
131
- print(f"ERROR: arch key '{arch_key}' not found in arch_config.yaml", file=sys.stderr)
132
- sys.exit(1)
133
- files['det'] = new
134
- print(f" [{lang}] det: {old} -> {new}")
135
- patched += 1
136
-
137
- with open(cfg_path, 'w') as f:
138
- yaml.dump(config, f, default_flow_style=False, allow_unicode=True)
139
-
140
- print(f"Patched {patched} language entries. models_config.yml updated.")
141
- PYEOF
142
-
143
- # ── Layer 4: Restore headless OpenCV ─────────────────────────────────────────
144
- # Layer 3 pulled opencv-python (non-headless) via doclayout-yolo/ultralytics/
145
- # rapid-table. Force-reinstall headless build so cv2 works on this slim image.
146
- RUN pip install --no-cache-dir --timeout 300 \
147
- --force-reinstall \
148
- "opencv-python-headless>=4.8.0"
149
-
150
- # ── Application code ──────────────────────────────────────────────────────────
151
- COPY download_models.py .
152
- COPY validate.py .
153
- COPY main.py .
154
- COPY entrypoint.sh .
155
- RUN chmod +x entrypoint.sh
156
-
157
- # ── Download models at build time ─────────────────────────────────────────────
158
- # MFR (formula recognition, ~1-2 GB) excluded — disabled in config.
159
- # rapidocr-onnxruntime models are BUNDLED in the pip wheel; no download needed.
160
- RUN python download_models.py
161
-
162
- RUN mkdir -p /app/config && cp /root/magic-pdf.json /app/config/magic-pdf.json
163
-
164
- # ── Runtime ───────────────────────────────────────────────────────────────────
165
- EXPOSE 7860
166
- ENTRYPOINT ["/app/entrypoint.sh"]