Upload 2 files
Browse files- handler.py +27 -0
- requirements.txt +1 -0
handler.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, Any
|
2 |
+
from deepsparse import Pipeline
|
3 |
+
from time import perf_counter
|
4 |
+
|
5 |
+
class EndpointHandler:
|
6 |
+
|
7 |
+
def __init__(self, path=""):
|
8 |
+
|
9 |
+
self.pipeline = Pipeline.create(task="text-classification", model_path=path)
|
10 |
+
|
11 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
12 |
+
"""
|
13 |
+
Args:
|
14 |
+
data (:obj:): prediction input text
|
15 |
+
"""
|
16 |
+
inputs = data.pop("inputs", data)
|
17 |
+
|
18 |
+
start = perf_counter()
|
19 |
+
prediction = self.pipeline(inputs)
|
20 |
+
end = perf_counter()
|
21 |
+
latency = end - start
|
22 |
+
|
23 |
+
return {
|
24 |
+
"labels": prediction.labels,
|
25 |
+
"scores": prediction.scores,
|
26 |
+
"latency (secs.)": latency
|
27 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
deepsparse>=1.2.0
|