| """Bootstrap spaCy (used by Docker entrypoint and local first run)."""
|
|
|
| from __future__ import annotations
|
|
|
|
|
| def ensure_resources() -> None:
|
| """Load local resources. Never hard-fail — regex fallback still works."""
|
| try:
|
| import spacy
|
| from app.config import SPACY_MODEL
|
|
|
| try:
|
| spacy.load(SPACY_MODEL)
|
| except OSError:
|
| print(
|
| f"[warn] spaCy model '{SPACY_MODEL}' not installed. "
|
| "Using regex fallback. Install with: "
|
| "pip install https://github.com/explosion/spacy-models/releases/"
|
| "download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl"
|
| )
|
| except Exception as exc:
|
| print(f"[warn] spaCy setup: {exc}")
|
|
|
| try:
|
| from app.config import (
|
| ENGINE_LEXICAL_REFINEMENT,
|
| ENGINE_PARAPHRASE,
|
| ENGINE_USE_MINILM_SAFETY,
|
| ENGINE_WORDNET_LEXICON,
|
| )
|
|
|
| if ENGINE_LEXICAL_REFINEMENT:
|
| import wn
|
|
|
| wn.config.allow_multithreading = True
|
| wn.Wordnet(ENGINE_WORDNET_LEXICON)
|
| if ENGINE_USE_MINILM_SAFETY:
|
| from app.pipeline.minilm import warm_minilm
|
|
|
| warm_minilm()
|
| if ENGINE_PARAPHRASE:
|
| from app.engine.paraphrase import warm_paraphrase
|
|
|
| warm_paraphrase()
|
| except Exception as exc:
|
| print(
|
| "[warn] optional rewrite resources unavailable; continuing without them: "
|
| f"{exc}"
|
| )
|
|
|
| if __name__ == "__main__":
|
| ensure_resources()
|
| print("Resources ready.")
|
|
|