Spaces:
Runtime error
Runtime error
File size: 892 Bytes
68a8c29 6570b48 68a8c29 5a1315d fc374da 39897d9 abed01c 39897d9 e3d850e 21247cf 606d796 a397155 e3d850e 39897d9 a397155 e3d850e 21247cf 16fc4ca b65ecd9 606d796 163a18d 606d796 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import streamlit as st
import langcodes
# https://huggingface.co/blog/streamlit-spaces
langtext = st.text_input("language code", "en")
if langcodes.tag_is_valid(langtext):
st.write(f"{langtext} is already a valid BCP-47 language tag")
else:
st.write(f"{langtext} is not already a valid BCP-47 language tag")
try:
lang = langcodes.Language.get(langtext)
except LanguageTagError as e:
st.write(f"{e}")
lang = None
if lang:
st.write(f"'{lang}' is a valid BCP-47 language code")
else:
try:
found = langcodes.find(langtext)
lang = found
except LookupError as e:
st.write(f"Couldn't look up langtext, sorry: {e}")
lang = None
#st.write(f"langcodes found the following tag: {type(found)}") # a Language object
display = lang.display_name()
st.write(f"langcodes found the following tag: {lang}")
st.write(f"Display name for {lang}: {display}")
|