Upload 2 files
Browse files- handler.py +25 -0
- requirements.txt +1 -0
handler.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
import spacy
|
3 |
+
|
4 |
+
|
5 |
+
class EndpointHandler:
|
6 |
+
def __init__(self, path=""):
|
7 |
+
self.nlp = spacy.load(path)
|
8 |
+
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
10 |
+
"""
|
11 |
+
Your mom.
|
12 |
+
"""
|
13 |
+
|
14 |
+
# Get inputs
|
15 |
+
text_input = data.pop("input", "")
|
16 |
+
|
17 |
+
# Perform regular model task
|
18 |
+
result = self.nlp(text_input)
|
19 |
+
|
20 |
+
# Return the result
|
21 |
+
entities = []
|
22 |
+
for ent in result.ents:
|
23 |
+
entities.append({"text": ent.text, "label": ent.label_, "id": ent.ent_id_})
|
24 |
+
|
25 |
+
return entities
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
spacy
|