AeternumS commited on
Commit
4eee2c5
1 Parent(s): 666c567
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -84,34 +84,41 @@ st.write(f"### Accuracy: {round(accuracy * 100, 2)}%")
84
  joblib.dump(dt, 'heart_disease_dt_model.pkl')
85
 
86
  # Convert the model for FHE
87
- st.write("### Converting the model for FHE...")
88
  fhe_compatible = FHEDecisionTreeClassifier.from_sklearn_model(dt, x_train, n_bits=10)
89
  fhe_compatible.compile(x_train)
90
 
91
  # Setup the server
92
- st.write("### Setting up the FHE server...")
93
  dev = FHEModelDev(path_dir=fhe_directory, model=fhe_compatible)
94
  dev.save()
95
  server = FHEModelServer(path_dir=fhe_directory)
96
  server.load()
 
97
 
98
  # Setup the client
99
- st.write("### Setting up the FHE client...")
100
  client = FHEModelClient(path_dir=fhe_directory, key_dir="/tmp/keys_client")
101
  serialized_evaluation_keys = client.get_serialized_evaluation_keys()
 
102
 
 
103
  # Load the dataset and select the relevant features for prediction
104
  sample_data = clean_data.iloc[0, 1:].values.reshape(1, -1) # First sample for prediction
105
  encrypted_data = client.quantize_encrypt_serialize(sample_data)
 
106
 
107
- st.write("### Running the server with encrypted data...")
108
  # Run the server with encrypted data
109
  encrypted_result = server.run(encrypted_data, serialized_evaluation_keys)
110
- st.write("### Decrypting the prediction result...")
 
 
111
  result = client.deserialize_decrypt_dequantize(encrypted_result)
 
112
 
113
- st.write("### Encrypted Prediction Result")
114
- if result == 1:
115
  st.write("Prediction: The patient is likely to have heart disease.")
116
  else:
117
  st.write("Prediction: The patient is unlikely to have heart disease.")
 
84
  joblib.dump(dt, 'heart_disease_dt_model.pkl')
85
 
86
  # Convert the model for FHE
87
+ st.write("#### Converting the model for FHE...")
88
  fhe_compatible = FHEDecisionTreeClassifier.from_sklearn_model(dt, x_train, n_bits=10)
89
  fhe_compatible.compile(x_train)
90
 
91
  # Setup the server
92
+ st.write("#### Setting up the FHE server...")
93
  dev = FHEModelDev(path_dir=fhe_directory, model=fhe_compatible)
94
  dev.save()
95
  server = FHEModelServer(path_dir=fhe_directory)
96
  server.load()
97
+ st.success("Done!")
98
 
99
  # Setup the client
100
+ st.write("#### Setting up the FHE client...")
101
  client = FHEModelClient(path_dir=fhe_directory, key_dir="/tmp/keys_client")
102
  serialized_evaluation_keys = client.get_serialized_evaluation_keys()
103
+ st.success("Done!")
104
 
105
+ st.write("#### Loading the dataset and encrypting relevant features for prediction...")
106
  # Load the dataset and select the relevant features for prediction
107
  sample_data = clean_data.iloc[0, 1:].values.reshape(1, -1) # First sample for prediction
108
  encrypted_data = client.quantize_encrypt_serialize(sample_data)
109
+ st.success("Done!")
110
 
111
+ st.write("##### Running the server with encrypted data...")
112
  # Run the server with encrypted data
113
  encrypted_result = server.run(encrypted_data, serialized_evaluation_keys)
114
+ st.success("Done!")
115
+
116
+ st.write("#### Decrypting the prediction result...")
117
  result = client.deserialize_decrypt_dequantize(encrypted_result)
118
+ st.success("Done!")
119
 
120
+ st.write("#### Encrypted Prediction Result")
121
+ if result:
122
  st.write("Prediction: The patient is likely to have heart disease.")
123
  else:
124
  st.write("Prediction: The patient is unlikely to have heart disease.")