liujch1998 commited on
Commit
aa7da7f
·
1 Parent(s): 2ca70fe

Add request timeout

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -21,7 +21,12 @@ def process(query_type, corpus_desc, engine_desc, query, maxnum, request: gr.Req
21
  print(json.dumps(data))
22
  if API_URL is None:
23
  raise ValueError(f'API_URL envvar is not set!')
24
- response = requests.post(API_URL, json=data)
 
 
 
 
 
25
  if response.status_code == 200:
26
  result = response.json()
27
  else:
 
21
  print(json.dumps(data))
22
  if API_URL is None:
23
  raise ValueError(f'API_URL envvar is not set!')
24
+ try:
25
+ response = requests.post(API_URL, json=data, timeout=10)
26
+ except requests.exceptions.Timeout:
27
+ raise ValueError('Web request timed out. Please try again later.')
28
+ except requests.exceptions.RequestException as e:
29
+ raise ValueError(f'Web request error: {e}')
30
  if response.status_code == 200:
31
  result = response.json()
32
  else: