earlalvarado-pi commited on
Commit
83fa20d
1 Parent(s): bb2d701

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +6 -4
handler.py CHANGED
@@ -12,15 +12,17 @@ import spacy
12
  from typing import Dict, Any
13
 
14
  class EndpointHandler:
15
- def __init__(self, path=""):
16
  self.nlp = spacy.load(path)
17
 
18
  def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
19
  text = data.get("text", "")
20
  doc = self.nlp(text)
21
- entities = [{"text": ent.text, "start": ent.start_char, "end": ent.end_char, "label": ent.label_} for ent in doc.ents]
22
- return {"entities": entities}
23
-
 
 
24
  """
25
  handler = EndpointHandler()
26
  data = {"text": "Apple is looking at buying U.K. startup for $1 billion"}
 
12
  from typing import Dict, Any
13
 
14
  class EndpointHandler:
15
+ def __init__(self, path="./"):
16
  self.nlp = spacy.load(path)
17
 
18
  def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
19
  text = data.get("text", "")
20
  doc = self.nlp(text)
21
+ entities = [
22
+ {"word": ent.text, "entity_group": ent.label_, "score": 1.0}
23
+ for ent in doc.ents
24
+ ]
25
+ return entities
26
  """
27
  handler = EndpointHandler()
28
  data = {"text": "Apple is looking at buying U.K. startup for $1 billion"}