Pavi0602 commited on
Commit
0240bbc
1 Parent(s): 3334dd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -46
app.py CHANGED
@@ -8,50 +8,34 @@ def translate_text(text, from_lang, to_lang):
8
  return translation
9
 
10
  # Streamlit app
11
-
12
- # Header and description
13
- st.markdown("""
14
- <style>
15
- .title {
16
- font-size: 36px;
17
- font-weight: bold;
18
- color: #0056b3;
19
- text-align: center;
20
- margin-bottom: 20px;
21
- }
22
- .description {
23
- font-size: 18px;
24
- color: #333;
25
- text-align: center;
26
- margin-bottom: 30px;
27
- }
28
- </style>
29
- """, unsafe_allow_html=True)
30
-
31
- st.markdown('<p class="title">Multilingual Text Translator</p>', unsafe_allow_html=True)
32
-
33
-
34
- # Language selection and input area
35
- col1, col2 = st.columns(2)
36
- with col1:
37
- from_lang = st.selectbox('Select the source language:',
38
- ['English', 'Spanish', 'French', 'German', 'Chinese', 'Japanese', 'Hindi'])
39
- with col2:
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
- with st.spinner('Translating...'):
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.')