Upload handler.py
Browse files- handler.py +18 -0
handler.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
class EndpointHandler():
|
5 |
+
def __init__(self, path=""):
|
6 |
+
self.pipeline = pipeline("text-to-speech",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 |
+
prediction = self.pipeline(inputs)
|
18 |
+
return prediction
|