File size: 597 Bytes
190f79e 066e2b0 190f79e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
|