From 61a0f353cd0b680c50e41be512ff3fb44b4fccfb Mon Sep 17 00:00:00 2001 From: plean Date: Wed, 18 Nov 2026 02:34:13 +0000 Subject: [PATCH] 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 --- README.md | 26 +++++++++++++++++++++++++- omni_api/mcp_server.py | 6 +++--- requirements.txt | 7 +++---- setup.sh | 12 +++++++++++- start.sh | 3 ++- util/utils.py | 17 ++++------------- 6 files changed, 48 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 45108ec..66e4843 100644 --- a/README.md +++ b/README.md @@ -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 ``` +`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" (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", "timeout": 120000, "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, include_som)`. In omp: `/mcp reload`, then `/mcp test omniparse`. The same 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 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 - **`503 GPU out of memory (another process on the card?)`** — something else diff --git a/omni_api/mcp_server.py b/omni_api/mcp_server.py index d290f04..f972ef5 100644 --- a/omni_api/mcp_server.py +++ b/omni_api/mcp_server.py @@ -12,11 +12,11 @@ Register in your harness's MCP config - e.g. ~/.omp/agent/mcp.json (stdio): "cwd": "", "timeout": 120000, "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 -the launching shell's variable or, when unset, ships the literal string.) +(!cmd values are executed at connect time without a shell - use an absolute +path; a bare env name copies the harness's variable or ships it literally.) """ import base64 import os diff --git a/requirements.txt b/requirements.txt index db38455..097fd81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,21 +4,20 @@ numpy==1.26.4 # torch/opencv ecosystem pin from upstream opencv-python-headless pillow matplotlib -requests tqdm supervision==0.18.0 -ultralytics==8.3.70 # fallback detector path only; default is vendored YOLOv9-E transformers>=4.45,<4.50 accelerate timm einops==0.8.0 # florence-2 remote code 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 # serving fastapi uvicorn[standard] +requests # MCP stdio shim (>=2.x: mcp.server.mcpserver.MCPServer; 1.x path was # mcp.server.fastmcp.FastMCP - adjust import if you pin lower) mcp>=2.0.0 +# Optional engines are deliberately NOT here - see README "Optional engines" +# (paddleocr/paddlepaddle: alternate OCR; ultralytics: AGPL, unsupported path). diff --git a/setup.sh b/setup.sh index fc34589..6d78e93 100755 --- a/setup.sh +++ b/setup.sh @@ -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; } 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 echo "== torch" diff --git a/start.sh b/start.sh index 8f5a4e0..d3e5476 100755 --- a/start.sh +++ b/start.sh @@ -37,7 +37,8 @@ if [[ "${OMNI_CUDA_DEVICE:-0}" == "-1" ]]; then else export CUDA_VISIBLE_DEVICES="${OMNI_CUDA_DEVICE:-0}" 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 & echo "started (pid $!) port $PORT card ${OMNI_CUDA_DEVICE:-0}; first parse pays a ~10 s lazy OCR load; log: $LOG" diff --git a/util/utils.py b/util/utils.py index cb131bb..ebe06c2 100644 --- a/util/utils.py +++ b/util/utils.py @@ -3,16 +3,7 @@ import os import io import base64 import time -from PIL import Image, ImageDraw, ImageFont -import json -import requests -# utility function -import os -from openai import AzureOpenAI - -import json -import sys -import os +from PIL import Image import cv2 import numpy as np # %matplotlib inline @@ -111,9 +102,9 @@ def get_yolo_model(model_path=None, device=None): return YOLOv9Detector(model_path=model_path, device=device) - from ultralytics import YOLO - - return YOLO(model_path) + raise RuntimeError( + "non-icon_detect_v3 detectors route through ultralytics (AGPL-3.0); " + "this service ships only the MIT icon_detect_v3 YOLOv9-E path") @torch.inference_mode()