Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from translate import Translator | |
| def translate_text(text, src_language, dest_language): | |
| translator = Translator(from_lang=src_language, to_lang=dest_language) | |
| translation = translator.translate(text) | |
| return translation | |
| st.title("Text Translator") | |
| option = st.selectbox( | |
| 'Select translation direction:', | |
| ('Arabic to English', 'English to Arabic') | |
| ) | |
| uploaded_file = st.file_uploader("Upload a text file (optional)", type=["txt"]) | |
| input_text = st.text_area("Enter the text you want to translate", "") | |
| if uploaded_file is not None: | |
| input_text = uploaded_file.read().decode("utf-8") | |
| if st.button("Translate"): | |
| if input_text.strip() != "": | |
| if option == 'Arabic to English': | |
| translated_text = translate_text(input_text, 'arabic', 'english') | |
| else: | |
| translated_text = translate_text(input_text, 'english', 'arabic') | |
| st.text_area("Translated Text", translated_text, height=200) | |
| else: | |
| st.warning("Please enter some text to translate.") | |