Fresh-machine hardening from review
- util: drop dead openai/json/sys/requests/PIL extras (openai import would ImportError before engine load); ultralytics fallback path now raises (AGPL isolation - only MIT icon_detect_v3 ships) - requirements: default path only; paddle + ultralytics moved to README optional section - setup.sh: venv fallback for distros without ensurepip; --skip-weights verified - start.sh: bind 127.0.0.1 by default (LAN = explicit opt-in) - docs: absolute-path !cat examples, HF startup/airgap notes, token placement, security defaults
This commit is contained in:
1 parent
933f33e70a
commit
61a0f353cd
6 files changed
+48
-23
No files matched your search
@@ -52,6 +52,12 @@ git clone https://git.plean.rip/plean/omniparse-mcp.git && cd omniparse-mcp
|
|||||||
curl -s http://127.0.0.1:8898/healthz
|
curl -s http://127.0.0.1:8898/healthz
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`start.sh` binds **127.0.0.1 by default** — the bearer token is a static
|
||||||
|
secret, so LAN exposure is an explicit opt-in: `OMNI_API_HOST=0.0.0.0
|
||||||
|
./start.sh` (firewall it yourself). The token lives **outside the repo**
|
||||||
|
(`~/.config/omniparse_token`, mode 600, auto-generated on first start) so
|
||||||
|
clones and worktrees share it and it can never be committed.
|
||||||
|
|
||||||
`start.sh` readiness = an actual parse round-trip, not just "models loaded"
|
`start.sh` readiness = an actual parse round-trip, not just "models loaded"
|
||||||
(OCR loads lazily and its detection peak is where VRAM pressure bites).
|
(OCR loads lazily and its detection peak is where VRAM pressure bites).
|
||||||
|
|
||||||
@@ -95,9 +101,12 @@ Start the service first. Then any MCP harness — omp (`~/.omp/agent/mcp.json`):
|
|||||||
"cwd": "/path/to/omniparse-mcp",
|
"cwd": "/path/to/omniparse-mcp",
|
||||||
"timeout": 120000,
|
"timeout": 120000,
|
||||||
"env": { "OMNI_API_URL": "http://127.0.0.1:8898",
|
"env": { "OMNI_API_URL": "http://127.0.0.1:8898",
|
||||||
"OMNI_API_TOKEN": "!cat ~/.config/omniparse_token" } } } }
|
"OMNI_API_TOKEN": "!cat /home/YOU/.config/omniparse_token" } } } }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
(use an **absolute** path: `!cmd` values are exec'd without a shell in most
|
||||||
|
harnesses, so `~` never expands)
|
||||||
|
|
||||||
The shim registers one tool, `omniparse(image_path | image_b64, format,
|
The shim registers one tool, `omniparse(image_path | image_b64, format,
|
||||||
include_som)`. In omp: `/mcp reload`, then `/mcp test omniparse`. The same
|
include_som)`. In omp: `/mcp reload`, then `/mcp test omniparse`. The same
|
||||||
entry works in Claude Desktop / Cursor-class harnesses; where `!cmd` env
|
entry works in Claude Desktop / Cursor-class harnesses; where `!cmd` env
|
||||||
@@ -123,6 +132,21 @@ Florence, 1920×1080 screenshots:
|
|||||||
OCR-recognition-bound: 1080 Ti ≈ 1070 Ti here. Any sm_70+ card with more
|
OCR-recognition-bound: 1080 Ti ≈ 1070 Ti here. Any sm_70+ card with more
|
||||||
memory scales with batch size instead.
|
memory scales with batch size instead.
|
||||||
|
|
||||||
|
## Optional engines & notes
|
||||||
|
|
||||||
|
- **PaddleOCR** (alternate OCR; the service exposes `engine: "paddle"` per
|
||||||
|
request): `pip install paddleocr==2.10.0 paddlepaddle==3.0.0` into the venv.
|
||||||
|
Deliberately not in `requirements.txt` — hundreds of MB plus their own
|
||||||
|
numpy/protobuf pins.
|
||||||
|
- **Ultralytics/YOLOv8 detector**: not offered — AGPL-3.0, and this pipeline
|
||||||
|
ships only the MIT `icon_detect_v3` (YOLOv9-E). Requesting another detector
|
||||||
|
path raises explicitly rather than dragging AGPL code in.
|
||||||
|
- **HuggingFace at startup**: the Florence-2 *processor* and tokenizer load
|
||||||
|
from `huggingface.co` on boot (`trust_remote_code=True` runs upstream
|
||||||
|
modeling code — pin your own audited copy in `weights/icon_caption_florence/
|
||||||
|
preprocessor_config.json` world if that matters to you). Airgapped boxes:
|
||||||
|
prime `HF_HOME` once on a networked machine, then set `HF_HUB_OFFLINE=1`.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
- **`503 GPU out of memory (another process on the card?)`** — something else
|
- **`503 GPU out of memory (another process on the card?)`** — something else
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ Register in your harness's MCP config - e.g. ~/.omp/agent/mcp.json (stdio):
|
|||||||
"cwd": "<repo>",
|
"cwd": "<repo>",
|
||||||
"timeout": 120000,
|
"timeout": 120000,
|
||||||
"env": { "OMNI_API_URL": "http://127.0.0.1:8898",
|
"env": { "OMNI_API_URL": "http://127.0.0.1:8898",
|
||||||
"OMNI_API_TOKEN": "!cat ~/.config/omniparse_token" }
|
"OMNI_API_TOKEN": "!cat /home/YOU/.config/omniparse_token" }
|
||||||
}
|
}
|
||||||
|
|
||||||
(!cmd values are executed by omp at connect time - a bare env name copies
|
(!cmd values are executed at connect time without a shell - use an absolute
|
||||||
the launching shell's variable or, when unset, ships the literal string.)
|
path; a bare env name copies the harness's variable or ships it literally.)
|
||||||
"""
|
"""
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
|
|||||||
+3
-4
@@ -4,21 +4,20 @@ numpy==1.26.4 # torch/opencv ecosystem pin from upstream
|
|||||||
opencv-python-headless
|
opencv-python-headless
|
||||||
pillow
|
pillow
|
||||||
matplotlib
|
matplotlib
|
||||||
requests
|
|
||||||
tqdm
|
tqdm
|
||||||
supervision==0.18.0
|
supervision==0.18.0
|
||||||
ultralytics==8.3.70 # fallback detector path only; default is vendored YOLOv9-E
|
|
||||||
transformers>=4.45,<4.50
|
transformers>=4.45,<4.50
|
||||||
accelerate
|
accelerate
|
||||||
timm
|
timm
|
||||||
einops==0.8.0 # florence-2 remote code
|
einops==0.8.0 # florence-2 remote code
|
||||||
easyocr # default OCR engine
|
easyocr # default OCR engine
|
||||||
paddleocr==2.10.0 # optional OCR engine (paddlepaddle 3.x dropped use_gpu kwarg upstream uses)
|
|
||||||
paddlepaddle==3.0.0
|
|
||||||
huggingface_hub
|
huggingface_hub
|
||||||
# serving
|
# serving
|
||||||
fastapi
|
fastapi
|
||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
|
requests
|
||||||
# MCP stdio shim (>=2.x: mcp.server.mcpserver.MCPServer; 1.x path was
|
# MCP stdio shim (>=2.x: mcp.server.mcpserver.MCPServer; 1.x path was
|
||||||
# mcp.server.fastmcp.FastMCP - adjust import if you pin lower)
|
# mcp.server.fastmcp.FastMCP - adjust import if you pin lower)
|
||||||
mcp>=2.0.0
|
mcp>=2.0.0
|
||||||
|
# Optional engines are deliberately NOT here - see README "Optional engines"
|
||||||
|
# (paddleocr/paddlepaddle: alternate OCR; ultralytics: AGPL, unsupported path).
|
||||||
@@ -20,7 +20,17 @@ command -v python3 >/dev/null || { echo "python3 required (3.10+)"; exit 1; }
|
|||||||
python3 -c 'import sys; assert sys.version_info >= (3, 10)' || { echo "python >= 3.10 required"; exit 1; }
|
python3 -c 'import sys; assert sys.version_info >= (3, 10)' || { echo "python >= 3.10 required"; exit 1; }
|
||||||
|
|
||||||
echo "== venv"
|
echo "== venv"
|
||||||
[[ -d .venv ]] || python3 -m venv .venv
|
if ! python3 -m venv .venv 2>/dev/null; then
|
||||||
|
# Debian/Ubuntu ship python3 without ensurepip (python3-venv package):
|
||||||
|
if command -v conda >/dev/null 2>&1; then
|
||||||
|
echo "(system python3 lacks venv support - using conda base python)"
|
||||||
|
"$(conda info --base)/bin/python3" -m venv .venv || { echo "venv creation failed"; exit 1; }
|
||||||
|
else
|
||||||
|
echo "venv creation failed - install python3-venv (apt) or run:"
|
||||||
|
echo " conda create -n omniparse python=3.12 && .venv fallback: OMNI_PYTHON=... (see README)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
.venv/bin/pip install -q --upgrade pip
|
.venv/bin/pip install -q --upgrade pip
|
||||||
|
|
||||||
echo "== torch"
|
echo "== torch"
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ if [[ "${OMNI_CUDA_DEVICE:-0}" == "-1" ]]; then
|
|||||||
else
|
else
|
||||||
export CUDA_VISIBLE_DEVICES="${OMNI_CUDA_DEVICE:-0}"
|
export CUDA_VISIBLE_DEVICES="${OMNI_CUDA_DEVICE:-0}"
|
||||||
fi
|
fi
|
||||||
nohup "$PY" -m uvicorn omni_api.server:app --host "${OMNI_API_HOST:-0.0.0.0}" \
|
# default: localhost only - set OMNI_API_HOST=0.0.0.0 deliberately for LAN use
|
||||||
|
nohup "$PY" -m uvicorn omni_api.server:app --host "${OMNI_API_HOST:-127.0.0.1}" \
|
||||||
--port "$PORT" --log-level warning >>"$LOG" 2>&1 &
|
--port "$PORT" --log-level warning >>"$LOG" 2>&1 &
|
||||||
echo "started (pid $!) port $PORT card ${OMNI_CUDA_DEVICE:-0}; first parse pays a ~10 s lazy OCR load; log: $LOG"
|
echo "started (pid $!) port $PORT card ${OMNI_CUDA_DEVICE:-0}; first parse pays a ~10 s lazy OCR load; log: $LOG"
|
||||||
|
|
||||||
|
|||||||
+4
-13
@@ -3,16 +3,7 @@ import os
|
|||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import time
|
import time
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image
|
||||||
import json
|
|
||||||
import requests
|
|
||||||
# utility function
|
|
||||||
import os
|
|
||||||
from openai import AzureOpenAI
|
|
||||||
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
# %matplotlib inline
|
# %matplotlib inline
|
||||||
@@ -111,9 +102,9 @@ def get_yolo_model(model_path=None, device=None):
|
|||||||
|
|
||||||
return YOLOv9Detector(model_path=model_path, device=device)
|
return YOLOv9Detector(model_path=model_path, device=device)
|
||||||
|
|
||||||
from ultralytics import YOLO
|
raise RuntimeError(
|
||||||
|
"non-icon_detect_v3 detectors route through ultralytics (AGPL-3.0); "
|
||||||
return YOLO(model_path)
|
"this service ships only the MIT icon_detect_v3 YOLOv9-E path")
|
||||||
|
|
||||||
|
|
||||||
@torch.inference_mode()
|
@torch.inference_mode()
|
||||||
|
|||||||
Reference in new issue
Block a user