Ziga Kerec commited on
Commit
2f17452
1 Parent(s): 0e6f1d4

custom handler added

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. handler.py +20 -0
  3. test.py +17 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /env
handler.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+
3
+ class EndpointHandler():
4
+ def __init__(self, path=""):
5
+ # Preload all the elements you are going to need at inference.
6
+ # pseudo:
7
+ # self.model= load_model(path)
8
+ print("Loading model")
9
+
10
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
11
+ """
12
+ data args:
13
+ inputs (:obj: `str` | `PIL.Image` | `np.array`)
14
+ kwargs
15
+ Return:
16
+ A :obj:`list` | `dict`: will be serialized and returned
17
+ """
18
+
19
+ # pseudo
20
+ # self.model(input)
test.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from handler import EndpointHandler
2
+
3
+ # init handler
4
+ my_handler = EndpointHandler(path=".")
5
+
6
+ # # prepare sample payload
7
+ # non_holiday_payload = {"inputs": "I am quite excited how this will turn out", "date": "2022-08-08"}
8
+ # holiday_payload = {"inputs": "Today is a though day", "date": "2022-07-04"}
9
+
10
+ # # test the handler
11
+ # non_holiday_pred=my_handler(non_holiday_payload)
12
+ # holiday_payload=my_handler(holiday_payload)
13
+
14
+ # # show results
15
+ # print("non_holiday_pred", non_holiday_pred)
16
+ # print("holiday_payload", holiday_payload)
17
+