Thomas Chardonnens
commited on
Commit
·
0ee9bf6
1
Parent(s):
4ee6018
updayte keygen
Browse files- app.py +17 -15
- client_server_interface.py +2 -0
app.py
CHANGED
|
@@ -7,10 +7,12 @@ import time
|
|
| 7 |
import gradio as gr
|
| 8 |
import numpy
|
| 9 |
import requests
|
|
|
|
| 10 |
from itertools import chain
|
| 11 |
|
| 12 |
from common import (
|
| 13 |
CLIENT_TMP_PATH,
|
|
|
|
| 14 |
SERVER_TMP_PATH,
|
| 15 |
EXAMPLES,
|
| 16 |
INPUT_SHAPE,
|
|
@@ -19,7 +21,7 @@ from common import (
|
|
| 19 |
SERVER_URL,
|
| 20 |
)
|
| 21 |
from client_server_interface import FHEClient
|
| 22 |
-
|
| 23 |
# Uncomment here to have both the server and client in the same terminal
|
| 24 |
subprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)
|
| 25 |
time.sleep(3)
|
|
@@ -108,24 +110,24 @@ def keygen():
|
|
| 108 |
# Clean temporary files
|
| 109 |
clean_temporary_files()
|
| 110 |
|
| 111 |
-
#
|
| 112 |
-
user_id =
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
client
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
client.generate_private_and_evaluation_keys(
|
| 119 |
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
# Save evaluation_key as bytes in a file as it is too large to pass through regular Gradio
|
| 124 |
-
# buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
| 125 |
-
evaluation_key_path = get_client_file_path("evaluation_key", user_id)
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
| 129 |
|
| 130 |
return (user_id, True)
|
| 131 |
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
import numpy
|
| 9 |
import requests
|
| 10 |
+
import numpy as np
|
| 11 |
from itertools import chain
|
| 12 |
|
| 13 |
from common import (
|
| 14 |
CLIENT_TMP_PATH,
|
| 15 |
+
SEIZURE_DETECTION_MODEL_PATH,
|
| 16 |
SERVER_TMP_PATH,
|
| 17 |
EXAMPLES,
|
| 18 |
INPUT_SHAPE,
|
|
|
|
| 21 |
SERVER_URL,
|
| 22 |
)
|
| 23 |
from client_server_interface import FHEClient
|
| 24 |
+
from concrete.ml.deployment import FHEModelClient
|
| 25 |
# Uncomment here to have both the server and client in the same terminal
|
| 26 |
subprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)
|
| 27 |
time.sleep(3)
|
|
|
|
| 110 |
# Clean temporary files
|
| 111 |
clean_temporary_files()
|
| 112 |
|
| 113 |
+
# Generate a random user ID
|
| 114 |
+
user_id = np.random.randint(0, 2**32)
|
| 115 |
+
print(f"Your user ID is: {user_id}....")
|
| 116 |
|
| 117 |
+
client = FHEModelClient(path_dir=SEIZURE_DETECTION_MODEL_PATH, key_dir=KEYS_PATH / f"{user_id}")
|
| 118 |
+
client.load()
|
| 119 |
|
| 120 |
+
# Creates the private and evaluation keys on the client side
|
| 121 |
+
client.generate_private_and_evaluation_keys()
|
| 122 |
|
| 123 |
+
# Get the serialized evaluation keys
|
| 124 |
+
serialized_evaluation_keys = client.get_serialized_evaluation_keys()
|
| 125 |
+
assert isinstance(serialized_evaluation_keys, bytes)
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
# Save the evaluation key
|
| 128 |
+
evaluation_key_path = KEYS_PATH / f"{user_id}/evaluation_key"
|
| 129 |
+
with evaluation_key_path.open("wb") as f:
|
| 130 |
+
f.write(serialized_evaluation_keys)
|
| 131 |
|
| 132 |
return (user_id, True)
|
| 133 |
|
client_server_interface.py
CHANGED
|
@@ -89,6 +89,8 @@ class FHEClient:
|
|
| 89 |
self.model_path = SEIZURE_DETECTION_MODEL_PATH
|
| 90 |
self.key_dir = key_dir
|
| 91 |
|
|
|
|
|
|
|
| 92 |
# If model_path does not exist raise
|
| 93 |
assert self.model_path.exists(), f"{self.model_path} does not exist. Please specify a valid path."
|
| 94 |
|
|
|
|
| 89 |
self.model_path = SEIZURE_DETECTION_MODEL_PATH
|
| 90 |
self.key_dir = key_dir
|
| 91 |
|
| 92 |
+
print(self.model_path)
|
| 93 |
+
|
| 94 |
# If model_path does not exist raise
|
| 95 |
assert self.model_path.exists(), f"{self.model_path} does not exist. Please specify a valid path."
|
| 96 |
|