Spaces:
Sleeping
Sleeping
send input
Browse files
app.py
CHANGED
@@ -208,19 +208,14 @@ def encrypt(user_id, input_image):
|
|
208 |
return (resize_img(input_image), encrypted_image_short)
|
209 |
|
210 |
def send_input(user_id):
|
211 |
-
"""Send the encrypted input image as well as the evaluation key to the server.
|
212 |
-
|
213 |
-
Args:
|
214 |
-
user_id (int): The current user's ID.
|
215 |
-
"""
|
216 |
# Get the evaluation key path
|
217 |
evaluation_key_path = get_client_file_path("evaluation_key", user_id)
|
|
|
218 |
|
219 |
if user_id == "" or not evaluation_key_path.is_file():
|
220 |
raise gr.Error("Please generate the private key first.")
|
221 |
|
222 |
-
encrypted_input_path = get_client_file_path("encrypted_image", user_id)
|
223 |
-
|
224 |
if not encrypted_input_path.is_file():
|
225 |
raise gr.Error("Please generate the private key and then encrypt an image first.")
|
226 |
|
@@ -230,17 +225,16 @@ def send_input(user_id):
|
|
230 |
}
|
231 |
|
232 |
files = [
|
233 |
-
("files", open(encrypted_input_path, "rb")),
|
234 |
-
("files", open(evaluation_key_path, "rb")),
|
235 |
]
|
236 |
|
|
|
|
|
|
|
237 |
# Send the encrypted input image and evaluation key to the server
|
238 |
url = SERVER_URL + "send_input"
|
239 |
-
with requests.post(
|
240 |
-
url=url,
|
241 |
-
data=data,
|
242 |
-
files=files,
|
243 |
-
) as response:
|
244 |
return response.ok
|
245 |
|
246 |
def run_fhe(user_id):
|
|
|
208 |
return (resize_img(input_image), encrypted_image_short)
|
209 |
|
210 |
def send_input(user_id):
|
211 |
+
"""Send the encrypted input image as well as the evaluation key to the server."""
|
|
|
|
|
|
|
|
|
212 |
# Get the evaluation key path
|
213 |
evaluation_key_path = get_client_file_path("evaluation_key", user_id)
|
214 |
+
encrypted_input_path = get_client_file_path("encrypted_image", user_id)
|
215 |
|
216 |
if user_id == "" or not evaluation_key_path.is_file():
|
217 |
raise gr.Error("Please generate the private key first.")
|
218 |
|
|
|
|
|
219 |
if not encrypted_input_path.is_file():
|
220 |
raise gr.Error("Please generate the private key and then encrypt an image first.")
|
221 |
|
|
|
225 |
}
|
226 |
|
227 |
files = [
|
228 |
+
("files", ("encrypted_image", open(encrypted_input_path, "rb"), "application/octet-stream")),
|
229 |
+
("files", ("evaluation_key", open(evaluation_key_path, "rb"), "application/octet-stream")),
|
230 |
]
|
231 |
|
232 |
+
logger.info(f"Sending encrypted_image from: {encrypted_input_path}")
|
233 |
+
logger.info(f"Sending evaluation_key from: {evaluation_key_path}")
|
234 |
+
|
235 |
# Send the encrypted input image and evaluation key to the server
|
236 |
url = SERVER_URL + "send_input"
|
237 |
+
with requests.post(url=url, data=data, files=files) as response:
|
|
|
|
|
|
|
|
|
238 |
return response.ok
|
239 |
|
240 |
def run_fhe(user_id):
|
server.py
CHANGED
@@ -40,6 +40,7 @@ async def send_input(user_id: str = Form(), files: List[UploadFile] = File(...))
|
|
40 |
try:
|
41 |
for file in files:
|
42 |
file_path = get_server_file_path(file.filename.split("_")[0], user_id)
|
|
|
43 |
with file_path.open("wb") as buffer:
|
44 |
content = await file.read()
|
45 |
buffer.write(content)
|
@@ -47,7 +48,7 @@ async def send_input(user_id: str = Form(), files: List[UploadFile] = File(...))
|
|
47 |
except Exception as e:
|
48 |
logger.error(f"Error in send_input: {str(e)}")
|
49 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
50 |
-
|
51 |
@app.post("/run_fhe")
|
52 |
def run_fhe(user_id: str = Form()):
|
53 |
"""Execute seizure detection on the encrypted input image using FHE."""
|
@@ -57,9 +58,14 @@ def run_fhe(user_id: str = Form()):
|
|
57 |
encrypted_image_path = get_server_file_path("encrypted_image", user_id)
|
58 |
evaluation_key_path = get_server_file_path("evaluation_key", user_id)
|
59 |
|
|
|
|
|
|
|
60 |
# Check if files exist
|
61 |
-
if not encrypted_image_path.exists()
|
62 |
-
raise FileNotFoundError("
|
|
|
|
|
63 |
|
64 |
# Read the files using the above paths
|
65 |
with encrypted_image_path.open("rb") as encrypted_image_file, evaluation_key_path.open("rb") as evaluation_key_file:
|
|
|
40 |
try:
|
41 |
for file in files:
|
42 |
file_path = get_server_file_path(file.filename.split("_")[0], user_id)
|
43 |
+
logger.info(f"Saving file to: {file_path}")
|
44 |
with file_path.open("wb") as buffer:
|
45 |
content = await file.read()
|
46 |
buffer.write(content)
|
|
|
48 |
except Exception as e:
|
49 |
logger.error(f"Error in send_input: {str(e)}")
|
50 |
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
51 |
+
|
52 |
@app.post("/run_fhe")
|
53 |
def run_fhe(user_id: str = Form()):
|
54 |
"""Execute seizure detection on the encrypted input image using FHE."""
|
|
|
58 |
encrypted_image_path = get_server_file_path("encrypted_image", user_id)
|
59 |
evaluation_key_path = get_server_file_path("evaluation_key", user_id)
|
60 |
|
61 |
+
logger.info(f"Looking for encrypted_image at: {encrypted_image_path}")
|
62 |
+
logger.info(f"Looking for evaluation_key at: {evaluation_key_path}")
|
63 |
+
|
64 |
# Check if files exist
|
65 |
+
if not encrypted_image_path.exists():
|
66 |
+
raise FileNotFoundError(f"Encrypted image file not found at {encrypted_image_path}")
|
67 |
+
if not evaluation_key_path.exists():
|
68 |
+
raise FileNotFoundError(f"Evaluation key file not found at {evaluation_key_path}")
|
69 |
|
70 |
# Read the files using the above paths
|
71 |
with encrypted_image_path.open("rb") as encrypted_image_file, evaluation_key_path.open("rb") as evaluation_key_file:
|