CedricZ commited on
Commit
9a52147
·
1 Parent(s): aa4ffc9
Files changed (2) hide show
  1. app.py +13 -13
  2. te.ipynb +0 -0
app.py CHANGED
@@ -25,20 +25,20 @@ def respond(
25
  "top_p": top_p
26
  }
27
  )
28
- try:
29
- output = response.json()["choices"][0]["text"]
30
- except requests.exceptions.JSONDecodeError as e:
31
- cleaned_output = response.text.strip().rstrip('%')
32
- output = json.loads(cleaned_output)
33
-
34
- if isinstance(output, str):
35
- return output
36
- elif 'error' in output:
37
- if output['error']['code'] == 'concurrency_limit_exceeded':
38
- return "Error: Concurrency limit exceeded. Try submit your request again in a few seconds."
39
- else:
40
  return f"Error: {output['error']['message']}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
41
-
 
42
 
43
  demo = gr.Interface(
44
  fn=respond,
 
25
  "top_p": top_p
26
  }
27
  )
28
+ if response.status_code == 200:
29
+ return response.json()["choices"][0]["text"]
30
+ elif response.status_code == 429:
31
+ try:
32
+ output = response.json()
33
+ return f"Error: {output['error']['code']}. Try submit your request again in a few seconds."
34
+ except requests.exceptions.JSONDecodeError as e:
35
+ return f"Error: {response}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
36
+ else:
37
+ try:
38
+ output = response.json()
 
39
  return f"Error: {output['error']['message']}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
40
+ except requests.exceptions.JSONDecodeError as e:
41
+ return f"Error: {response}. Refresh the page and try again later, post the error on OLAT forum if your issue persists."
42
 
43
  demo = gr.Interface(
44
  fn=respond,
te.ipynb ADDED
File without changes