import streamlit as st from translate import Translator # Streamlit app st.title("Text Translator") # Input text user_text = st.text_area("Enter the text you want to translate:") # Target language selection with a unique key st.subheader("Select the target language for translation:") target_language = st.selectbox("Select a target language:", ["af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "ny", "zh-cn", "co", "hr", "cs", "da", "nl", "en", "eo", "et", "tl", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "iw", "hi", "hmn", "hu", "is", "ig", "id", "ga", "it", "ja", "jw", "kn", "kk", "km", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "yo", "zu"]) # Initialize the translator translator = Translator(to_lang=target_language) # Translate the text when the user clicks the "Translate" button if st.button("Translate"): try: # Translate the input text to the selected target language translated_text = translator.translate(user_text) st.success(f"Translated text: {translated_text}") except Exception as e: st.error(f"Translation failed: {str(e)}")