Commit ·
7831a95
1
Parent(s): e46675a
chore: update concrete-ml and smooth UI
Browse filesFiles changed (5)
63 unmodified lines6465666768697071727374757611 unmodified lines88899091929394959697989910010110210310410510610767 unmodified lines17517617717817918018112 unmodified lines19419519619719819920020120220328 unmodified lines2322332342352362372382392402415 unmodified lines2472482492502512522539 unmodified lines26326426526626726826927027127227327427527618 unmodified lines2952962972982993003013 unmodified lines30530630730830931031131231331463 unmodified lines# Generate a fresh keyfhe_api.generate_private_and_evaluation_keys(force=True)evaluation_key = fhe_api.get_serialized_evaluation_keys()size_evaluation_key = len(evaluation_key)# Save evaluation_key in a file, since too large to pass through regular Gradio# buttons, https://github.com/gradio-app/gradio/issues/1877numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], size_evaluation_key, user_id]def encode_quantize_encrypt(text, user_id):11 unmodified linesnumpy.save(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy", encrypted_quantized_encoding)# Compute sizetext_size = len(text.encode())encodings_size = len(encodings.tobytes())quantized_encoding_size = len(quantized_encodings.tobytes())encrypted_quantized_encoding_size = len(encrypted_quantized_encoding)encrypted_quantized_encoding_shorten = list(encrypted_quantized_encoding)[:ENCRYPTED_DATA_BROWSER_LIMIT]encrypted_quantized_encoding_shorten_hex = ''.join(f'{i:02x}' for i in encrypted_quantized_encoding_shorten)return (encodings[0],quantized_encodings[0],encrypted_quantized_encoding_shorten_hex,text_size,encodings_size,quantized_encoding_size,encrypted_quantized_encoding_size,)67 unmodified lines<img width=200 src="https://user-images.githubusercontent.com/5758427/197816413-d9cddad3-ba38-4793-847d-120975e1da11.png"></p><h2 align="center">Machine Learning, Natural Language Processing and Fully Homomorphic Encryption to do Sentiment Analysis on Encrypted data.</h2><p align="center"><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>12 unmodified lines)# FIXME: make it smaller and in the middle# gr.Image("Zama.svg")gr.Markdown("""<p align="center">28 unmodified linesvisible=False)size_evaluation_key = gr.Number(label="Size of the evalution key (in bytes):", value=0, interactive=False)gr.Markdown("# Step 2: Provide a message")gr.Markdown("## Client side")gr.Markdown(5 unmodified linesb_encode_quantize_text = gr.Button("Encode, quantize and encrypt the text with transformer vectorizer, and send to server")size_text = gr.Number(label="Size of the text (in bytes):", value="0", interactive=False)with gr.Row():encoding = gr.Textbox(9 unmodified linesmax_lines=4,interactive=False,)with gr.Row():size_encoding = gr.Number(label="Size (in bytes):", value=0, interactive=False)size_quantized_encoding = gr.Number(label="Size (in bytes):", value=0, interactive=False)size_encrypted_quantized_encoding = gr.Number(label="Size (in bytes):",value=0,interactive=False,)gr.Markdown("# Step 4: Run the FHE evaluation")gr.Markdown("## Server side")18 unmodified lineslabels_sentiment = gr.Label(label="Sentiment:")# Button for key generationb_gen_key_and_install.click(keygen, inputs=[], outputs=[evaluation_key, size_evaluation_key, user_id])# Button to quantize and encryptb_encode_quantize_text.click(3 unmodified linesencoding,quantized_encoding,encrypted_quantized_encoding,size_text,size_encoding,size_quantized_encoding,size_encrypted_quantized_encoding,],)63 unmodified lines64656667686970717273747511 unmodified lines87888990919293949596979867 unmodified lines16616716816917017117212 unmodified lines18518618718818919028 unmodified lines2192202212222232245 unmodified lines2302312322332342359 unmodified lines24524624724824925018 unmodified lines2692702712722732742753 unmodified lines27928028128228328463 unmodified lines# Generate a fresh keyfhe_api.generate_private_and_evaluation_keys(force=True)evaluation_key = fhe_api.get_serialized_evaluation_keys()# Save evaluation_key in a file, since too large to pass through regular Gradio# buttons, https://github.com/gradio-app/gradio/issues/1877numpy.save(f"tmp/tmp_evaluation_key_{user_id}.npy", evaluation_key)return [list(evaluation_key)[:ENCRYPTED_DATA_BROWSER_LIMIT], user_id]def encode_quantize_encrypt(text, user_id):11 unmodified linesnumpy.save(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy", encrypted_quantized_encoding)# Compute sizeencrypted_quantized_encoding_shorten = list(encrypted_quantized_encoding)[:ENCRYPTED_DATA_BROWSER_LIMIT]encrypted_quantized_encoding_shorten_hex = ''.join(f'{i:02x}' for i in encrypted_quantized_encoding_shorten)return (encodings[0],quantized_encodings[0],encrypted_quantized_encoding_shorten_hex,)67 unmodified lines<img width=200 src="https://user-images.githubusercontent.com/5758427/197816413-d9cddad3-ba38-4793-847d-120975e1da11.png"></p><h2 align="center">Sentiment Analysis On Encrypted Data Using Homomorphic Encryption.</h2><p align="center"><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>12 unmodified lines)gr.Markdown("""<p align="center">28 unmodified linesvisible=False)gr.Markdown("# Step 2: Provide a message")gr.Markdown("## Client side")gr.Markdown(5 unmodified linesb_encode_quantize_text = gr.Button("Encode, quantize and encrypt the text with transformer vectorizer, and send to server")with gr.Row():encoding = gr.Textbox(9 unmodified linesmax_lines=4,interactive=False,)gr.Markdown("# Step 4: Run the FHE evaluation")gr.Markdown("## Server side")18 unmodified lineslabels_sentiment = gr.Label(label="Sentiment:")# Button for key generationb_gen_key_and_install.click(keygen, inputs=[], outputs=[evaluation_key, user_id])# Button to quantize and encryptb_encode_quantize_text.click(3 unmodified linesencoding,quantized_encoding,encrypted_quantized_encoding,],)
1234concrete-ml==0.4.0gradio==3.10.0pandas==1.4.3uvicorn==0.18.21234concrete-ml==0.6.1gradio==3.10.0pandas==1.4.3uvicorn==0.18.2
123version https://git-lfs.github.com/spec/v1oid sha256:c0f9430bcbd16f40dfcd8547b7c0053be4a5692f5385206fa5ef42e9d3270242size 467123version https://git-lfs.github.com/spec/v1oid sha256:23ed14c3533c6950f73ea2bbbaff34b7de8bc57703e49fb62da29e37ecf66b87size 481
123version https://git-lfs.github.com/spec/v1oid sha256:237a28ea8367363255d3e1324841c54938885c7e4a8fff33bc1a49844c997873size 10443123version https://git-lfs.github.com/spec/v1oid sha256:4342713378f3fc474bc8a3fdd3149e45b94cf79c4ab0cf0c3322b435fcc8cb42size 10418
app.py+3-33
requirements.txt+1-1
sentiment_fhe_model/deployment/client.zip+2-2
sentiment_fhe_model/deployment/serialized_processing.json
sentiment_fhe_model/deployment/server.zip+2-2