import subprocess import sys try: import spacy except ImportError: # Attempt to install spacy subprocess.check_call([sys.executable, "-m", "pip", "install", "spacy"]) import spacy import spacy from typing import Dict, Any import spacy from typing import Dict, Any class EndpointHandler: def __init__(self, path): self.nlp = spacy.load(path) def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]: text = data.get("inputs", "") doc = self.nlp(text) entities = [ {"word": ent.text, "entity_group": ent.label_, "score": 1.0} for ent in doc.ents ] return entities """ handler = EndpointHandler() data = {"text": "Apple is looking at buying U.K. startup for $1 billion"} result = handler(data) print(result) """