Added button and error messages
Browse files
app.py
CHANGED
|
@@ -12,7 +12,13 @@ def translate(text):
|
|
| 12 |
"inputs": text,
|
| 13 |
}
|
| 14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
st.set_page_config(
|
|
@@ -29,11 +35,11 @@ text = st.text_area("Enter text:",
|
|
| 29 |
help="Enter your text here",
|
| 30 |
)
|
| 31 |
|
| 32 |
-
if
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
|
| 39 |
|
|
|
|
| 12 |
"inputs": text,
|
| 13 |
}
|
| 14 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 15 |
+
json_response = response.json()
|
| 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(
|
|
|
|
| 35 |
help="Enter your text here",
|
| 36 |
)
|
| 37 |
|
| 38 |
+
if st.button('Translate'):
|
| 39 |
+
if str(text).strip() == "":
|
| 40 |
+
st.warning('Please **enter text** for translation')
|
| 41 |
+
else:
|
| 42 |
+
st.info(str(translate(text)))
|
| 43 |
|
| 44 |
|
| 45 |
|