Update app.py
Browse files
app.py
CHANGED
@@ -8,50 +8,34 @@ def translate_text(text, from_lang, to_lang):
|
|
8 |
return translation
|
9 |
|
10 |
# Streamlit app
|
11 |
-
|
12 |
-
|
13 |
-
st.
|
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 |
-
|
39 |
-
|
40 |
-
to_lang = st.selectbox('Select the target language:',
|
41 |
-
['Spanish', 'English', 'French', 'German', 'Chinese', 'Japanese', 'Hindi'])
|
42 |
-
|
43 |
-
text = st.text_area('Enter the text you want to translate:', height=150)
|
44 |
-
|
45 |
-
# Translation button
|
46 |
-
if st.button('Translate', key='translate_btn'):
|
47 |
-
if text.strip() == '':
|
48 |
-
st.warning('Please enter the text you want to translate.')
|
49 |
else:
|
50 |
-
|
51 |
-
from_lang_code = lang_codes[from_lang]
|
52 |
-
to_lang_code = lang_codes[to_lang]
|
53 |
-
translation = translate_text(text, from_lang_code, to_lang_code)
|
54 |
-
st.success(f'Translation ({from_lang} to {to_lang}):')
|
55 |
-
st.write(f'{translation}')
|
56 |
-
|
57 |
-
|
|
|
8 |
return translation
|
9 |
|
10 |
# Streamlit app
|
11 |
+
st.title('Multilingual Text Translator')
|
12 |
+
|
13 |
+
st.write('Translate text from one language to another with this simple app.')
|
14 |
+
|
15 |
+
from_lang = st.selectbox('Select the source language:',
|
16 |
+
['English', 'Spanish', 'French', 'German', 'Chinese', 'Japanese', 'Hindi'],
|
17 |
+
index=0)
|
18 |
+
to_lang = st.selectbox('Select the target language:',
|
19 |
+
['Spanish', 'English', 'French', 'German', 'Chinese', 'Japanese', 'Hindi'],
|
20 |
+
index=1)
|
21 |
+
|
22 |
+
lang_codes = {
|
23 |
+
'English': 'en',
|
24 |
+
'Spanish': 'es',
|
25 |
+
'French': 'fr',
|
26 |
+
'German': 'de',
|
27 |
+
'Chinese': 'zh',
|
28 |
+
'Japanese': 'ja',
|
29 |
+
'Hindi': 'hi'
|
30 |
+
}
|
31 |
+
|
32 |
+
text = st.text_area('Enter the text you want to translate:')
|
33 |
+
|
34 |
+
if st.button('Translate'):
|
35 |
+
if text:
|
36 |
+
from_lang_code = lang_codes[from_lang]
|
37 |
+
to_lang_code = lang_codes[to_lang]
|
38 |
+
translation = translate_text(text, from_lang_code, to_lang_code)
|
39 |
+
st.success(f'Translation ({from_lang} to {to_lang}): {translation}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
else:
|
41 |
+
st.error('Please enter the text you want to translate.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|