Spaces:
Sleeping
Sleeping
polling
Browse files
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 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
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)}")
|