romanbredehoft-zama
commited on
Commit
•
e5b8aae
1
Parent(s):
82c6741
Compile deployment files to python 3.10 and improve app display
Browse files- .gitignore +5 -0
- app.py +5 -3
- deployment_files/client.zip +0 -0
- deployment_files/server.zip +0 -0
- {deployment_logit → deployment_files}/versions.json +1 -1
- deployment_logit/client.zip +0 -0
- deployment_logit/server.zip +0 -0
- dev.py +1 -1
- server.py +4 -4
- utils.py +1 -1
.gitignore
CHANGED
@@ -1,2 +1,7 @@
|
|
1 |
__pycache__/
|
2 |
.ipynb_checkpoints
|
|
|
|
|
|
|
|
|
|
|
|
1 |
__pycache__/
|
2 |
.ipynb_checkpoints
|
3 |
+
|
4 |
+
.venv
|
5 |
+
deployment_files/.*
|
6 |
+
deployment_files/client_dir/
|
7 |
+
deployment_files/server_dir/
|
app.py
CHANGED
@@ -171,10 +171,11 @@ def key_gen_fn(user_symptoms: List[str]) -> Dict:
|
|
171 |
return {
|
172 |
error_box2: gr.update(visible=False),
|
173 |
key_box: gr.update(visible=False, value=serialized_evaluation_keys_shorten_hex),
|
174 |
-
user_id_box: gr.update(visible=
|
175 |
key_len_box: gr.update(
|
176 |
visible=False, value=f"{len(serialized_evaluation_keys) / (10**6):.2f} MB"
|
177 |
),
|
|
|
178 |
}
|
179 |
|
180 |
|
@@ -608,9 +609,9 @@ if __name__ == "__main__":
|
|
608 |
"The evaluation key will be transmitted to the server for further processing."
|
609 |
)
|
610 |
|
611 |
-
gen_key_btn = gr.Button("Generate the evaluation
|
612 |
error_box2 = gr.Textbox(label="Error ❌", visible=False)
|
613 |
-
user_id_box = gr.Textbox(label="User ID:", visible=
|
614 |
key_len_box = gr.Textbox(label="Evaluation Key Size:", visible=False)
|
615 |
key_box = gr.Textbox(label="Evaluation key (truncated):", max_lines=3, visible=False)
|
616 |
|
@@ -622,6 +623,7 @@ if __name__ == "__main__":
|
|
622 |
user_id_box,
|
623 |
key_len_box,
|
624 |
error_box2,
|
|
|
625 |
],
|
626 |
)
|
627 |
|
|
|
171 |
return {
|
172 |
error_box2: gr.update(visible=False),
|
173 |
key_box: gr.update(visible=False, value=serialized_evaluation_keys_shorten_hex),
|
174 |
+
user_id_box: gr.update(visible=False, value=user_id),
|
175 |
key_len_box: gr.update(
|
176 |
visible=False, value=f"{len(serialized_evaluation_keys) / (10**6):.2f} MB"
|
177 |
),
|
178 |
+
gen_key_btn: gr.update(value="Keys have been generated ✅")
|
179 |
}
|
180 |
|
181 |
|
|
|
609 |
"The evaluation key will be transmitted to the server for further processing."
|
610 |
)
|
611 |
|
612 |
+
gen_key_btn = gr.Button("Generate the private and evaluation keys.")
|
613 |
error_box2 = gr.Textbox(label="Error ❌", visible=False)
|
614 |
+
user_id_box = gr.Textbox(label="User ID:", visible=False)
|
615 |
key_len_box = gr.Textbox(label="Evaluation Key Size:", visible=False)
|
616 |
key_box = gr.Textbox(label="Evaluation key (truncated):", max_lines=3, visible=False)
|
617 |
|
|
|
623 |
user_id_box,
|
624 |
key_len_box,
|
625 |
error_box2,
|
626 |
+
gen_key_btn,
|
627 |
],
|
628 |
)
|
629 |
|
deployment_files/client.zip
ADDED
Binary file (3.09 kB). View file
|
|
deployment_files/server.zip
ADDED
Binary file (9.61 kB). View file
|
|
{deployment_logit → deployment_files}/versions.json
RENAMED
@@ -1 +1 @@
|
|
1 |
-
{"concrete-python": "2.5", "concrete-ml": "1.4.0", "python": "3.
|
|
|
1 |
+
{"concrete-python": "2.5", "concrete-ml": "1.4.0", "python": "3.10.11"}
|
deployment_logit/client.zip
DELETED
Binary file (3.09 kB)
|
|
deployment_logit/server.zip
DELETED
Binary file (9.62 kB)
|
|
dev.py
CHANGED
@@ -42,7 +42,7 @@ fhe_circuit = clf.compile(X_train)
|
|
42 |
|
43 |
fhe_circuit.client.keygen(force=False)
|
44 |
|
45 |
-
path_to_model = Path("./
|
46 |
|
47 |
if path_to_model.exists():
|
48 |
shutil.rmtree(path_to_model)
|
|
|
42 |
|
43 |
fhe_circuit.client.keygen(force=False)
|
44 |
|
45 |
+
path_to_model = Path("./deployment_files/").resolve()
|
46 |
|
47 |
if path_to_model.exists():
|
48 |
shutil.rmtree(path_to_model)
|
server.py
CHANGED
@@ -9,6 +9,9 @@ from utils import DEPLOYMENT_DIR, SERVER_DIR # pylint: disable=no-name-in-modul
|
|
9 |
|
10 |
from concrete.ml.deployment import FHEModelServer
|
11 |
|
|
|
|
|
|
|
12 |
# Initialize an instance of FastAPI
|
13 |
app = FastAPI()
|
14 |
|
@@ -62,12 +65,9 @@ def run_fhe(
|
|
62 |
encrypted_output = encrypted_output_file.read()
|
63 |
evaluation_key = evaluation_key_file.read()
|
64 |
|
65 |
-
# Load the FHE server and the model
|
66 |
-
fhe_server = FHEModelServer(DEPLOYMENT_DIR)
|
67 |
-
|
68 |
# Run the FHE execution
|
69 |
start = time.time()
|
70 |
-
encrypted_output =
|
71 |
assert isinstance(encrypted_output, bytes)
|
72 |
fhe_execution_time = round(time.time() - start, 2)
|
73 |
|
|
|
9 |
|
10 |
from concrete.ml.deployment import FHEModelServer
|
11 |
|
12 |
+
# Load the FHE server
|
13 |
+
FHE_SERVER = FHEModelServer(DEPLOYMENT_DIR)
|
14 |
+
|
15 |
# Initialize an instance of FastAPI
|
16 |
app = FastAPI()
|
17 |
|
|
|
65 |
encrypted_output = encrypted_output_file.read()
|
66 |
evaluation_key = evaluation_key_file.read()
|
67 |
|
|
|
|
|
|
|
68 |
# Run the FHE execution
|
69 |
start = time.time()
|
70 |
+
encrypted_output = FHE_SERVER.run(encrypted_output, evaluation_key)
|
71 |
assert isinstance(encrypted_output, bytes)
|
72 |
fhe_execution_time = round(time.time() - start, 2)
|
73 |
|
utils.py
CHANGED
@@ -16,7 +16,7 @@ INPUT_BROWSER_LIMIT = 400
|
|
16 |
SERVER_URL = "http://localhost:8000/"
|
17 |
|
18 |
CURRENT_DIR = Path(__file__).parent
|
19 |
-
DEPLOYMENT_DIR = CURRENT_DIR / "
|
20 |
KEYS_DIR = DEPLOYMENT_DIR / ".fhe_keys"
|
21 |
CLIENT_DIR = DEPLOYMENT_DIR / "client_dir"
|
22 |
SERVER_DIR = DEPLOYMENT_DIR / "server_dir"
|
|
|
16 |
SERVER_URL = "http://localhost:8000/"
|
17 |
|
18 |
CURRENT_DIR = Path(__file__).parent
|
19 |
+
DEPLOYMENT_DIR = CURRENT_DIR / "deployment_files"
|
20 |
KEYS_DIR = DEPLOYMENT_DIR / ".fhe_keys"
|
21 |
CLIENT_DIR = DEPLOYMENT_DIR / "client_dir"
|
22 |
SERVER_DIR = DEPLOYMENT_DIR / "server_dir"
|