mariotawfik commited on
Commit
2b27752
Β·
1 Parent(s): a3956a0
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -43,6 +43,8 @@ time.sleep(4)
43
  ENCRYPTED_DATA_BROWSER_LIMIT = 500
44
  N_USER_KEY_STORED = 20
45
 
 
 
46
 
47
  def clean_tmp_directory():
48
  # Allow 20 user keys to be stored.
@@ -66,7 +68,7 @@ def clean_tmp_directory():
66
  file.unlink()
67
 
68
 
69
- def keygen():
70
  # Clean tmp directory if needed
71
  clean_tmp_directory()
72
 
@@ -82,7 +84,7 @@ def keygen():
82
 
83
  numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)
84
 
85
- return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], user_id]
86
 
87
 
88
  def encode_quantize(test_file, eval_key):
@@ -342,15 +344,9 @@ if __name__ == "__main__":
342
  b_decrypt_result = gr.Button("πŸ” Decrypt scan result")
343
 
344
  scan_result = gr.Textbox(label="Scan Result:")
345
-
346
- eval_key = keygen()
347
- encodings = encode_quantize(file_input, eval_key)
348
- encrypted_quantized_encoding = encrypt_encoded_quantize(encodings)
349
- encrypted_prediction = run_fhe(eval_key[1])
350
- decrypted_encryption = decrypt_prediction(eval_key[1])
351
-
352
  # Button for key generation
353
- b_gen_key.click(eval_key, inputs=[], outputs=[evaluation_key])
354
 
355
  # Button to extract vector
356
  b_extract.click(
@@ -361,16 +357,16 @@ if __name__ == "__main__":
361
 
362
  # Button to encrypt file
363
  b_encrypt_file.click(
364
- encrypted_quantized_encoding,
365
- inputs=[],
366
  outputs=[encrypted_file],
367
  )
368
 
369
  # Button to run FHE-based malware scan
370
- b_run_fhe_scan.click(encrypted_prediction, inputs=[], outputs=[encrypted_scan_result])
371
 
372
  # Button to decrypt the scan result
373
- b_decrypt_result.click(decrypted_encryption, inputs=[], outputs=[scan_result])
374
 
375
  gr.Markdown(
376
  "ClairVault is built using advanced Fully Homomorphic Encryption techniques to ensure your data remains private and secure throughout the entire malware scanning process."
 
43
  ENCRYPTED_DATA_BROWSER_LIMIT = 500
44
  N_USER_KEY_STORED = 20
45
 
46
+ #Evaluation Key
47
+ eval_key = []
48
 
49
  def clean_tmp_directory():
50
  # Allow 20 user keys to be stored.
 
68
  file.unlink()
69
 
70
 
71
+ def keygen(eval_key):
72
  # Clean tmp directory if needed
73
  clean_tmp_directory()
74
 
 
84
 
85
  numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)
86
 
87
+ eval_key = [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], user_id]
88
 
89
 
90
  def encode_quantize(test_file, eval_key):
 
344
  b_decrypt_result = gr.Button("πŸ” Decrypt scan result")
345
 
346
  scan_result = gr.Textbox(label="Scan Result:")
347
+
 
 
 
 
 
 
348
  # Button for key generation
349
+ b_gen_key.click(keygen, inputs=[eval_key], outputs=[])
350
 
351
  # Button to extract vector
352
  b_extract.click(
 
357
 
358
  # Button to encrypt file
359
  b_encrypt_file.click(
360
+ encode_quantize,
361
+ inputs=[file_input, eval_key],
362
  outputs=[encrypted_file],
363
  )
364
 
365
  # Button to run FHE-based malware scan
366
+ b_run_fhe_scan.click(run_fhe, inputs=[eval_key[1]], outputs=[encrypted_scan_result])
367
 
368
  # Button to decrypt the scan result
369
+ b_decrypt_result.click(decrypt_prediction, inputs=[eval_key[1]], outputs=[scan_result])
370
 
371
  gr.Markdown(
372
  "ClairVault is built using advanced Fully Homomorphic Encryption techniques to ensure your data remains private and secure throughout the entire malware scanning process."