Instructions to use Mbiot/spacy-custom with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- spaCy
How to use Mbiot/spacy-custom with spaCy:
!pip install https://huggingface.co/Mbiot/spacy-custom/resolve/main/spacy-custom-any-py3-none-any.whl # Using spacy.load(). import spacy nlp = spacy.load("spacy-custom") # Importing as module. import spacy-custom nlp = spacy-custom.load() - Notebooks
- Google Colab
- Kaggle
| import spacy | |
| from typing import Dict, Any, List | |
| class EndpointHandler: | |
| def __init__(self, path: str = ""): | |
| # Load the spaCy model. Make sure you've added it in requirements.txt | |
| self.nlp = spacy.load(path) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| # Accept both 'inputs' and 'text' as valid keys | |
| text = data.get("inputs") or data.get("text") or "" | |
| if not text: | |
| return [{"error": "Missing input text"}] | |
| doc = self.nlp(text) | |
| results = [] | |
| for ent in doc.ents: | |
| results.append({ | |
| "text": ent.text, | |
| "start": ent.start_char, | |
| "end": ent.end_char, | |
| "label": ent.label_ | |
| }) | |
| return results |