binoykunhi commited on
Commit
fbefb2d
·
verified ·
1 Parent(s): a8cbd31

Create handler.py

Browse files
Files changed (1) hide show
  1. handler.py +23 -0
handler.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ os.environ.setdefault("USE_TF", "0")
4
+
5
+ import laya
6
+
7
+
8
+ class EndpointHandler:
9
+ def __init__(self, path=""):
10
+ self.agent = laya.load(path)
11
+
12
+ def __call__(self, data):
13
+ payload = data.get("inputs", data)
14
+
15
+ state = payload.get("state")
16
+ questions = payload.get("questions")
17
+
18
+ if state is None or questions is None:
19
+ raise ValueError(
20
+ "Request must contain inputs.state and inputs.questions"
21
+ )
22
+
23
+ return self.agent.predict(state, questions)