File size: 1,042 Bytes
c681c1e
35d98db
c681c1e
 
35d98db
 
 
c681c1e
 
 
35d98db
 
 
 
 
 
 
c681c1e
 
35d98db
 
 
c681c1e
 
35d98db
 
 
 
c681c1e
 
 
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
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.")