buraktrk commited on
Commit
c7d3893
·
verified ·
1 Parent(s): 83d7959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -178,7 +178,10 @@ scaler_sel = MinMaxScaler().fit(X_tr[COLS])
178
  Xtr_sel = scaler_sel.transform(X_tr[COLS])
179
  final_model = ConcreteXGBClassifier(n_bits=8, **best_params, random_state=42)
180
  final_model.fit(Xtr_sel, ytr_e)
181
- fhe_model = final_model.compile(Xtr_sel)
 
 
 
182
 
183
 
184
  print("\n🔍 Seçilen Özellikler (%95 etkili):")
@@ -188,11 +191,12 @@ for i, col in enumerate(COLS, 1):
188
 
189
  # ------------------------ FONKSİYONLAR ------------------------
190
  def generate_keys():
191
- global fhe_model
192
- if fhe_model is None:
193
- raise gr.Error("FHE circuit hazır değil.")
194
- keys = fhe_model.keygen()
195
- return keys.serialize()[:120] + "..."
 
196
 
197
 
198
 
@@ -204,18 +208,20 @@ def encrypt_excel(file):
204
  enriched = compute_ratios(raw_df)
205
  X_input = enriched[COLS].dropna()
206
  scaled = scaler_sel.transform(X_input)
207
- enc_input = fhe_model.encrypt(scaled)
208
  return str(enc_input)[:150] + "..."
209
 
 
210
  def run_fhe():
211
- import time
212
  global enc_output
 
213
  start = time.time()
214
- enc_output = fhe_model.run(enc_input)
215
  return f"{time.time() - start:.2f}"
216
 
 
217
  def decrypt_result():
218
- y_pred = fhe_model.decrypt(enc_output)
219
  return encoder.inverse_transform([y_pred])[0]
220
 
221
  # -------------------- Gradio UI -------------------- #
 
178
  Xtr_sel = scaler_sel.transform(X_tr[COLS])
179
  final_model = ConcreteXGBClassifier(n_bits=8, **best_params, random_state=42)
180
  final_model.fit(Xtr_sel, ytr_e)
181
+ fhe_circuit = final_model.compile(Xtr_sel)
182
+ keys = fhe_circuit.keygen()
183
+ serialized_eval_key = keys.evaluation.serialize()
184
+
185
 
186
 
187
  print("\n🔍 Seçilen Özellikler (%95 etkili):")
 
191
 
192
  # ------------------------ FONKSİYONLAR ------------------------
193
  def generate_keys():
194
+ global fhe_circuit, keys
195
+ if fhe_circuit is None:
196
+ raise gr.Error("Model henüz derlenmedi.")
197
+ keys = fhe_circuit.keygen()
198
+ return keys.evaluation.serialize()[:120].decode() + "..."
199
+
200
 
201
 
202
 
 
208
  enriched = compute_ratios(raw_df)
209
  X_input = enriched[COLS].dropna()
210
  scaled = scaler_sel.transform(X_input)
211
+ enc_input = fhe_circuit.encrypt(scaled, keys.evaluation)
212
  return str(enc_input)[:150] + "..."
213
 
214
+
215
  def run_fhe():
 
216
  global enc_output
217
+ import time
218
  start = time.time()
219
+ enc_output = fhe_circuit.run(enc_input)
220
  return f"{time.time() - start:.2f}"
221
 
222
+
223
  def decrypt_result():
224
+ y_pred = fhe_circuit.decrypt(enc_output, keys.decryption)
225
  return encoder.inverse_transform([y_pred])[0]
226
 
227
  # -------------------- Gradio UI -------------------- #