Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -128,7 +128,8 @@ def encode_quantize(test_file, eval_key, encodings):
|
|
128 |
|
129 |
return encodings
|
130 |
|
131 |
-
def encrypt_encoded_quantize(encodings,
|
|
|
132 |
fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{user_id}")
|
133 |
fhe_api.load()
|
134 |
|
@@ -146,7 +147,8 @@ def encrypt_encoded_quantize(encodings, user_id, eval_key):
|
|
146 |
encrypted_quantized_encoding_shorten_hex = "".join(f"{i:02x}" for i in encrypted_quantized_encoding_shorten)
|
147 |
return (encodings,quantized_encodings,encrypted_quantized_encoding_shorten_hex)
|
148 |
|
149 |
-
def run_fhe(
|
|
|
150 |
encoded_data_path = Path(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy")
|
151 |
encrypted_quantized_encoding = numpy.load(encoded_data_path)
|
152 |
|
@@ -178,7 +180,8 @@ def run_fhe(user_id):
|
|
178 |
return encrypted_prediction_shorten_hex
|
179 |
|
180 |
|
181 |
-
def decrypt_prediction(
|
|
|
182 |
encoded_data_path = Path(f"tmp/tmp_encrypted_prediction_{user_id}.npy")
|
183 |
|
184 |
# Read encrypted_prediction from the file
|
@@ -348,7 +351,6 @@ if __name__ == "__main__":
|
|
348 |
"The encrypted scan result is sent back to the client, who can finally decrypt it with their private key. Only the client is aware of the original file content and the scan result."
|
349 |
)
|
350 |
b_decrypt_result = gr.Button("π Decrypt scan result")
|
351 |
-
user_id_input = gr.Number(value=user_id, visible=False)
|
352 |
scan_result = gr.Textbox(label="Scan Result:")
|
353 |
|
354 |
eval_key_input = gr.Textbox(value=eval_key, visible=False)
|
@@ -366,15 +368,15 @@ if __name__ == "__main__":
|
|
366 |
# Button to encrypt file
|
367 |
b_encrypt_file.click(
|
368 |
fn=encrypt_encoded_quantize,
|
369 |
-
inputs=[extracted_vector,
|
370 |
outputs=[encrypted_file],
|
371 |
)
|
372 |
|
373 |
# Button to run FHE-based malware scan
|
374 |
-
b_run_fhe_scan.click(fn=run_fhe, inputs=[
|
375 |
|
376 |
# Button to decrypt the scan result
|
377 |
-
b_decrypt_result.click(fn=decrypt_prediction, inputs=[
|
378 |
|
379 |
gr.Markdown(
|
380 |
"ClairVault is built using advanced Fully Homomorphic Encryption techniques to ensure your data remains private and secure throughout the entire malware scanning process."
|
|
|
128 |
|
129 |
return encodings
|
130 |
|
131 |
+
def encrypt_encoded_quantize(encodings, eval_key):
|
132 |
+
global user_id
|
133 |
fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{user_id}")
|
134 |
fhe_api.load()
|
135 |
|
|
|
147 |
encrypted_quantized_encoding_shorten_hex = "".join(f"{i:02x}" for i in encrypted_quantized_encoding_shorten)
|
148 |
return (encodings,quantized_encodings,encrypted_quantized_encoding_shorten_hex)
|
149 |
|
150 |
+
def run_fhe():
|
151 |
+
global user_id
|
152 |
encoded_data_path = Path(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy")
|
153 |
encrypted_quantized_encoding = numpy.load(encoded_data_path)
|
154 |
|
|
|
180 |
return encrypted_prediction_shorten_hex
|
181 |
|
182 |
|
183 |
+
def decrypt_prediction():
|
184 |
+
global user_id
|
185 |
encoded_data_path = Path(f"tmp/tmp_encrypted_prediction_{user_id}.npy")
|
186 |
|
187 |
# Read encrypted_prediction from the file
|
|
|
351 |
"The encrypted scan result is sent back to the client, who can finally decrypt it with their private key. Only the client is aware of the original file content and the scan result."
|
352 |
)
|
353 |
b_decrypt_result = gr.Button("π Decrypt scan result")
|
|
|
354 |
scan_result = gr.Textbox(label="Scan Result:")
|
355 |
|
356 |
eval_key_input = gr.Textbox(value=eval_key, visible=False)
|
|
|
368 |
# Button to encrypt file
|
369 |
b_encrypt_file.click(
|
370 |
fn=encrypt_encoded_quantize,
|
371 |
+
inputs=[extracted_vector, eval_key_input],
|
372 |
outputs=[encrypted_file],
|
373 |
)
|
374 |
|
375 |
# Button to run FHE-based malware scan
|
376 |
+
b_run_fhe_scan.click(fn=run_fhe, inputs=[], outputs=[encrypted_scan_result])
|
377 |
|
378 |
# Button to decrypt the scan result
|
379 |
+
b_decrypt_result.click(fn=decrypt_prediction, inputs=[], outputs=[scan_result])
|
380 |
|
381 |
gr.Markdown(
|
382 |
"ClairVault is built using advanced Fully Homomorphic Encryption techniques to ensure your data remains private and secure throughout the entire malware scanning process."
|