vikram-fresche commited on
Commit
1900701
·
1 Parent(s): 24057d9

added custom handler

Browse files
Files changed (1) hide show
  1. handler.py +17 -0
handler.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from transformers import pipeline
3
+
4
+ class EndpointHandler():
5
+ def __init__(self, path=""):
6
+ self.model = pipeline("text-generation", model=path)
7
+
8
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
9
+ """
10
+ data args:
11
+ inputs (:obj: `str` | `PIL.Image` | `np.array`)
12
+ kwargs
13
+ Return:
14
+ A :obj:`list` | `dict`: will be serialized and returned
15
+ """
16
+ inputs = data.pop("inputs", data)
17
+ return self.model(inputs, **data)