Instructions to use wjbeeson/en_core_web_sm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- spaCy
How to use wjbeeson/en_core_web_sm with spaCy:
!pip install https://huggingface.co/wjbeeson/en_core_web_sm/resolve/main/en_core_web_sm-any-py3-none-any.whl # Using spacy.load(). import spacy nlp = spacy.load("en_core_web_sm") # Importing as module. import en_core_web_sm nlp = en_core_web_sm.load() - Notebooks
- Google Colab
- Kaggle
| from typing import Dict, List, Any | |
| import importlib.util | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| """ | |
| The __init__ method is called when starting the Endpoint. | |
| We perform the imports and model loading here to match your logic. | |
| """ | |
| # 1. Check if spaCy is installed (Your specific error handling) | |
| if importlib.util.find_spec("spacy") is None: | |
| raise RuntimeError( | |
| "SpaCy is required but not installed. Install it with:\n" | |
| ".\\.venv\\Scripts\\python -m pip install spacy\n" | |
| "Then download the model:\n" | |
| ".\\.venv\\Scripts\\python -m spacy download en_core_web_sm" | |
| ) | |
| import spacy | |
| # 2. Load the model (Your specific error handling) | |
| try: | |
| # We load the model directly by name since it's installed via requirements.txt | |
| self.nlp = spacy.load("en_core_web_sm") | |
| except Exception as e: | |
| raise RuntimeError( | |
| "SpaCy model 'en_core_web_sm' is required but not available. " | |
| "Install it with:\n" | |
| ".\\.venv\\Scripts\\python -m spacy download en_core_web_sm" | |
| ) from e | |
| def __call__(self, data: Dict[str, Any]) -> List[str]: | |
| """ | |
| The __call__ method is called on every request. | |
| """ | |
| # 1. Extract inputs | |
| # The payload usually comes as {"inputs": "some text"} | |
| raw_text = data.pop("inputs", data) | |
| # Handle edge case where inputs might be a list | |
| if isinstance(raw_text, list): | |
| raw_text = raw_text[0] | |
| # 2. Run your processing logic | |
| doc = self.nlp(raw_text) | |
| # 3. Apply your specific list comprehension | |
| raw_sentences = [s.text.strip() for s in doc.sents if s.text.strip()] | |
| return raw_sentences |