Spaces:
Sleeping
Sleeping
logging
Browse files
app.py
CHANGED
@@ -18,7 +18,34 @@ from common import (
|
|
18 |
REPO_DIR,
|
19 |
SERVER_URL,
|
20 |
)
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Uncomment here to have both the server and client in the same terminal
|
24 |
subprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)
|
@@ -222,19 +249,26 @@ def run_fhe(user_id):
|
|
222 |
url = SERVER_URL + "run_fhe"
|
223 |
|
224 |
try:
|
225 |
-
|
|
|
|
|
226 |
response.raise_for_status() # Raises an HTTPError for bad responses
|
227 |
if response.ok:
|
228 |
return response.json()
|
229 |
else:
|
|
|
230 |
raise gr.Error(f"Server responded with status code {response.status_code}")
|
231 |
except requests.exceptions.Timeout:
|
|
|
232 |
raise gr.Error("The request timed out. The server might be overloaded.")
|
233 |
-
except requests.exceptions.ConnectionError:
|
|
|
234 |
raise gr.Error("Failed to connect to the server. Please check your network connection.")
|
235 |
except requests.exceptions.RequestException as e:
|
|
|
236 |
raise gr.Error(f"An error occurred: {str(e)}")
|
237 |
except Exception as e:
|
|
|
238 |
raise gr.Error(f"An unexpected error occurred: {str(e)}")
|
239 |
|
240 |
def get_output(user_id):
|
|
|
18 |
REPO_DIR,
|
19 |
SERVER_URL,
|
20 |
)
|
21 |
+
|
22 |
+
import requests
|
23 |
+
from requests.adapters import HTTPAdapter
|
24 |
+
from requests.packages.urllib3.util.retry import Retry
|
25 |
+
import logging
|
26 |
+
|
27 |
+
# Set up logging
|
28 |
+
logging.basicConfig(level=logging.DEBUG)
|
29 |
+
logger = logging.getLogger(__name__)
|
30 |
+
|
31 |
+
def requests_retry_session(
|
32 |
+
retries=3,
|
33 |
+
backoff_factor=0.3,
|
34 |
+
status_forcelist=(500, 502, 504),
|
35 |
+
session=None,
|
36 |
+
):
|
37 |
+
session = session or requests.Session()
|
38 |
+
retry = Retry(
|
39 |
+
total=retries,
|
40 |
+
read=retries,
|
41 |
+
connect=retries,
|
42 |
+
backoff_factor=backoff_factor,
|
43 |
+
status_forcelist=status_forcelist,
|
44 |
+
)
|
45 |
+
adapter = HTTPAdapter(max_retries=retry)
|
46 |
+
session.mount('http://', adapter)
|
47 |
+
session.mount('https://', adapter)
|
48 |
+
return session
|
49 |
|
50 |
# Uncomment here to have both the server and client in the same terminal
|
51 |
subprocess.Popen(["uvicorn", "server:app"], cwd=REPO_DIR)
|
|
|
249 |
url = SERVER_URL + "run_fhe"
|
250 |
|
251 |
try:
|
252 |
+
logger.info(f"Sending request to {url} with user_id: {user_id}")
|
253 |
+
with requests_retry_session().post(url=url, data=data, timeout=300) as response:
|
254 |
+
logger.info(f"Received response with status code: {response.status_code}")
|
255 |
response.raise_for_status() # Raises an HTTPError for bad responses
|
256 |
if response.ok:
|
257 |
return response.json()
|
258 |
else:
|
259 |
+
logger.error(f"Server responded with status code {response.status_code}")
|
260 |
raise gr.Error(f"Server responded with status code {response.status_code}")
|
261 |
except requests.exceptions.Timeout:
|
262 |
+
logger.error("The request timed out. The server might be overloaded.")
|
263 |
raise gr.Error("The request timed out. The server might be overloaded.")
|
264 |
+
except requests.exceptions.ConnectionError as e:
|
265 |
+
logger.error(f"Failed to connect to the server. Error: {str(e)}")
|
266 |
raise gr.Error("Failed to connect to the server. Please check your network connection.")
|
267 |
except requests.exceptions.RequestException as e:
|
268 |
+
logger.error(f"An error occurred: {str(e)}")
|
269 |
raise gr.Error(f"An error occurred: {str(e)}")
|
270 |
except Exception as e:
|
271 |
+
logger.error(f"An unexpected error occurred: {str(e)}")
|
272 |
raise gr.Error(f"An unexpected error occurred: {str(e)}")
|
273 |
|
274 |
def get_output(user_id):
|