Spaces:
Sleeping
Sleeping
keygen logging
Browse files
app.py
CHANGED
@@ -126,35 +126,43 @@ def clean_temporary_files(n_keys=20):
|
|
126 |
file.unlink()
|
127 |
|
128 |
def keygen():
|
129 |
-
"""Generate the private key for seizure detection.
|
|
|
|
|
|
|
|
|
130 |
|
131 |
-
|
132 |
-
|
|
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
|
138 |
-
|
139 |
-
|
|
|
|
|
140 |
|
141 |
-
|
142 |
-
|
|
|
|
|
143 |
|
144 |
-
|
145 |
-
|
|
|
|
|
146 |
|
147 |
-
|
148 |
-
|
|
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
with evaluation_key_path.open("wb") as evaluation_key_file:
|
155 |
-
evaluation_key_file.write(evaluation_key)
|
156 |
-
|
157 |
-
return (user_id, True)
|
158 |
|
159 |
def encrypt(user_id, input_image):
|
160 |
"""Encrypt the given image for seizure detection.
|
|
|
126 |
file.unlink()
|
127 |
|
128 |
def keygen():
|
129 |
+
"""Generate the private key for seizure detection."""
|
130 |
+
logger.info("Starting key generation process")
|
131 |
+
try:
|
132 |
+
# Clean temporary files
|
133 |
+
clean_temporary_files()
|
134 |
|
135 |
+
# Create an ID for the current user
|
136 |
+
user_id = numpy.random.randint(0, 2**32)
|
137 |
+
logger.info(f"Generated user_id: {user_id}")
|
138 |
|
139 |
+
# Retrieve the client API
|
140 |
+
client = get_client(user_id)
|
141 |
+
logger.info("Retrieved client API")
|
142 |
|
143 |
+
# Generate a private key
|
144 |
+
logger.info("Generating private and evaluation keys")
|
145 |
+
client.generate_private_and_evaluation_keys(force=True)
|
146 |
+
logger.info("Private and evaluation keys generated successfully")
|
147 |
|
148 |
+
# Retrieve the serialized evaluation key
|
149 |
+
logger.info("Retrieving serialized evaluation keys")
|
150 |
+
evaluation_key = client.get_serialized_evaluation_keys()
|
151 |
+
logger.info("Serialized evaluation keys retrieved")
|
152 |
|
153 |
+
# Save evaluation_key as bytes in a file as it is too large to pass through regular Gradio
|
154 |
+
# buttons (see https://github.com/gradio-app/gradio/issues/1877)
|
155 |
+
evaluation_key_path = get_client_file_path("evaluation_key", user_id)
|
156 |
+
logger.info(f"Saving evaluation key to: {evaluation_key_path}")
|
157 |
|
158 |
+
with evaluation_key_path.open("wb") as evaluation_key_file:
|
159 |
+
evaluation_key_file.write(evaluation_key)
|
160 |
+
logger.info("Evaluation key saved successfully")
|
161 |
|
162 |
+
return (user_id, True)
|
163 |
+
except Exception as e:
|
164 |
+
logger.error(f"Error during key generation: {str(e)}")
|
165 |
+
raise gr.Error(f"Key generation failed: {str(e)}")
|
|
|
|
|
|
|
|
|
166 |
|
167 |
def encrypt(user_id, input_image):
|
168 |
"""Encrypt the given image for seizure detection.
|