markaw commited on
Commit
5af9dc9
1 Parent(s): b026dfa

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +22 -0
handler.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from sentence_transformers import SentenceTransformer
3
+
4
+ class EndpointHandler():
5
+ def __init__(self, path=""):
6
+ # Preload all the elements you are going to need at inference.
7
+ # pseudo:
8
+ # self.model= load_model(path)
9
+ self.embedding_model = SentenceTransformer(model=path)
10
+
11
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
12
+ """
13
+ data args:
14
+ inputs (:obj: `str` | `PIL.Image` | `np.array`)
15
+ kwargs
16
+ Return:
17
+ A :obj:`list` | `dict`: will be serialized and returned
18
+ """
19
+ embeddings = self.embedding_model.encode(data)
20
+ return embeddings
21
+ # pseudo
22
+ # self.model(input)