30 lines
1.2 KiB
Bash
30 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
export MINERU_MODEL_SOURCE=${MINERU_MODEL_SOURCE:-local}
|
|
export MINERU_MODEL_DIR=${MINERU_MODEL_DIR:-/models}
|
|
export MINERU_TOOLS_CONFIG_JSON=${MINERU_TOOLS_CONFIG_JSON:-/root/mineru.json}
|
|
export MINERU_API_MAX_CONCURRENT_REQUESTS=${MINERU_API_MAX_CONCURRENT_REQUESTS:-1}
|
|
export PYTHONPATH="/app${PYTHONPATH:+:$PYTHONPATH}"
|
|
|
|
# Preserve mounted settings, including optional title-aided configuration.
|
|
python3 - <<'PY'
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
path = Path(os.environ['MINERU_TOOLS_CONFIG_JSON'])
|
|
config = json.loads(path.read_text()) if path.exists() else {}
|
|
models = config.setdefault('models-dir', {})
|
|
if not isinstance(models, dict):
|
|
raise ValueError('models-dir must contain pipeline and vlm paths')
|
|
root = Path(os.environ['MINERU_MODEL_DIR'])
|
|
for backend in ('pipeline', 'vlm'):
|
|
override = os.getenv(f'MINERU_{backend.upper()}_MODEL_DIR')
|
|
models[backend] = override or models.get(backend) or str(root / backend)
|
|
config.setdefault('config_version', '1.3.1')
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
if not path.exists() or json.loads(path.read_text()) != config:
|
|
path.write_text(json.dumps(config, ensure_ascii=False, indent=2))
|
|
PY
|
|
exec "$@"
|