chore: adding an example from our template with a NeuralNetClassifier.
Browse files- play_with_endpoint.py +6 -7
play_with_endpoint.py
CHANGED
@@ -20,8 +20,7 @@ def from_json(python_object):
|
|
20 |
return bytes(python_object["__value__"])
|
21 |
|
22 |
|
23 |
-
|
24 |
-
API_URL = "https://XXXXXXX.us-east-1.aws.endpoints.huggingface.cloud"
|
25 |
headers = {
|
26 |
"Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
|
27 |
"Content-Type": "application/json",
|
@@ -39,12 +38,13 @@ def query(payload):
|
|
39 |
|
40 |
path_to_model = Path("compiled_model")
|
41 |
|
42 |
-
#
|
43 |
-
from sklearn.datasets import make_classification
|
44 |
from sklearn.model_selection import train_test_split
|
|
|
45 |
|
46 |
-
|
47 |
-
_, X_test, _, Y_test = train_test_split(
|
|
|
48 |
|
49 |
# Recover parameters for client side
|
50 |
fhemodel_client = FHEModelClient(path_to_model)
|
@@ -112,4 +112,3 @@ for i in range(nb_samples):
|
|
112 |
print(f"Accuracy on {nb_samples} samples is {nb_good * 1. / nb_samples}")
|
113 |
print(f"Total time: {time.time() - time_start:.3f} seconds")
|
114 |
print(f"Duration per inference: {duration / nb_samples:.3f} seconds")
|
115 |
-
# END: replace this part with your privacy-preserving application
|
|
|
20 |
return bytes(python_object["__value__"])
|
21 |
|
22 |
|
23 |
+
API_URL = "https://zkmlo9jbfzj9ep1j.eu-west-1.aws.endpoints.huggingface.cloud"
|
|
|
24 |
headers = {
|
25 |
"Authorization": "Bearer " + os.environ.get("HF_TOKEN"),
|
26 |
"Content-Type": "application/json",
|
|
|
38 |
|
39 |
path_to_model = Path("compiled_model")
|
40 |
|
41 |
+
# Iris and NeuralNetClassifier in FHE
|
|
|
42 |
from sklearn.model_selection import train_test_split
|
43 |
+
from sklearn.datasets import load_iris
|
44 |
|
45 |
+
X, y = load_iris(return_X_y=True)
|
46 |
+
_, X_test, _, Y_test = train_test_split(X, y, test_size=0.25, random_state=42)
|
47 |
+
X_test = X_test.astype("float32")
|
48 |
|
49 |
# Recover parameters for client side
|
50 |
fhemodel_client = FHEModelClient(path_to_model)
|
|
|
112 |
print(f"Accuracy on {nb_samples} samples is {nb_good * 1. / nb_samples}")
|
113 |
print(f"Total time: {time.time() - time_start:.3f} seconds")
|
114 |
print(f"Duration per inference: {duration / nb_samples:.3f} seconds")
|
|