Update app.py
Browse files
app.py
CHANGED
@@ -7,12 +7,15 @@ st.title("Text Translator")
|
|
7 |
# Input text
|
8 |
user_text = st.text_area("Enter the text you want to translate:")
|
9 |
|
10 |
-
#
|
11 |
-
st.subheader("Select the
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
# Initialize the translator
|
18 |
translator = Translator()
|
@@ -20,8 +23,15 @@ translator = Translator()
|
|
20 |
# Translate the text when the user clicks the "Translate" button
|
21 |
if st.button("Translate"):
|
22 |
try:
|
23 |
-
# Translate the text to the
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
except Exception as e:
|
27 |
st.error(f"Translation failed: {str(e)}")
|
|
|
7 |
# Input text
|
8 |
user_text = st.text_area("Enter the text you want to translate:")
|
9 |
|
10 |
+
# Source language selection
|
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 language:", list(source_language_options.keys()))
|
14 |
|
15 |
+
# Target language selection
|
16 |
+
st.subheader("Select the target language for translation:")
|
17 |
+
target_language_options = {lang: code for code, lang in LANGUAGES.items()}
|
18 |
+
selected_target_language = st.selectbox("Select a language:", list(target_language_options.keys()))
|
19 |
|
20 |
# Initialize the translator
|
21 |
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 |
+
translated = translator.translate(
|
28 |
+
user_text,
|
29 |
+
src=source_language_options[selected_source_language],
|
30 |
+
dest=target_language_options[selected_target_language]
|
31 |
+
)
|
32 |
+
translated_text = translated.text
|
33 |
+
translated_language = LANGUAGES[translated.dest]
|
34 |
+
|
35 |
+
st.success(f"Translated text ({translated_language}): {translated_text}")
|
36 |
except Exception as e:
|
37 |
st.error(f"Translation failed: {str(e)}")
|