VaultChem commited on
Commit
4d743ae
·
verified ·
1 Parent(s): dd8b714

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
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"deployment/deployment_{task}", f".fhe_keys/{user_id}")
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
- def update(name):
173
- return f"Welcome to Gradio, {name}!"
 
 
 
 
 
 
 
174
 
 
175
 
176
  if __name__ == "__main__":
 
177
  app = gr.Interface(
178
- [
179
- keygen,
180
- encode_quantize_encrypt,
181
- run_fhe,
182
- decrypt_prediction,
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.outputs.Textbox(label="Evaluation Key"),
191
- gr.outputs.Textbox(label="Encodings"),
192
- gr.outputs.Textbox(label="Encrypted Quantized Encoding"),
193
- gr.outputs.Textbox(label="Encrypted Prediction"),
194
  ],
195
  title="FHE Model",
196
  description="This is a FHE Model",
197
  )
198
- app.launch()
 
 
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()