binoua commited on
Commit
80b8a6a
1 Parent(s): 5ac98ad

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +9 -1
handler.py CHANGED
@@ -8,6 +8,14 @@ def from_json(python_object):
8
  return bytes(python_object["__value__"])
9
 
10
 
 
 
 
 
 
 
 
 
11
  class EndpointHandler:
12
  def __init__(self, path="benoit.model"):
13
 
@@ -32,4 +40,4 @@ class EndpointHandler:
32
  # Run CML prediction
33
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
34
 
35
- return encrypted_prediction
 
8
  return bytes(python_object["__value__"])
9
 
10
 
11
+ def to_json(python_object):
12
+ if isinstance(python_object, bytes):
13
+ return {"__class__": "bytes", "__value__": list(python_object)}
14
+ # if isinstance(python_object, bytes):
15
+ # return list(python_object)
16
+ raise TypeError(repr(python_object) + " is not JSON serializable")
17
+
18
+
19
  class EndpointHandler:
20
  def __init__(self, path="benoit.model"):
21
 
 
40
  # Run CML prediction
41
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
42
 
43
+ return to_json(encrypted_prediction)