romanbredehoft-zama commited on
Commit
7ba6721
1 Parent(s): b65bef2

Add encrypted output representation

Browse files
Files changed (2) hide show
  1. app.py +5 -5
  2. backend.py +6 -7
app.py CHANGED
@@ -139,15 +139,15 @@ with demo:
139
  )
140
  get_output_button = gr.Button("Receive the encrypted output from the server.")
141
 
142
- # encrypted_output_representation = gr.Textbox(
143
- # label="Encrypted output representation: ", max_lines=1, interactive=False
144
- # )
145
 
146
  gr.Markdown("### Step 8: Decrypt the output.")
147
  decrypt_button = gr.Button("Decrypt the output")
148
 
149
  prediction_output = gr.Textbox(
150
- label="Credit card approval decision: ", max_lines=1, interactive=False
151
  )
152
 
153
  # Button to pre-process, generate the key, encrypt and send the user inputs from the client
@@ -184,7 +184,7 @@ with demo:
184
  get_output_button.click(
185
  get_output,
186
  inputs=[user_id, bank_id, third_party_id],
187
- # outputs=[encrypted_output_representation]
188
  )
189
 
190
  # TODO : ID should be unique
 
139
  )
140
  get_output_button = gr.Button("Receive the encrypted output from the server.")
141
 
142
+ encrypted_output_representation = gr.Textbox(
143
+ label="Encrypted output representation: ", max_lines=1, interactive=False
144
+ )
145
 
146
  gr.Markdown("### Step 8: Decrypt the output.")
147
  decrypt_button = gr.Button("Decrypt the output")
148
 
149
  prediction_output = gr.Textbox(
150
+ label="Credit card approval high risk: ", max_lines=1, interactive=False
151
  )
152
 
153
  # Button to pre-process, generate the key, encrypt and send the user inputs from the client
 
184
  get_output_button.click(
185
  get_output,
186
  inputs=[user_id, bank_id, third_party_id],
187
+ outputs=[encrypted_output_representation],
188
  )
189
 
190
  # TODO : ID should be unique
backend.py CHANGED
@@ -342,6 +342,9 @@ def get_output(user_id, bank_id, third_party_id):
342
  user_id (int): The user ID to consider.
343
  bank_id (int): The bank ID to consider.
344
  third_party_id (int): The third party ID to consider.
 
 
 
345
  """
346
  data = {
347
  "user_id": user_id,
@@ -360,19 +363,15 @@ def get_output(user_id, bank_id, third_party_id):
360
 
361
  # Save the encrypted output to bytes in a file as it is too large to pass through regular
362
  # Gradio buttons (see https://github.com/gradio-app/gradio/issues/1877)
363
- # TODO : check if output to user is relevant
364
  encrypted_output_path = _get_client_file_path("encrypted_output", user_id + bank_id + third_party_id, "output")
365
 
366
  with encrypted_output_path.open("wb") as encrypted_output_file:
367
  encrypted_output_file.write(encrypted_output)
368
 
369
- # TODO
370
- # Decrypt the output using a different (wrong) key for display
371
- # output_encrypted_representation = decrypt_output_with_wrong_key(encrypted_output, client_type)
372
-
373
- # return output_encrypted_representation
374
 
375
- return None
376
  else:
377
  raise gr.Error("Please wait for the FHE execution to be completed.")
378
 
 
342
  user_id (int): The user ID to consider.
343
  bank_id (int): The bank ID to consider.
344
  third_party_id (int): The third party ID to consider.
345
+
346
+ Returns:
347
+ encrypted_output_short (bytes): A byte short representation of the encrypted output.
348
  """
349
  data = {
350
  "user_id": user_id,
 
363
 
364
  # Save the encrypted output to bytes in a file as it is too large to pass through regular
365
  # Gradio buttons (see https://github.com/gradio-app/gradio/issues/1877)
 
366
  encrypted_output_path = _get_client_file_path("encrypted_output", user_id + bank_id + third_party_id, "output")
367
 
368
  with encrypted_output_path.open("wb") as encrypted_output_file:
369
  encrypted_output_file.write(encrypted_output)
370
 
371
+ # Create a truncated version of the encrypted inputs for display
372
+ encrypted_output_short = shorten_bytes_object(encrypted_output)
 
 
 
373
 
374
+ return encrypted_output_short
375
  else:
376
  raise gr.Error("Please wait for the FHE execution to be completed.")
377