| from gliner import GLiNER | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| # Use the provided path for loading the model | |
| self.model = GLiNER.from_pretrained(path) | |
| def __call__(self, data): | |
| try: | |
| text = data.get("text", "") | |
| labels = data.get("labels", []) | |
| if not text or not labels: | |
| return {"error": "Please provide 'text' and 'labels'"} | |
| entities = self.model.predict(text, labels) | |
| return {"entities": entities} | |
| except Exception as e: | |
| return {"error": str(e)} |