kcelia commited on
Commit
e3e1dc8
1 Parent(s): ce79710

chore: version5

Browse files
Files changed (3) hide show
  1. app.py +5 -9
  2. server.py +10 -7
  3. utils.py +1 -1
app.py CHANGED
@@ -158,7 +158,7 @@ def key_gen_fn(user_symptoms: List[str]) -> Dict:
158
  with evaluation_key_path.open("wb") as f:
159
  f.write(serialized_evaluation_keys)
160
 
161
- serialized_evaluation_keys_shorten_hex = serialized_evaluation_keys.hex()[:INPUT_BROWSER_LIMIT]
162
 
163
  return {
164
  error_box2: gr.update(visible=False),
@@ -331,8 +331,6 @@ def get_output_fn(user_id: str, user_symptoms: np.ndarray) -> Dict:
331
  )
332
  }
333
 
334
-
335
-
336
  data = {
337
  "user_id": user_id,
338
  }
@@ -363,7 +361,7 @@ def decrypt_fn(user_id: str, user_symptoms: np.ndarray) -> Dict:
363
  Args:
364
  user_id (int): The current user's ID
365
  user_symptoms (numpy.ndarray): The user symptoms
366
-
367
  Returns:
368
  Decrypted output
369
  """
@@ -408,7 +406,6 @@ def decrypt_fn(user_id: str, user_symptoms: np.ndarray) -> Dict:
408
  }
409
 
410
 
411
-
412
  def clear_all_btn():
413
  """Clear all the box outputs."""
414
 
@@ -450,7 +447,7 @@ CSS = """
450
  if __name__ == "__main__":
451
 
452
  print("Starting demo ...")
453
-
454
  clean_directory()
455
 
456
  (X_train, X_test), (y_train, y_test) = load_data()
@@ -510,7 +507,7 @@ if __name__ == "__main__":
510
  error_box1 = gr.Textbox(label="Error", visible=False)
511
 
512
  # Default disease, picked from the dataframe
513
- # disease_box = gr.Dropdown(list(sorted(set(df_test["prognosis"]))),
514
  # label="Disease:")
515
  # disease_box.change(
516
  # fn=fill_in_fn,
@@ -533,7 +530,7 @@ if __name__ == "__main__":
533
  inputs=[*check_boxes],
534
  outputs=[user_vect_box1, error_box1],
535
  )
536
-
537
  with gr.TabItem("2. Data Encryption") as encryption_tab:
538
  gr.Markdown("<span style='color:orange'>Client Side</span>")
539
  gr.Markdown("## Step 2: Generate the keys")
@@ -659,7 +656,6 @@ if __name__ == "__main__":
659
  outputs=[srv_resp_retrieve_data_box, error_box6],
660
  )
661
 
662
-
663
  gr.Markdown("## Step 7: Decrypt the output")
664
 
665
  decrypt_target_btn = gr.Button("Decrypt the output")
 
158
  with evaluation_key_path.open("wb") as f:
159
  f.write(serialized_evaluation_keys)
160
 
161
+ serialized_evaluation_keys_shorten_hex = serialized_evaluation_keys.hex()[:INPUT_BROWSER_LIMIT]
162
 
163
  return {
164
  error_box2: gr.update(visible=False),
 
331
  )
332
  }
333
 
 
 
334
  data = {
335
  "user_id": user_id,
336
  }
 
361
  Args:
362
  user_id (int): The current user's ID
363
  user_symptoms (numpy.ndarray): The user symptoms
364
+
365
  Returns:
366
  Decrypted output
367
  """
 
406
  }
407
 
408
 
 
409
  def clear_all_btn():
410
  """Clear all the box outputs."""
411
 
 
447
  if __name__ == "__main__":
448
 
449
  print("Starting demo ...")
450
+
451
  clean_directory()
452
 
453
  (X_train, X_test), (y_train, y_test) = load_data()
 
507
  error_box1 = gr.Textbox(label="Error", visible=False)
508
 
509
  # Default disease, picked from the dataframe
510
+ # disease_box = gr.Dropdown(list(sorted(set(df_test["prognosis"]))),
511
  # label="Disease:")
512
  # disease_box.change(
513
  # fn=fill_in_fn,
 
530
  inputs=[*check_boxes],
531
  outputs=[user_vect_box1, error_box1],
532
  )
533
+
534
  with gr.TabItem("2. Data Encryption") as encryption_tab:
535
  gr.Markdown("<span style='color:orange'>Client Side</span>")
536
  gr.Markdown("## Step 2: Generate the keys")
 
656
  outputs=[srv_resp_retrieve_data_box, error_box6],
657
  )
658
 
 
659
  gr.Markdown("## Step 7: Decrypt the output")
660
 
661
  decrypt_target_btn = gr.Button("Decrypt the output")
server.py CHANGED
@@ -32,11 +32,12 @@ def send_input(
32
  """Send the inputs to the server."""
33
 
34
  print("\nSend the data to the server ............\n")
35
- # Retrieve the encrypted input and the evaluation key paths
 
36
  evaluation_key_path = SERVER_DIR / f"{user_id}_valuation_key"
37
- encrypted_input_path = SERVER_DIR / f"{user_id}_encrypted_symptoms"
38
 
39
- # # Write the files using the above paths
40
  with encrypted_input_path.open("wb") as encrypted_input, evaluation_key_path.open(
41
  "wb"
42
  ) as evaluation_key:
@@ -52,9 +53,9 @@ def run_fhe(
52
 
53
  print("\nRun in FHE in the server ............\n")
54
  evaluation_key_path = SERVER_DIR / f"{user_id}_valuation_key"
55
- encrypted_input_path = SERVER_DIR / f"{user_id}_encrypted_symptoms"
56
 
57
- # Read the files using the above paths
58
  with encrypted_input_path.open("rb") as encrypted_output_file, evaluation_key_path.open(
59
  "rb"
60
  ) as evaluation_key_file:
@@ -82,10 +83,11 @@ def run_fhe(
82
 
83
  @app.post("/get_output")
84
  def get_output(user_id: str = Form()):
85
- """Retrieve the encrypted output."""
86
 
87
  print("\nGet the output from the server ............\n")
88
- # Retrieve the encrypted output path
 
89
  encrypted_output_path = SERVER_DIR / f"{user_id}_encrypted_output"
90
 
91
  # Read the file using the above path
@@ -94,4 +96,5 @@ def get_output(user_id: str = Form()):
94
 
95
  time.sleep(1)
96
 
 
97
  return Response(encrypted_output)
 
32
  """Send the inputs to the server."""
33
 
34
  print("\nSend the data to the server ............\n")
35
+
36
+ # Receive the Client's files (Evaluation key + Encrypted symptoms)
37
  evaluation_key_path = SERVER_DIR / f"{user_id}_valuation_key"
38
+ encrypted_input_path = SERVER_DIR / f"{user_id}_encrypted_input"
39
 
40
+ # Save the files using the above paths
41
  with encrypted_input_path.open("wb") as encrypted_input, evaluation_key_path.open(
42
  "wb"
43
  ) as evaluation_key:
 
53
 
54
  print("\nRun in FHE in the server ............\n")
55
  evaluation_key_path = SERVER_DIR / f"{user_id}_valuation_key"
56
+ encrypted_input_path = SERVER_DIR / f"{user_id}_encrypted_input"
57
 
58
+ # Read the files (Evaluation key + Encrypted symptoms) using the above paths
59
  with encrypted_input_path.open("rb") as encrypted_output_file, evaluation_key_path.open(
60
  "rb"
61
  ) as evaluation_key_file:
 
83
 
84
  @app.post("/get_output")
85
  def get_output(user_id: str = Form()):
86
+ """Retrieve the encrypted output from the server."""
87
 
88
  print("\nGet the output from the server ............\n")
89
+
90
+ # Path where the encrypted output is saved
91
  encrypted_output_path = SERVER_DIR / f"{user_id}_encrypted_output"
92
 
93
  # Read the file using the above path
 
96
 
97
  time.sleep(1)
98
 
99
+ # Send the encrypted output
100
  return Response(encrypted_output)
utils.py CHANGED
@@ -118,7 +118,7 @@ def load_data() -> Tuple[pandas.DataFrame, pandas.DataFrame, numpy.ndarray]:
118
 
119
  def load_model(X_train: pandas.DataFrame, y_train: numpy.ndarray):
120
  """
121
- Load a pretrained serialized model
122
 
123
  Args:
124
  X_train (pandas.DataFrame): Training set
 
118
 
119
  def load_model(X_train: pandas.DataFrame, y_train: numpy.ndarray):
120
  """
121
+ Load a pre-trained serialized model
122
 
123
  Args:
124
  X_train (pandas.DataFrame): Training set