philipp-zettl commited on
Commit
88b3b6a
1 Parent(s): 550f4c2

Create handler.py (#1)

Browse files

- Create handler.py (2cb1233d891f5af2d33293d99f65f978150c40cf)
- Create requirements.txt (1967b12ecae3dfe901b0ea125a9eb47bf6317fa8)

Files changed (2) hide show
  1. handler.py +24 -0
  2. requirements.txt +2 -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)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ optimum