batuergun commited on
Commit
df12c8c
1 Parent(s): 835e258
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -245,6 +245,8 @@ def send_input(user_id):
245
  with requests.post(url=url, data=data, files=files) as response:
246
  return response.ok
247
 
 
 
248
  def run_fhe(user_id):
249
  """Apply the seizure detection model on the encrypted image previously sent using FHE."""
250
  data = {"user_id": user_id}
@@ -252,20 +254,23 @@ def run_fhe(user_id):
252
 
253
  try:
254
  logger.info(f"Sending request to {url} with user_id: {user_id}")
255
- with requests_retry_session().post(url=url, data=data, timeout=300) as response:
256
- logger.info(f"Received response with status code: {response.status_code}")
257
- response.raise_for_status() # Raises an HTTPError for bad responses
258
- if response.ok:
259
- return response.json()
260
- else:
261
- logger.error(f"Server responded with status code {response.status_code}")
262
- raise gr.Error(f"Server responded with status code {response.status_code}")
263
- except requests.exceptions.Timeout:
264
- logger.error("The request timed out. The server might be overloaded.")
265
- raise gr.Error("The request timed out. The server might be overloaded.")
266
- except requests.exceptions.ConnectionError as e:
267
- logger.error(f"Failed to connect to the server. Error: {str(e)}")
268
- raise gr.Error("Failed to connect to the server. Please check your network connection.")
 
 
 
269
  except requests.exceptions.RequestException as e:
270
  logger.error(f"An error occurred: {str(e)}")
271
  raise gr.Error(f"An error occurred: {str(e)}")
 
245
  with requests.post(url=url, data=data, files=files) as response:
246
  return response.ok
247
 
248
+ import time
249
+
250
  def run_fhe(user_id):
251
  """Apply the seizure detection model on the encrypted image previously sent using FHE."""
252
  data = {"user_id": user_id}
 
254
 
255
  try:
256
  logger.info(f"Sending request to {url} with user_id: {user_id}")
257
+
258
+ max_attempts = 20
259
+ attempt = 0
260
+ while attempt < max_attempts:
261
+ try:
262
+ with requests_retry_session().post(url=url, data=data, timeout=30) as response:
263
+ response.raise_for_status()
264
+ result = response.json()
265
+ logger.info(f"FHE execution completed. Result: {result}")
266
+ return result.get('execution_time', 'N/A')
267
+ except requests.exceptions.Timeout:
268
+ logger.info(f"Request timed out. Retrying... (Attempt {attempt + 1}/{max_attempts})")
269
+ time.sleep(15) # Wait for 15 seconds before retrying
270
+ attempt += 1
271
+
272
+ raise gr.Error("FHE execution timed out after multiple attempts")
273
+
274
  except requests.exceptions.RequestException as e:
275
  logger.error(f"An error occurred: {str(e)}")
276
  raise gr.Error(f"An error occurred: {str(e)}")