kcelia commited on
Commit
1a494e6
1 Parent(s): bd20950

chore: add key gen

Browse files
Files changed (2) hide show
  1. app.py +21 -4
  2. utils_demo.py +1 -1
app.py CHANGED
@@ -9,6 +9,7 @@ import pandas as pd
9
  from fhe_anonymizer import FHEAnonymizer
10
  from openai import OpenAI
11
  from utils_demo import *
 
12
 
13
  ORIGINAL_DOCUMENT = read_txt(ORIGINAL_FILE_PATH).split("\n\n")
14
  ANONYMIZED_DOCUMENT = read_txt(ANONYMIZED_FILE_PATH)
@@ -40,9 +41,27 @@ def key_gen_fn() -> Dict:
40
  """
41
  print("Key Gen..")
42
 
43
- anonymizer.generate_key()
 
 
44
 
45
- evaluation_key_path = KEYS_DIR / "evaluation_key"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  if not evaluation_key_path.is_file():
48
  error_message = (
@@ -244,8 +263,6 @@ with demo:
244
 
245
  gr.Markdown("## Step 2: Private document")
246
 
247
-
248
-
249
  with gr.Row():
250
  with gr.Column():
251
  gr.Markdown("**Original document:**")
 
9
  from fhe_anonymizer import FHEAnonymizer
10
  from openai import OpenAI
11
  from utils_demo import *
12
+ from concrete.ml.deployment import FHEModelClient
13
 
14
  ORIGINAL_DOCUMENT = read_txt(ORIGINAL_FILE_PATH).split("\n\n")
15
  ANONYMIZED_DOCUMENT = read_txt(ANONYMIZED_FILE_PATH)
 
41
  """
42
  print("Key Gen..")
43
 
44
+ # Generate a random user ID
45
+ user_id = np.random.randint(0, 2**32)
46
+ print(f"Your user ID is: {user_id}....")
47
 
48
+ client = FHEModelClient(path_dir=DEPLOYMENT_DIR, key_dir=KEYS_DIR / f"{user_id}")
49
+ client.load()
50
+
51
+ # Creates the private and evaluation keys on the client side
52
+ client.generate_private_and_evaluation_keys()
53
+
54
+ # Get the serialized evaluation keys
55
+ serialized_evaluation_keys = client.get_serialized_evaluation_keys()
56
+ assert isinstance(serialized_evaluation_keys, bytes)
57
+
58
+ # Save the evaluation key
59
+ evaluation_key_path = KEYS_DIR / f"{user_id}/evaluation_key"
60
+
61
+ with evaluation_key_path.open("wb") as f:
62
+ f.write(serialized_evaluation_keys)
63
+
64
+ # anonymizer.generate_key()
65
 
66
  if not evaluation_key_path.is_file():
67
  error_message = (
 
263
 
264
  gr.Markdown("## Step 2: Private document")
265
 
 
 
266
  with gr.Row():
267
  with gr.Column():
268
  gr.Markdown("**Original document:**")
utils_demo.py CHANGED
@@ -25,7 +25,7 @@ CURRENT_DIR = Path(__file__).parent
25
  DATA_PATH = CURRENT_DIR / "files"
26
  LOGREG_MODEL_PATH = CURRENT_DIR / "models" / "cml_logreg.model"
27
  DEPLOYMENT_DIR = CURRENT_DIR / "deployment"
28
- KEYS_DIR = DEPLOYMENT_DIR / ".fhe_keys"
29
 
30
  ORIGINAL_FILE_PATH = DATA_PATH / "original_document.txt"
31
  ANONYMIZED_FILE_PATH = DATA_PATH / "anonymized_document.txt"
 
25
  DATA_PATH = CURRENT_DIR / "files"
26
  LOGREG_MODEL_PATH = CURRENT_DIR / "models" / "cml_logreg.model"
27
  DEPLOYMENT_DIR = CURRENT_DIR / "deployment"
28
+ KEYS_DIR = DEPLOYMENT_DIR / "fhe_keys"
29
 
30
  ORIGINAL_FILE_PATH = DATA_PATH / "original_document.txt"
31
  ANONYMIZED_FILE_PATH = DATA_PATH / "anonymized_document.txt"