philipp-zettl commited on
Commit
2cb1233
1 Parent(s): 550f4c2

Create handler.py

Browse files
Files changed (1) hide show
  1. handler.py +24 -0
handler.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from optimum.pipeline import pipeline
3
+ from transformers import AutoTokenizer
4
+ from optimum import ORTModelForSeq2SeqLM
5
+
6
+
7
+ class EndpointHandler():
8
+ def __init__(self, path=""):
9
+ tokenizer = AutoTokenizer.from_pretrained(path)
10
+ model = ORTModelForSeq2SeqLM.from_pretrained(path)
11
+ self.pipeline = pipeline("summarization",model=model, tokenizer=tokenizer)
12
+
13
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
14
+ """
15
+ data args:
16
+ inputs (:obj: `str`)
17
+ Return:
18
+ A :obj:`list` | `dict`: will be serialized and returned
19
+ """
20
+ # get inputs
21
+ inputs = data.pop("inputs",data)
22
+
23
+ # run normal prediction
24
+ return self.pipeline(inputs)