mariotawfik commited on
Commit
16607b8
·
1 Parent(s): eea003f
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -49,6 +49,8 @@ eval_key = []
49
  encodings = []
50
  #User ID
51
  user_id = []
 
 
52
 
53
  def clean_tmp_directory():
54
  # Allow 20 user keys to be stored.
@@ -150,24 +152,10 @@ def encode_quantize(test_file, eval_key, encodings):
150
 
151
  return encodings
152
 
153
- def encrypt_encoded_quantize(encodings):
154
  fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{eval_key}")
155
  fhe_api.load()
156
 
157
- encodings = encodings[0]
158
-
159
- if isinstance(encodings, str):
160
- encodings = safe_eval(encodings)
161
-
162
- encodings = np.array(encodings, dtype=np.float32)
163
-
164
- # Check if the array is empty
165
- if encodings.size == 0:
166
- raise ValueError("Encodings array is empty, cannot proceed with encryption.")
167
-
168
- if np.isnan(encodings).any() or np.isinf(encodings).any():
169
- raise ValueError("Encodings contain NaN or Inf values, which cannot be processed.")
170
-
171
  quantized_encodings = fhe_api.model.quantize_input(encodings).astype(numpy.uint8)
172
  encrypted_quantized_encoding = fhe_api.quantize_encrypt_serialize(encodings)
173
 
@@ -403,7 +391,7 @@ if __name__ == "__main__":
403
  # Button to encrypt file
404
  b_encrypt_file.click(
405
  fn=encrypt_encoded_quantize,
406
- inputs=[extracted_vector],
407
  outputs=[encrypted_file],
408
  )
409
 
 
49
  encodings = []
50
  #User ID
51
  user_id = []
52
+ #Encoded Vector
53
+ encoded_vector = []
54
 
55
  def clean_tmp_directory():
56
  # Allow 20 user keys to be stored.
 
152
 
153
  return encodings
154
 
155
+ def encrypt_encoded_quantize():
156
  fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{eval_key}")
157
  fhe_api.load()
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  quantized_encodings = fhe_api.model.quantize_input(encodings).astype(numpy.uint8)
160
  encrypted_quantized_encoding = fhe_api.quantize_encrypt_serialize(encodings)
161
 
 
391
  # Button to encrypt file
392
  b_encrypt_file.click(
393
  fn=encrypt_encoded_quantize,
394
+ inputs=[],
395
  outputs=[encrypted_file],
396
  )
397