jfrery-zama commited on
Commit
8ad105a
1 Parent(s): 8285da1

chore: update gradio and add error message when wrong order execution

Browse files
Files changed (2) hide show
  1. app.py +14 -5
  2. requirements.txt +1 -1
app.py CHANGED
@@ -71,7 +71,8 @@ def keygen():
71
 
72
 
73
  def encode_quantize_encrypt(text, user_id):
74
- assert user_id != [], "Please, wait for the creation of FHE keys before trying to encrypt."
 
75
 
76
  fhe_api = FHEModelClient("sentiment_fhe_model/deployment", f".fhe_keys/{user_id}")
77
  fhe_api.load()
@@ -102,10 +103,14 @@ def encode_quantize_encrypt(text, user_id):
102
 
103
 
104
  def run_fhe(user_id):
105
- assert user_id != [], "Please, wait for the creation of FHE keys before trying to predict."
 
 
 
 
106
 
107
  # Read encrypted_quantized_encoding from the file
108
- encrypted_quantized_encoding = numpy.load(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy")
109
 
110
  # Read evaluation_key from the file
111
  evaluation_key = numpy.load(f"tmp/tmp_evaluation_key_{user_id}.npy")
@@ -132,10 +137,14 @@ def run_fhe(user_id):
132
 
133
 
134
  def decrypt_prediction(user_id):
135
- assert user_id != [], "Please, wait for the creation of FHE keys before trying to decrypt."
 
 
 
 
136
 
137
  # Read encrypted_prediction from the file
138
- encrypted_prediction = numpy.load(f"tmp/tmp_encrypted_prediction_{user_id}.npy").tobytes()
139
 
140
  fhe_api = FHEModelClient("sentiment_fhe_model/deployment", f".fhe_keys/{user_id}")
141
  fhe_api.load()
 
71
 
72
 
73
  def encode_quantize_encrypt(text, user_id):
74
+ if not user_id:
75
+ raise gr.Error("You need to generate FHE keys first.")
76
 
77
  fhe_api = FHEModelClient("sentiment_fhe_model/deployment", f".fhe_keys/{user_id}")
78
  fhe_api.load()
 
103
 
104
 
105
  def run_fhe(user_id):
106
+ encoded_data_path = Path(f"tmp/tmp_encrypted_quantized_encoding_{user_id}.npy")
107
+ if not user_id:
108
+ raise gr.Error("You need to generate FHE keys first.")
109
+ if not encoded_data_path.is_file():
110
+ raise gr.Error("No encrypted data was found. Encrypt the data before trying to predict.")
111
 
112
  # Read encrypted_quantized_encoding from the file
113
+ encrypted_quantized_encoding = numpy.load(encoded_data_path)
114
 
115
  # Read evaluation_key from the file
116
  evaluation_key = numpy.load(f"tmp/tmp_evaluation_key_{user_id}.npy")
 
137
 
138
 
139
  def decrypt_prediction(user_id):
140
+ encoded_data_path = Path(f"tmp/tmp_encrypted_prediction_{user_id}.npy")
141
+ if not user_id:
142
+ raise gr.Error("You need to generate FHE keys first.")
143
+ if not encoded_data_path.is_file():
144
+ raise gr.Error("No encrypted prediction was found. Run the prediction over the encrypted data first.")
145
 
146
  # Read encrypted_prediction from the file
147
+ encrypted_prediction = numpy.load(encoded_data_path).tobytes()
148
 
149
  fhe_api = FHEModelClient("sentiment_fhe_model/deployment", f".fhe_keys/{user_id}")
150
  fhe_api.load()
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  concrete-ml==0.4.0
2
- gradio==3.1.0
3
  pandas==1.4.3
4
  uvicorn==0.18.2
5
  transformers==4.20.1
 
1
  concrete-ml==0.4.0
2
+ gradio==3.10.0
3
  pandas==1.4.3
4
  uvicorn==0.18.2
5
  transformers==4.20.1