batuergun commited on
Commit
7ea0738
·
1 Parent(s): 6d96105

naming fix

Browse files
Files changed (1) hide show
  1. server.py +14 -2
server.py CHANGED
@@ -32,6 +32,10 @@ FHE_SERVER = FHEModelServer(DEPLOYMENT_DIR)
32
 
33
  def get_server_file_path(file_type: str, user_id: str) -> Path:
34
  """Get the path to a file on the server."""
 
 
 
 
35
  return Path(__file__).parent / "server_tmp" / f"{file_type}_{user_id}"
36
 
37
  @app.post("/send_input")
@@ -41,9 +45,17 @@ async def send_input(user_id: str = Form(), files: List[UploadFile] = File(...))
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)
 
 
 
 
 
 
 
47
  return JSONResponse(content={"message": "Files received successfully"})
48
  except Exception as e:
49
  logger.error(f"Error in send_input: {str(e)}")
@@ -55,8 +67,8 @@ def run_fhe(user_id: str = Form()):
55
  logger.info(f"Starting FHE execution for user {user_id}")
56
  try:
57
  # Retrieve the encrypted input image and the evaluation key paths
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}")
 
32
 
33
  def get_server_file_path(file_type: str, user_id: str) -> Path:
34
  """Get the path to a file on the server."""
35
+ if file_type == "encrypted_image":
36
+ file_type = "encrypted"
37
+ elif file_type == "evaluation_key":
38
+ file_type = "evaluation"
39
  return Path(__file__).parent / "server_tmp" / f"{file_type}_{user_id}"
40
 
41
  @app.post("/send_input")
 
45
  for file in files:
46
  file_path = get_server_file_path(file.filename.split("_")[0], user_id)
47
  logger.info(f"Saving file to: {file_path}")
48
+ file_path.parent.mkdir(parents=True, exist_ok=True) # Ensure the directory exists
49
  with file_path.open("wb") as buffer:
50
  content = await file.read()
51
  buffer.write(content)
52
+
53
+ # Check if the file was saved successfully
54
+ if not file_path.exists():
55
+ raise IOError(f"Failed to save file at {file_path}")
56
+ else:
57
+ logger.info(f"File saved successfully at {file_path}")
58
+
59
  return JSONResponse(content={"message": "Files received successfully"})
60
  except Exception as e:
61
  logger.error(f"Error in send_input: {str(e)}")
 
67
  logger.info(f"Starting FHE execution for user {user_id}")
68
  try:
69
  # Retrieve the encrypted input image and the evaluation key paths
70
+ encrypted_image_path = get_server_file_path("encrypted", user_id)
71
+ evaluation_key_path = get_server_file_path("evaluation", user_id)
72
 
73
  logger.info(f"Looking for encrypted_image at: {encrypted_image_path}")
74
  logger.info(f"Looking for evaluation_key at: {evaluation_key_path}")