versae commited on
Commit
ec54f3f
·
1 Parent(s): 43b19d1

Adding try except

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -11,14 +11,15 @@ def translate(text):
11
  payload = {
12
  "inputs": text,
13
  }
14
- response = requests.post(API_URL, headers=headers, json=payload)
15
- json_response = response.json()[0]
16
- if "error" in json_response:
17
- return f"Model still loading: {json_response}"
18
- elif "translation_text" in json_response:
19
- return json_response["translation_text"]
20
- else:
21
- return "Oops, something went wrong."
 
22
 
23
 
24
  st.set_page_config(
 
11
  payload = {
12
  "inputs": text,
13
  }
14
+ try:
15
+ response = requests.post(API_URL, headers=headers, json=payload)
16
+ json_response = response.json()[0]
17
+ if "error" in json_response:
18
+ return f"Model still loading: {json_response}"
19
+ elif "translation_text" in json_response:
20
+ return json_response["translation_text"]
21
+ except Exception as exc:
22
+ return f"Oops, something went wrong: {exc}"
23
 
24
 
25
  st.set_page_config(