Adding try except
Browse files
app.py
CHANGED
|
@@ -11,14 +11,15 @@ def translate(text):
|
|
| 11 |
payload = {
|
| 12 |
"inputs": text,
|
| 13 |
}
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 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(
|