Download mcp/nlp.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 496 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/392591064f42dbd2d1f5bde48d8f2eb2c2bbfd0f/mcp/nlp.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@392591064f42dbd2d1f5bde48d8f2eb2c2bbfd0f/mcp/nlp.py
-
curl -L -o nlp.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/392591064f42dbd2d1f5bde48d8f2eb2c2bbfd0f/mcp/nlp.py
496 Bytes
| # 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' is not installed. " | |
| "Ensure Dockerfile downloads it at build time." | |
| ) | |
| nlp = load_model() | |
| def extract_keywords(text: str): | |
| """Extract unique Named Entities longer than 2 characters.""" | |
| doc = nlp(text) | |
| return list({ent.text for ent in doc.ents if len(ent.text.strip()) > 2}) | |