Nehal07 commited on
Commit
aba198b
1 Parent(s): 932fe2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from googletrans import Translator, LANGUAGES, LANGCODES
3
 
4
  # Streamlit app
5
  st.title("Text Translator")
@@ -7,11 +7,6 @@ st.title("Text Translator")
7
  # Input text
8
  user_text = st.text_area("Enter the text you want to translate:")
9
 
10
- # Source language selection with a unique key
11
- st.subheader("Select the source language of the input text:")
12
- source_language_options = {lang: code for code, lang in LANGUAGES.items()}
13
- selected_source_language = st.selectbox("Select a source language:", list(source_language_options.keys()), key="source_language")
14
-
15
  # Target language selection with a unique key
16
  st.subheader("Select the target language for translation:")
17
  target_language_options = {lang: code for code, lang in LANGUAGES.items()}
@@ -23,14 +18,11 @@ translator = Translator()
23
  # Translate the text when the user clicks the "Translate" button
24
  if st.button("Translate"):
25
  try:
26
- # Translate the input text from the source language to the target language
27
- src_lang_code = LANGCODES[selected_source_language]
28
- dest_lang_code = LANGCODES[selected_target_language]
29
-
30
  translated = translator.translate(
31
  user_text,
32
- src=src_lang_code,
33
- dest=dest_lang_code
34
  )
35
 
36
  translated_text = translated.text
 
1
  import streamlit as st
2
+ from googletrans import Translator, LANGUAGES
3
 
4
  # Streamlit app
5
  st.title("Text Translator")
 
7
  # Input text
8
  user_text = st.text_area("Enter the text you want to translate:")
9
 
 
 
 
 
 
10
  # Target language selection with a unique key
11
  st.subheader("Select the target language for translation:")
12
  target_language_options = {lang: code for code, lang in LANGUAGES.items()}
 
18
  # Translate the text when the user clicks the "Translate" button
19
  if st.button("Translate"):
20
  try:
21
+ # Translate the input text from English to the target language
 
 
 
22
  translated = translator.translate(
23
  user_text,
24
+ src='en', # Source language is set to English
25
+ dest=target_language_options[selected_target_language]
26
  )
27
 
28
  translated_text = translated.text