Commit
·
7831a95
1
Parent(s):
e46675a
chore: update concrete-ml and smooth UI
Browse files
app.py
CHANGED
|
@@ -64,13 +64,12 @@ def keygen():
|
|
| 64 |
# Generate a fresh key
|
| 65 |
fhe_api.generate_private_and_evaluation_keys(force=True)
|
| 66 |
evaluation_key = fhe_api.get_serialized_evaluation_keys()
|
| 67 |
-
size_evaluation_key = len(evaluation_key)
|
| 68 |
|
| 69 |
# Save evaluation_key in a file, since too large to pass through regular Gradio
|
| 70 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
| 71 |
numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)
|
| 72 |
|
| 73 |
-
return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT],
|
| 74 |
|
| 75 |
|
| 76 |
def encode_quantize_encrypt(text, user_id):
|
|
@@ -88,20 +87,12 @@ def encode_quantize_encrypt(text, user_id):
|
|
| 88 |
numpy.save(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy", encrypted_quantized_encoding)
|
| 89 |
|
| 90 |
# Compute size
|
| 91 |
-
text_size = len(text.encode())
|
| 92 |
-
encodings_size = len(encodings.tobytes())
|
| 93 |
-
quantized_encoding_size = len(quantized_encodings.tobytes())
|
| 94 |
-
encrypted_quantized_encoding_size = len(encrypted_quantized_encoding)
|
| 95 |
encrypted_quantized_encoding_shorten = list(encrypted_quantized_encoding)[:ENCRYPTED_DATA_BROWSER_LIMIT]
|
| 96 |
encrypted_quantized_encoding_shorten_hex = ''.join(f'{i:02x}' for i in encrypted_quantized_encoding_shorten)
|
| 97 |
return (
|
| 98 |
encodings[0],
|
| 99 |
quantized_encodings[0],
|
| 100 |
encrypted_quantized_encoding_shorten_hex,
|
| 101 |
-
text_size,
|
| 102 |
-
encodings_size,
|
| 103 |
-
quantized_encoding_size,
|
| 104 |
-
encrypted_quantized_encoding_size,
|
| 105 |
)
|
| 106 |
|
| 107 |
|
|
@@ -175,7 +166,7 @@ with demo:
|
|
| 175 |
<img width=200 src="https://user-images.githubusercontent.com/5758427/197816413-d9cddad3-ba38-4793-847d-120975e1da11.png">
|
| 176 |
</p>
|
| 177 |
|
| 178 |
-
<h2 align="center">
|
| 179 |
|
| 180 |
<p align="center">
|
| 181 |
<a href="https://github.com/zama-ai/concrete-ml"> <img style="vertical-align: middle; display:inline-block; margin-right: 3px;" width=15 src="https://user-images.githubusercontent.com/5758427/197972109-faaaff3e-10e2-4ab6-80f5-7531f7cfb08f.png">Concrete-ML</a>
|
|
@@ -194,10 +185,6 @@ with demo:
|
|
| 194 |
)
|
| 195 |
|
| 196 |
|
| 197 |
-
|
| 198 |
-
# FIXME: make it smaller and in the middle
|
| 199 |
-
# gr.Image("Zama.svg")
|
| 200 |
-
|
| 201 |
gr.Markdown(
|
| 202 |
"""
|
| 203 |
<p align="center">
|
|
@@ -232,10 +219,6 @@ with demo:
|
|
| 232 |
visible=False
|
| 233 |
)
|
| 234 |
|
| 235 |
-
size_evaluation_key = gr.Number(
|
| 236 |
-
label="Size of the evalution key (in bytes):", value=0, interactive=False
|
| 237 |
-
)
|
| 238 |
-
|
| 239 |
gr.Markdown("# Step 2: Provide a message")
|
| 240 |
gr.Markdown("## Client side")
|
| 241 |
gr.Markdown(
|
|
@@ -247,7 +230,6 @@ with demo:
|
|
| 247 |
b_encode_quantize_text = gr.Button(
|
| 248 |
"Encode, quantize and encrypt the text with transformer vectorizer, and send to server"
|
| 249 |
)
|
| 250 |
-
size_text = gr.Number(label="Size of the text (in bytes):", value="0", interactive=False)
|
| 251 |
|
| 252 |
with gr.Row():
|
| 253 |
encoding = gr.Textbox(
|
|
@@ -263,14 +245,6 @@ with demo:
|
|
| 263 |
max_lines=4,
|
| 264 |
interactive=False,
|
| 265 |
)
|
| 266 |
-
with gr.Row():
|
| 267 |
-
size_encoding = gr.Number(label="Size (in bytes):", value=0, interactive=False)
|
| 268 |
-
size_quantized_encoding = gr.Number(label="Size (in bytes):", value=0, interactive=False)
|
| 269 |
-
size_encrypted_quantized_encoding = gr.Number(
|
| 270 |
-
label="Size (in bytes):",
|
| 271 |
-
value=0,
|
| 272 |
-
interactive=False,
|
| 273 |
-
)
|
| 274 |
|
| 275 |
gr.Markdown("# Step 4: Run the FHE evaluation")
|
| 276 |
gr.Markdown("## Server side")
|
|
@@ -295,7 +269,7 @@ with demo:
|
|
| 295 |
labels_sentiment = gr.Label(label="Sentiment:")
|
| 296 |
|
| 297 |
# Button for key generation
|
| 298 |
-
b_gen_key_and_install.click(keygen, inputs=[], outputs=[evaluation_key,
|
| 299 |
|
| 300 |
# Button to quantize and encrypt
|
| 301 |
b_encode_quantize_text.click(
|
|
@@ -305,10 +279,6 @@ with demo:
|
|
| 305 |
encoding,
|
| 306 |
quantized_encoding,
|
| 307 |
encrypted_quantized_encoding,
|
| 308 |
-
size_text,
|
| 309 |
-
size_encoding,
|
| 310 |
-
size_quantized_encoding,
|
| 311 |
-
size_encrypted_quantized_encoding,
|
| 312 |
],
|
| 313 |
)
|
| 314 |
|
|
|
|
| 64 |
# Generate a fresh key
|
| 65 |
fhe_api.generate_private_and_evaluation_keys(force=True)
|
| 66 |
evaluation_key = fhe_api.get_serialized_evaluation_keys()
|
|
|
|
| 67 |
|
| 68 |
# Save evaluation_key in a file, since too large to pass through regular Gradio
|
| 69 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
| 70 |
numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)
|
| 71 |
|
| 72 |
+
return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], user_id]
|
| 73 |
|
| 74 |
|
| 75 |
def encode_quantize_encrypt(text, user_id):
|
|
|
|
| 87 |
numpy.save(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy", encrypted_quantized_encoding)
|
| 88 |
|
| 89 |
# Compute size
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
encrypted_quantized_encoding_shorten = list(encrypted_quantized_encoding)[:ENCRYPTED_DATA_BROWSER_LIMIT]
|
| 91 |
encrypted_quantized_encoding_shorten_hex = ''.join(f'{i:02x}' for i in encrypted_quantized_encoding_shorten)
|
| 92 |
return (
|
| 93 |
encodings[0],
|
| 94 |
quantized_encodings[0],
|
| 95 |
encrypted_quantized_encoding_shorten_hex,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
|
|
|
|
| 166 |
<img width=200 src="https://user-images.githubusercontent.com/5758427/197816413-d9cddad3-ba38-4793-847d-120975e1da11.png">
|
| 167 |
</p>
|
| 168 |
|
| 169 |
+
<h2 align="center">Sentiment Analysis On Encrypted Data Using Homomorphic Encryption.</h2>
|
| 170 |
|
| 171 |
<p align="center">
|
| 172 |
<a href="https://github.com/zama-ai/concrete-ml"> <img style="vertical-align: middle; display:inline-block; margin-right: 3px;" width=15 src="https://user-images.githubusercontent.com/5758427/197972109-faaaff3e-10e2-4ab6-80f5-7531f7cfb08f.png">Concrete-ML</a>
|
|
|
|
| 185 |
)
|
| 186 |
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
gr.Markdown(
|
| 189 |
"""
|
| 190 |
<p align="center">
|
|
|
|
| 219 |
visible=False
|
| 220 |
)
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
gr.Markdown("# Step 2: Provide a message")
|
| 223 |
gr.Markdown("## Client side")
|
| 224 |
gr.Markdown(
|
|
|
|
| 230 |
b_encode_quantize_text = gr.Button(
|
| 231 |
"Encode, quantize and encrypt the text with transformer vectorizer, and send to server"
|
| 232 |
)
|
|
|
|
| 233 |
|
| 234 |
with gr.Row():
|
| 235 |
encoding = gr.Textbox(
|
|
|
|
| 245 |
max_lines=4,
|
| 246 |
interactive=False,
|
| 247 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
gr.Markdown("# Step 4: Run the FHE evaluation")
|
| 250 |
gr.Markdown("## Server side")
|
|
|
|
| 269 |
labels_sentiment = gr.Label(label="Sentiment:")
|
| 270 |
|
| 271 |
# Button for key generation
|
| 272 |
+
b_gen_key_and_install.click(keygen, inputs=[], outputs=[evaluation_key, user_id])
|
| 273 |
|
| 274 |
# Button to quantize and encrypt
|
| 275 |
b_encode_quantize_text.click(
|
|
|
|
| 279 |
encoding,
|
| 280 |
quantized_encoding,
|
| 281 |
encrypted_quantized_encoding,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
],
|
| 283 |
)
|
| 284 |
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
concrete-ml==0.
|
| 2 |
gradio==3.10.0
|
| 3 |
pandas==1.4.3
|
| 4 |
uvicorn==0.18.2
|
|
|
|
| 1 |
+
concrete-ml==0.6.1
|
| 2 |
gradio==3.10.0
|
| 3 |
pandas==1.4.3
|
| 4 |
uvicorn==0.18.2
|
sentiment_fhe_model/deployment/client.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:23ed14c3533c6950f73ea2bbbaff34b7de8bc57703e49fb62da29e37ecf66b87
|
| 3 |
+
size 481
|
sentiment_fhe_model/deployment/serialized_processing.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sentiment_fhe_model/deployment/server.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4342713378f3fc474bc8a3fdd3149e45b94cf79c4ab0cf0c3322b435fcc8cb42
|
| 3 |
+
size 10418
|