Thomas Chardonnens commited on
Commit ·
0ee9bf6
1
Parent(s): 4ee6018
updayte keygen
Browse filesFiles changed (2)
- app.py+17-15
- client_server_interface.py+2
6 unmodified lines789101112131415162 unmodified lines1920212223242582 unmodified lines1081091101111121131141151161171181191201211221231241251261271281291301316 unmodified linesimport gradio as grimport numpyimport requestsfrom itertools import chainfrom common import (CLIENT_TMP_PATH,SERVER_TMP_PATH,EXAMPLES,INPUT_SHAPE,2 unmodified linesSERVER_URL,)from client_server_interface import FHEClient# Uncomment here to have both the server and client in the same terminalsubprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)time.sleep(3)82 unmodified lines# Clean temporary filesclean_temporary_files()# Create an ID for the current useruser_id = numpy.random.randint(0, 2**32)# Retrieve the client APIclient = get_client(user_id)# Generate a private keyclient.generate_private_and_evaluation_keys(force=True)# Retrieve the serialized evaluation keyevaluation_key = client.get_serialized_evaluation_keys()# Save evaluation_key as bytes in a file as it is too large to pass through regular Gradio# buttons (see https://github.com/gradio-app/gradio/issues/1877)evaluation_key_path = get_client_file_path("evaluation_key", user_id)with evaluation_key_path.open("wb") as evaluation_key_file:evaluation_key_file.write(evaluation_key)return (user_id, True)6 unmodified lines7891011121314151617182 unmodified lines2122232425262782 unmodified lines1101111121131141151161171181191201211221231241251261271281291301311321336 unmodified linesimport gradio as grimport numpyimport requestsimport numpy as npfrom itertools import chainfrom common import (CLIENT_TMP_PATH,SEIZURE_DETECTION_MODEL_PATH,SERVER_TMP_PATH,EXAMPLES,INPUT_SHAPE,2 unmodified linesSERVER_URL,)from client_server_interface import FHEClientfrom concrete.ml.deployment import FHEModelClient# Uncomment here to have both the server and client in the same terminalsubprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)time.sleep(3)82 unmodified lines# Clean temporary filesclean_temporary_files()# Generate a random user IDuser_id = np.random.randint(0, 2**32)print(f"Your user ID is: {user_id}....")client = FHEModelClient(path_dir=SEIZURE_DETECTION_MODEL_PATH, key_dir=KEYS_PATH / f"{user_id}")client.load()# Creates the private and evaluation keys on the client sideclient.generate_private_and_evaluation_keys()# Get the serialized evaluation keysserialized_evaluation_keys = client.get_serialized_evaluation_keys()assert isinstance(serialized_evaluation_keys, bytes)# Save the evaluation keyevaluation_key_path = KEYS_PATH / f"{user_id}/evaluation_key"with evaluation_key_path.open("wb") as f:f.write(serialized_evaluation_keys)return (user_id, True)
88 unmodified lines89909192939488 unmodified linesself.model_path = SEIZURE_DETECTION_MODEL_PATHself.key_dir = key_dir# If model_path does not exist raiseassert self.model_path.exists(), f"{self.model_path} does not exist. Please specify a valid path."88 unmodified lines899091929394959688 unmodified linesself.model_path = SEIZURE_DETECTION_MODEL_PATHself.key_dir = key_dirprint(self.model_path)# If model_path does not exist raiseassert self.model_path.exists(), f"{self.model_path} does not exist. Please specify a valid path."
app.py+17-15
client_server_interface.py+2