File size: 517 Bytes
0a3aede bb95791 0375bcb ba02d68 0375bcb bb95791 0a3aede ba02d68 0a3aede ba02d68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# mcp/nlp.py
import spacy
def load_model():
try:
return spacy.load("en_core_web_sm")
except OSError:
raise RuntimeError(
"spaCy model 'en_core_web_sm' not found. "
"Install it in your Dockerfile or requirements.txt before building the app."
)
nlp = load_model()
def extract_keywords(text: str):
"""Extract entities (longer than 2 chars, no duplicates)."""
doc = nlp(text)
return list({ent.text for ent in doc.ents if len(ent.text.strip()) > 2})
|