Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -70,7 +70,7 @@ def keygen():
|
|
70 |
print("Initializing FHEModelClient...")
|
71 |
# Let's create a user_id
|
72 |
user_id = numpy.random.randint(0, 2**32)
|
73 |
-
fhe_api = FHEModelClient(f"
|
74 |
fhe_api.load()
|
75 |
|
76 |
# Generate a fresh key
|
@@ -169,30 +169,35 @@ def decrypt_prediction(user_id):
|
|
169 |
predictions = fhe_api.deserialize_decrypt_dequantize(encrypted_prediction)
|
170 |
|
171 |
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
|
|
175 |
|
176 |
if __name__ == "__main__":
|
|
|
177 |
app = gr.Interface(
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
],
|
184 |
-
[
|
185 |
-
gr.inputs.Textbox(label="Task", default="malware"),
|
186 |
-
gr.inputs.File(label="Test File"),
|
187 |
-
gr.inputs.Textbox(label="User ID"),
|
188 |
],
|
189 |
-
[
|
190 |
-
gr.
|
191 |
-
gr.
|
192 |
-
gr.
|
193 |
-
gr.
|
194 |
],
|
195 |
title="FHE Model",
|
196 |
description="This is a FHE Model",
|
197 |
)
|
198 |
-
|
|
|
|
70 |
print("Initializing FHEModelClient...")
|
71 |
# Let's create a user_id
|
72 |
user_id = numpy.random.randint(0, 2**32)
|
73 |
+
fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{user_id}")
|
74 |
fhe_api.load()
|
75 |
|
76 |
# Generate a fresh key
|
|
|
169 |
predictions = fhe_api.deserialize_decrypt_dequantize(encrypted_prediction)
|
170 |
|
171 |
|
172 |
+
if __name__ == "__main__":
|
173 |
+
import gradio as gr
|
174 |
+
|
175 |
+
|
176 |
+
def process_pipeline(task, test_file, user_id):
|
177 |
+
eval_key = keygen(task, user_id)
|
178 |
+
encodings = encode_quantize_encrypt(test_file, eval_key)
|
179 |
+
encrypted_quantized_encoding = run_fhe(encodings)
|
180 |
+
encrypted_prediction = decrypt_prediction(encrypted_quantized_encoding)
|
181 |
|
182 |
+
return eval_key, encodings, encrypted_quantized_encoding, encrypted_prediction
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
+
import gradio as gr
|
186 |
app = gr.Interface(
|
187 |
+
fn=process_pipeline,
|
188 |
+
inputs=[
|
189 |
+
gr.Textbox(label="Task", value="malware"),
|
190 |
+
gr.File(label="Test File"),
|
191 |
+
gr.Textbox(label="User ID"),
|
|
|
|
|
|
|
|
|
|
|
192 |
],
|
193 |
+
outputs=[
|
194 |
+
gr.Textbox(label="Evaluation Key"),
|
195 |
+
gr.Textbox(label="Encodings"),
|
196 |
+
gr.Textbox(label="Encrypted Quantized Encoding"),
|
197 |
+
gr.Textbox(label="Encrypted Prediction"),
|
198 |
],
|
199 |
title="FHE Model",
|
200 |
description="This is a FHE Model",
|
201 |
)
|
202 |
+
|
203 |
+
app.launch()
|