Spaces:
Sleeping
Sleeping
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,131 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: MinerU OCR Service
|
| 3 |
-
emoji: π
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_port: 7860
|
| 8 |
-
pinned: false
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# MinerU OCR & Document Extraction Service
|
| 12 |
-
|
| 13 |
-
Production-quality OCR and document extraction API powered by **MinerU** (`magic-pdf` package), running on Hugging Face Docker Spaces β free CPU tier.
|
| 14 |
-
|
| 15 |
-
---
|
| 16 |
-
|
| 17 |
-
## Root Cause Analysis β Previous Build Failures
|
| 18 |
-
|
| 19 |
-
| Cause | Detail | Fix Applied |
|
| 20 |
-
|---|---|---|
|
| 21 |
-
| `libreoffice` in apt | ~1.5 GB installed; caused disk/OOM during build | **Removed** β DOCX/PPTX/XLSX dropped |
|
| 22 |
-
| X11 libs (`libsm6`, `libxext6`, `libxrender-dev`) | Only needed for OpenCV GUI windows (cv2.imshow); headless server never uses a display | **Removed** |
|
| 23 |
-
| `libmagic1` | C dep for python-magic, which was never imported | **Removed** |
|
| 24 |
-
| `python-magic` in pip | Listed in requirements but never used in code | **Removed** |
|
| 25 |
-
| `wget` / `curl` in apt | Runtime testing tools, not needed in container | **Removed** |
|
| 26 |
-
| Single pip layer | Any failure re-downloads all packages including 2 GB magic-pdf | **Split into 2 cached layers** |
|
| 27 |
-
| MFR models downloaded | Formula recognition (unimernet, ~1-2 GB) downloaded even though disabled | **Excluded via ignore_patterns** |
|
| 28 |
-
| `ModuleNotFoundError: magic_pdf.pipe.UNIPipe` | API removed in magic-pdf >= 1.0 | **Replaced** with current API |
|
| 29 |
-
|
| 30 |
-
---
|
| 31 |
-
|
| 32 |
-
## Supported File Types
|
| 33 |
-
|
| 34 |
-
| Category | Extensions |
|
| 35 |
-
|---|---|
|
| 36 |
-
| PDF | `.pdf` (searchable, scanned, mixed) |
|
| 37 |
-
| Images | `.jpg` `.jpeg` `.png` `.webp` `.bmp` `.tiff` `.tif` `.gif` `.heic` `.heif` `.avif` |
|
| 38 |
-
|
| 39 |
-
> DOCX / PPTX / XLSX were removed because they required LibreOffice, which caused build failures on free-tier hardware. Add them back once the base deployment is stable.
|
| 40 |
-
|
| 41 |
-
---
|
| 42 |
-
|
| 43 |
-
## API Endpoints
|
| 44 |
-
|
| 45 |
-
### `GET /health`
|
| 46 |
-
```json
|
| 47 |
-
{ "status": "healthy" }
|
| 48 |
-
```
|
| 49 |
-
|
| 50 |
-
### `GET /status`
|
| 51 |
-
```json
|
| 52 |
-
{
|
| 53 |
-
"status": "healthy",
|
| 54 |
-
"provider": "mineru",
|
| 55 |
-
"version": "1.3.12",
|
| 56 |
-
"modelsLoaded": true,
|
| 57 |
-
"uptimeSeconds": 3742,
|
| 58 |
-
"memoryUsedMB": 5200,
|
| 59 |
-
"memoryTotalMB": 16384,
|
| 60 |
-
"activeRequests": 0,
|
| 61 |
-
"cacheEntries": 3
|
| 62 |
-
}
|
| 63 |
-
```
|
| 64 |
-
|
| 65 |
-
### `POST /extract`
|
| 66 |
-
```json
|
| 67 |
-
{
|
| 68 |
-
"success": true,
|
| 69 |
-
"filename": "invoice.pdf",
|
| 70 |
-
"docType": "invoice",
|
| 71 |
-
"pageCount": 2,
|
| 72 |
-
"confidence": 0.95,
|
| 73 |
-
"markdown": "# Invoice\n\n...",
|
| 74 |
-
"metadata": {
|
| 75 |
-
"parseMethod": "txt",
|
| 76 |
-
"backend": "pipeline",
|
| 77 |
-
"cached": false,
|
| 78 |
-
"processingTimeMs": 4200,
|
| 79 |
-
"docTypeClassification": "invoice",
|
| 80 |
-
"imageCount": 0,
|
| 81 |
-
"tableCount": 1,
|
| 82 |
-
"formulaCount": 0
|
| 83 |
-
}
|
| 84 |
-
}
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
### `POST /batch`
|
| 88 |
-
```json
|
| 89 |
-
{
|
| 90 |
-
"success": true,
|
| 91 |
-
"processed": 3,
|
| 92 |
-
"results": [...]
|
| 93 |
-
}
|
| 94 |
-
```
|
| 95 |
-
|
| 96 |
-
---
|
| 97 |
-
|
| 98 |
-
## Deployment
|
| 99 |
-
|
| 100 |
-
1. Create a new Hugging Face Space β **Docker** SDK
|
| 101 |
-
2. Upload all files from this directory to the Space repo root
|
| 102 |
-
3. Space builds automatically (~20β30 min for first build; subsequent code-only rebuilds are faster due to Docker layer cache)
|
| 103 |
-
4. Test with curl:
|
| 104 |
-
|
| 105 |
-
```bash
|
| 106 |
-
curl https://<your-space>.hf.space/health
|
| 107 |
-
curl -X POST https://<your-space>.hf.space/extract -F "file=@doc.pdf"
|
| 108 |
-
curl -X POST https://<your-space>.hf.space/batch \
|
| 109 |
-
-F "files=@a.pdf" -F "files=@b.jpg" -F "files=@c.png"
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
---
|
| 113 |
-
|
| 114 |
-
## Resource Budget (free CPU Basic)
|
| 115 |
-
|
| 116 |
-
| Resource | Budget | Usage |
|
| 117 |
-
|---|---|---|
|
| 118 |
-
| Disk | 50 GB | ~8β10 GB (packages ~3 GB + models ~4β5 GB) |
|
| 119 |
-
| RAM | 16 GB | ~6β8 GB at load; peaks ~10 GB during extraction |
|
| 120 |
-
| vCPU | 2 | Single uvicorn worker; sequential batch processing |
|
| 121 |
-
|
| 122 |
-
---
|
| 123 |
-
|
| 124 |
-
## Known Limitations
|
| 125 |
-
|
| 126 |
-
1. **No DOCX/PPTX/XLSX** β dropped to make the build reliable. Re-add with LibreOffice on paid hardware.
|
| 127 |
-
2. **Formula OCR disabled** β MFR models excluded to save ~1-2 GB. Set `"enable": true` in `~/magic-pdf.json` and re-download MFR models to enable.
|
| 128 |
-
3. **First-request latency** β models are lazy-loaded into RAM on the first request (~30β60 s).
|
| 129 |
-
4. **30 MB file size limit** β enforced on both `/extract` and `/batch`.
|
| 130 |
-
5. **In-process cache** β SHA256 cache lives in RAM, cleared on container restart.
|
| 131 |
-
6. **HEIC/HEIF** β requires `pillow-heif` (included); may fail on unusual encoder variants.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|