WenqingZhang
commited on
Commit
•
4e70a31
1
Parent(s):
d25f8c0
Update app.py
Browse files
app.py
CHANGED
@@ -72,34 +72,23 @@ def keygen(selected_tasks):
|
|
72 |
if "financial_rating" in selected_tasks:
|
73 |
model_names.append('financial_rating')
|
74 |
|
75 |
-
# Let's create a user_id
|
76 |
|
77 |
|
|
|
78 |
user_id = numpy.random.randint(0, 2**32)
|
79 |
fhe_api = FHEModelClient(FHE_MODEL_PATH, f".fhe_keys/{user_id}")
|
80 |
fhe_api.load()
|
81 |
|
82 |
|
83 |
-
|
84 |
fhe_api.generate_private_and_evaluation_keys(force=True)
|
85 |
evaluation_key = fhe_api.get_serialized_evaluation_keys()
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
numpy.save(eval_key_path, evaluation_key)
|
91 |
-
|
92 |
-
user_id_leagl = numpy.random.randint(0, 2**32)
|
93 |
-
fhe_api_legal= FHEModelClient(FHE_LEGAL_PATH, f".fhe_keys/{user_id_leagl}")
|
94 |
-
fhe_api_legal.load()
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
evaluation_keys = []
|
99 |
-
evaluation_keys.append(list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT])
|
100 |
-
#evaluation_keys.append(list(evaluation_key_legal)[:ENCRYPTED_DATA_BROWSER_LIMIT])
|
101 |
|
102 |
-
return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT],
|
103 |
def encode_quantize_encrypt(text, user_id):
|
104 |
if not user_id:
|
105 |
raise gr.Error("You need to generate FHE keys first.")
|
|
|
72 |
if "financial_rating" in selected_tasks:
|
73 |
model_names.append('financial_rating')
|
74 |
|
|
|
75 |
|
76 |
|
77 |
+
# Let's create a user_id
|
78 |
user_id = numpy.random.randint(0, 2**32)
|
79 |
fhe_api = FHEModelClient(FHE_MODEL_PATH, f".fhe_keys/{user_id}")
|
80 |
fhe_api.load()
|
81 |
|
82 |
|
83 |
+
# Generate a fresh key
|
84 |
fhe_api.generate_private_and_evaluation_keys(force=True)
|
85 |
evaluation_key = fhe_api.get_serialized_evaluation_keys()
|
86 |
|
87 |
+
# Save evaluation_key in a file, since too large to pass through regular Gradio
|
88 |
+
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
89 |
+
numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], user_id]
|
92 |
def encode_quantize_encrypt(text, user_id):
|
93 |
if not user_id:
|
94 |
raise gr.Error("You need to generate FHE keys first.")
|