File size: 1,694 Bytes
8f6d79d
155974e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74087c2
 
 
0435b8d
 
74087c2
 
 
 
 
 
c212805
74087c2
0435b8d
 
 
 
 
 
 
 
74087c2
 
0435b8d
74087c2
 
 
155974e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""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:  # noqa: BLE001
        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:  # noqa: BLE001
        print(
            "[warn] optional rewrite resources unavailable; continuing without them: "
            f"{exc}"
        )

if __name__ == "__main__":
    ensure_resources()
    print("Resources ready.")