Token Classification
GLiNER
PyTorch
English
Manu Biot commited on
Commit
b121d58
·
1 Parent(s): 6f0d3f3

Add requirements.txt for endpoint dependencies

Browse files
Files changed (1) hide show
  1. handler.py +12 -11
handler.py CHANGED
@@ -1,14 +1,15 @@
1
  from gliner import GLiNER
2
- from typing import Dict
3
 
4
- class EndpointHandler:
 
5
  def __init__(self, path=""):
6
- self.model = GLiNER.from_pretrained(path)
7
-
8
- def __call__(self, data: Dict[str, str]) -> Dict:
9
- text = data.get("text", "")
10
- labels = data.get("labels", [])
11
- if not text or not labels:
12
- return {"error": "Missing 'text' or 'labels'"}
13
- entities = self.model.predict_entities(text, labels)
14
- return {"entities": entities}
 
1
  from gliner import GLiNER
2
+ from typing import Dict, List, Any
3
 
4
+
5
+ class EndpointHandler():
6
  def __init__(self, path=""):
7
+ self.model = GLiNER.from_pretrained("Mbiot/gliner-custom")
8
+
9
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
10
+ # get inputs
11
+ inputs = data.pop("inputs", data)
12
+ labels = data.pop("labels", None)
13
+
14
+ prediction = self.model.predict_entities(inputs, labels)
15
+ return prediction