Roman
commited on
chore: remove all size displays
Browse files
app.py
CHANGED
|
@@ -163,10 +163,6 @@ def keygen(filter_name):
|
|
| 163 |
# execution
|
| 164 |
evaluation_key = client.get_serialized_evaluation_keys()
|
| 165 |
|
| 166 |
-
# Compute the private key's size in Kilobytes
|
| 167 |
-
private_key_path = next(client.key_dir.iterdir()) / "0_0/secretKey_big"
|
| 168 |
-
private_key_size = private_key_path.stat().st_size / 1000
|
| 169 |
-
|
| 170 |
# Save evaluation_key as bytes in a file as it is too large to pass through regular Gradio
|
| 171 |
# buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
| 172 |
evaluation_key_path = get_client_file_path("evaluation_key", user_id, filter_name)
|
|
@@ -174,7 +170,7 @@ def keygen(filter_name):
|
|
| 174 |
with evaluation_key_path.open("wb") as evaluation_key_file:
|
| 175 |
evaluation_key_file.write(evaluation_key)
|
| 176 |
|
| 177 |
-
return (user_id, True
|
| 178 |
|
| 179 |
|
| 180 |
def encrypt(user_id, input_image, filter_name):
|
|
@@ -202,9 +198,6 @@ def encrypt(user_id, input_image, filter_name):
|
|
| 202 |
# Pre-process, encrypt and serialize the image
|
| 203 |
encrypted_image = client.encrypt_serialize(input_image)
|
| 204 |
|
| 205 |
-
# Compute the input's size in Megabytes
|
| 206 |
-
encrypted_input_size = len(encrypted_image) / 1000000
|
| 207 |
-
|
| 208 |
# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio
|
| 209 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
| 210 |
encrypted_image_path = get_client_file_path("encrypted_image", user_id, filter_name)
|
|
@@ -215,7 +208,7 @@ def encrypt(user_id, input_image, filter_name):
|
|
| 215 |
# Create a truncated version of the encrypted image for display
|
| 216 |
encrypted_image_short = shorten_bytes_object(encrypted_image)
|
| 217 |
|
| 218 |
-
return (input_image, encrypted_image_short
|
| 219 |
|
| 220 |
|
| 221 |
def send_input(user_id, filter_name):
|
|
@@ -306,9 +299,6 @@ def get_output(user_id, filter_name):
|
|
| 306 |
if response.ok:
|
| 307 |
encrypted_output = response.content
|
| 308 |
|
| 309 |
-
# Compute the output's size in Megabytes
|
| 310 |
-
encrypted_output_size = len(encrypted_output) / 1000000
|
| 311 |
-
|
| 312 |
# Save the encrypted output to bytes in a file as it is too large to pass through regular
|
| 313 |
# Gradio buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
| 314 |
encrypted_output_path = get_client_file_path("encrypted_output", user_id, filter_name)
|
|
@@ -319,7 +309,7 @@ def get_output(user_id, filter_name):
|
|
| 319 |
# Decrypt the image using a different (wrong) key for display
|
| 320 |
output_image_representation = decrypt_output_with_wrong_key(encrypted_output, filter_name)
|
| 321 |
|
| 322 |
-
return output_image_representation
|
| 323 |
else:
|
| 324 |
raise gr.Error("Please wait for the FHE execution to be completed.")
|
| 325 |
|
|
@@ -398,7 +388,7 @@ with demo:
|
|
| 398 |
)
|
| 399 |
with gr.Row():
|
| 400 |
input_image = gr.Image(
|
| 401 |
-
label="Upload an image here.", shape=INPUT_SHAPE, source="upload", interactive=True
|
| 402 |
)
|
| 403 |
|
| 404 |
examples = gr.Examples(
|
|
@@ -424,10 +414,6 @@ with demo:
|
|
| 424 |
with gr.Row():
|
| 425 |
keygen_checkbox = gr.Checkbox(label="Private key generated:", interactive=False)
|
| 426 |
|
| 427 |
-
private_key_size = gr.Number(
|
| 428 |
-
label="Private key size (in kB):", value=0, precision=1, interactive=False
|
| 429 |
-
)
|
| 430 |
-
|
| 431 |
user_id = gr.Textbox(label="", max_lines=2, interactive=False, visible=False)
|
| 432 |
|
| 433 |
gr.Markdown("### Step 4: Encrypt the image using FHE.")
|
|
@@ -438,10 +424,6 @@ with demo:
|
|
| 438 |
label="Encrypted input representation:", max_lines=2, interactive=False
|
| 439 |
)
|
| 440 |
|
| 441 |
-
encrypted_input_size = gr.Number(
|
| 442 |
-
label="Encrypted input size (in MB):", value=0, precision=1, interactive=False
|
| 443 |
-
)
|
| 444 |
-
|
| 445 |
gr.Markdown("## Server side")
|
| 446 |
gr.Markdown(
|
| 447 |
"The encrypted value is received by the server. The server can then compute the filter "
|
|
@@ -473,10 +455,6 @@ with demo:
|
|
| 473 |
)
|
| 474 |
encrypted_output_representation.style(height=256, width=256)
|
| 475 |
|
| 476 |
-
encrypted_output_size = gr.Number(
|
| 477 |
-
label="Encrypted output size (in MB):", value=0, precision=1, interactive=False
|
| 478 |
-
)
|
| 479 |
-
|
| 480 |
gr.Markdown("## Client side")
|
| 481 |
gr.Markdown(
|
| 482 |
"The encrypted output is sent back to the client, who can finally decrypt it with the "
|
|
@@ -508,14 +486,14 @@ with demo:
|
|
| 508 |
keygen_button.click(
|
| 509 |
keygen,
|
| 510 |
inputs=[filter_name],
|
| 511 |
-
outputs=[user_id, keygen_checkbox
|
| 512 |
)
|
| 513 |
|
| 514 |
# Button to encrypt inputs on the client side
|
| 515 |
encrypt_button.click(
|
| 516 |
encrypt,
|
| 517 |
inputs=[user_id, input_image, filter_name],
|
| 518 |
-
outputs=[original_image, encrypted_input
|
| 519 |
)
|
| 520 |
|
| 521 |
# Button to send the encodings to the server using post method
|
|
@@ -530,7 +508,7 @@ with demo:
|
|
| 530 |
get_output_button.click(
|
| 531 |
get_output,
|
| 532 |
inputs=[user_id, filter_name],
|
| 533 |
-
outputs=[encrypted_output_representation
|
| 534 |
)
|
| 535 |
|
| 536 |
# Button to decrypt the output on the client side
|
|
|
|
| 163 |
# execution
|
| 164 |
evaluation_key = client.get_serialized_evaluation_keys()
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
# Save evaluation_key as bytes in a file as it is too large to pass through regular Gradio
|
| 167 |
# buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
| 168 |
evaluation_key_path = get_client_file_path("evaluation_key", user_id, filter_name)
|
|
|
|
| 170 |
with evaluation_key_path.open("wb") as evaluation_key_file:
|
| 171 |
evaluation_key_file.write(evaluation_key)
|
| 172 |
|
| 173 |
+
return (user_id, True)
|
| 174 |
|
| 175 |
|
| 176 |
def encrypt(user_id, input_image, filter_name):
|
|
|
|
| 198 |
# Pre-process, encrypt and serialize the image
|
| 199 |
encrypted_image = client.encrypt_serialize(input_image)
|
| 200 |
|
|
|
|
|
|
|
|
|
|
| 201 |
# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio
|
| 202 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
| 203 |
encrypted_image_path = get_client_file_path("encrypted_image", user_id, filter_name)
|
|
|
|
| 208 |
# Create a truncated version of the encrypted image for display
|
| 209 |
encrypted_image_short = shorten_bytes_object(encrypted_image)
|
| 210 |
|
| 211 |
+
return (input_image, encrypted_image_short)
|
| 212 |
|
| 213 |
|
| 214 |
def send_input(user_id, filter_name):
|
|
|
|
| 299 |
if response.ok:
|
| 300 |
encrypted_output = response.content
|
| 301 |
|
|
|
|
|
|
|
|
|
|
| 302 |
# Save the encrypted output to bytes in a file as it is too large to pass through regular
|
| 303 |
# Gradio buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
| 304 |
encrypted_output_path = get_client_file_path("encrypted_output", user_id, filter_name)
|
|
|
|
| 309 |
# Decrypt the image using a different (wrong) key for display
|
| 310 |
output_image_representation = decrypt_output_with_wrong_key(encrypted_output, filter_name)
|
| 311 |
|
| 312 |
+
return output_image_representation
|
| 313 |
else:
|
| 314 |
raise gr.Error("Please wait for the FHE execution to be completed.")
|
| 315 |
|
|
|
|
| 388 |
)
|
| 389 |
with gr.Row():
|
| 390 |
input_image = gr.Image(
|
| 391 |
+
value=None, label="Upload an image here.", shape=INPUT_SHAPE, source="upload", interactive=True,
|
| 392 |
)
|
| 393 |
|
| 394 |
examples = gr.Examples(
|
|
|
|
| 414 |
with gr.Row():
|
| 415 |
keygen_checkbox = gr.Checkbox(label="Private key generated:", interactive=False)
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
user_id = gr.Textbox(label="", max_lines=2, interactive=False, visible=False)
|
| 418 |
|
| 419 |
gr.Markdown("### Step 4: Encrypt the image using FHE.")
|
|
|
|
| 424 |
label="Encrypted input representation:", max_lines=2, interactive=False
|
| 425 |
)
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
gr.Markdown("## Server side")
|
| 428 |
gr.Markdown(
|
| 429 |
"The encrypted value is received by the server. The server can then compute the filter "
|
|
|
|
| 455 |
)
|
| 456 |
encrypted_output_representation.style(height=256, width=256)
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
gr.Markdown("## Client side")
|
| 459 |
gr.Markdown(
|
| 460 |
"The encrypted output is sent back to the client, who can finally decrypt it with the "
|
|
|
|
| 486 |
keygen_button.click(
|
| 487 |
keygen,
|
| 488 |
inputs=[filter_name],
|
| 489 |
+
outputs=[user_id, keygen_checkbox],
|
| 490 |
)
|
| 491 |
|
| 492 |
# Button to encrypt inputs on the client side
|
| 493 |
encrypt_button.click(
|
| 494 |
encrypt,
|
| 495 |
inputs=[user_id, input_image, filter_name],
|
| 496 |
+
outputs=[original_image, encrypted_input],
|
| 497 |
)
|
| 498 |
|
| 499 |
# Button to send the encodings to the server using post method
|
|
|
|
| 508 |
get_output_button.click(
|
| 509 |
get_output,
|
| 510 |
inputs=[user_id, filter_name],
|
| 511 |
+
outputs=[encrypted_output_representation]
|
| 512 |
)
|
| 513 |
|
| 514 |
# Button to decrypt the output on the client side
|