vlbthambawita
commited on
Commit
•
091beb2
1
Parent(s):
0364e84
adding custom handler
Browse files- handler.py +29 -0
handler.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
|
3 |
+
from transformers import AutoModel
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
class EndpointHandler():
|
8 |
+
def __init__(self, path=""):
|
9 |
+
# Preload all the elements you are going to need at inference.
|
10 |
+
# pseudo:
|
11 |
+
# self.model= load_model(path)
|
12 |
+
self.model = AutoModel.from_pretrained("deepsynthbody/deepfake_ecg", trust_remote_code=True)
|
13 |
+
|
14 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
15 |
+
"""
|
16 |
+
data args:
|
17 |
+
inputs (:obj: `str` | `PIL.Image` | `np.array`)
|
18 |
+
kwargs
|
19 |
+
Return:
|
20 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
21 |
+
"""
|
22 |
+
num_samples = data.pop("num_samples",data)
|
23 |
+
|
24 |
+
output = self.model(num_samples)
|
25 |
+
|
26 |
+
# pseudo
|
27 |
+
# self.model(input)
|
28 |
+
|
29 |
+
return output
|