| from typing import Dict, List, Any | |
| import spacy | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| self.nlp = spacy.load(path) | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| Your mom. | |
| """ | |
| # Get inputs | |
| text_input = data.pop("inputs", "") | |
| # Perform regular model task | |
| result = self.nlp(text_input) | |
| # Return the result | |
| entities = [] | |
| for ent in result.ents: | |
| entities.append({"text": ent.text, "label": ent.label_, "id": ent.ent_id_}) | |
| return entities | |