YassineB commited on
Commit
4a36cbd
1 Parent(s): 528dd95

Test spacy

Browse files
Files changed (2) hide show
  1. handler.py +29 -0
  2. requirements.txt +1 -0
handler.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+
3
+ import spacy
4
+ import os
5
+
6
+ class EndpointHandler():
7
+ def __init__(self, path=""):
8
+ # load the optimized model
9
+ os.system("python -m spacy download en_core_web_sm")
10
+ self.pipeline = spacy.load("en_core_web_sm")
11
+
12
+ def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
13
+ """
14
+ Args:
15
+ data (:obj:):
16
+ includes the input data and the parameters for the inference.
17
+ Return:
18
+ A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
19
+ - "label": A string representing what the label/class is. There can be multiple labels.
20
+ - "score": A score between 0 and 1 describing how confident the model is for this label/class.
21
+ """
22
+ inputs = data.pop("inputs", data)
23
+
24
+ doc = self.pipeline(inputs)
25
+ res = []
26
+ for token in doc:
27
+ res.append({"token": token.text, "pos": token.pos_, "dep": token.dep_})
28
+
29
+ return res
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ spacy