Views
No views yet
███████╗ ██████╗ █████╗ ██████╗ ███████╗ ███████╗
██╔════╝ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔════╝ ██╔════╝
███████╗ ██████╔╝ ███████║ ██████╔╝ ███████╗ █████╗
╚════██║ ██╔═══╝ ██╔══██║ ██╔══██╗ ╚════██║█ █╔══╝
███████║ ██║ ██║ ██║ ██║ ██ ║███████║ ███████╗
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═ ╝╚══════╝ ╚══════╝



1class EndpointHandler:
2
3 def __init__(self, path=""):
4
5 self.pipeline = Pipeline.create(task="text-classification", model_path=path)
6
7 def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
8 """
9 Args:
10 data (:obj:): prediction input text
11 """
12 inputs = data.pop("inputs", data)
13
14 start = perf_counter()
15 prediction = self.pipeline(inputs)
16 end = perf_counter()
17 latency = end - start
18
19 return {
20 "labels": prediction.labels,
21 "scores": prediction.scores,
22 "latency (secs.)": latency
23 }