binoua commited on
Commit
5ba534e
1 Parent(s): a7efd05

chore: back to json

Browse files
Files changed (2) hide show
  1. handler.py +3 -6
  2. play_with_endpoint.py +6 -8
handler.py CHANGED
@@ -30,15 +30,12 @@ class EndpointHandler:
30
  """
31
 
32
  # Get inputs
33
- # encrypted_inputs = from_json(data.pop("encrypted_inputs", data))
34
- encrypted_inputs = data.pop("encrypted_inputs", data)
35
 
36
  # Get keys
37
- # evaluation_keys = from_json(data.pop("evaluation_keys", data))
38
- evaluation_keys = data.pop("evaluation_keys", data)
39
 
40
  # Run CML prediction
41
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
42
 
43
- # return to_json(encrypted_prediction)
44
- return encrypted_prediction
 
30
  """
31
 
32
  # Get inputs
33
+ encrypted_inputs = from_json(data.pop("encrypted_inputs", data))
 
34
 
35
  # Get keys
36
+ evaluation_keys = from_json(data.pop("evaluation_keys", data))
 
37
 
38
  # Run CML prediction
39
  encrypted_prediction = self.fhemodel_server.run(encrypted_inputs, evaluation_keys)
40
 
41
+ return to_json(encrypted_prediction)
 
play_with_endpoint.py CHANGED
@@ -24,12 +24,12 @@ def from_json(python_object):
24
  API_URL = "https://yw1dgyuig6ff5pft.us-east-1.aws.endpoints.huggingface.cloud"
25
  headers = {
26
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
27
- "Content-Type": "application/octet-stream",
28
  }
29
 
30
 
31
  def query(payload):
32
- response = requests.post(API_URL, headers=headers, data=payload)
33
  return response.json()
34
 
35
 
@@ -74,16 +74,14 @@ for i in range(nb_samples):
74
  # Quantize the input and encrypt it
75
  encrypted_inputs = fhemodel_client.quantize_encrypt_serialize(X_test[i].reshape(1, -1))
76
 
77
- # print(f"Size of encrypted input {sys.getsizeof(encrypted_inputs)}")
78
- # print(f"Size of keys {sys.getsizeof(evaluation_keys)}")
79
 
80
  # Prepare the payload, including the evaluation keys which are needed server side
81
  payload = {
82
  "inputs": "fake",
83
- # "encrypted_inputs": to_json(encrypted_inputs),
84
- # "evaluation_keys": to_json(evaluation_keys),
85
- "encrypted_inputs": encrypted_inputs,
86
- "evaluation_keys": evaluation_keys,
87
  }
88
 
89
  print(f"{payload=}")
 
24
  API_URL = "https://yw1dgyuig6ff5pft.us-east-1.aws.endpoints.huggingface.cloud"
25
  headers = {
26
  "Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
27
+ "Content-Type": "application/json",
28
  }
29
 
30
 
31
  def query(payload):
32
+ response = requests.post(API_URL, headers=headers, json=payload)
33
  return response.json()
34
 
35
 
 
74
  # Quantize the input and encrypt it
75
  encrypted_inputs = fhemodel_client.quantize_encrypt_serialize(X_test[i].reshape(1, -1))
76
 
77
+ print(f"Size of encrypted input {sys.getsizeof(encrypted_inputs)}")
78
+ print(f"Size of keys {sys.getsizeof(evaluation_keys)}")
79
 
80
  # Prepare the payload, including the evaluation keys which are needed server side
81
  payload = {
82
  "inputs": "fake",
83
+ "encrypted_inputs": to_json(encrypted_inputs),
84
+ "evaluation_keys": to_json(evaluation_keys),
 
 
85
  }
86
 
87
  print(f"{payload=}")