Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,8 @@ from gtts import gTTS
|
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
# Title and Introduction
|
| 8 |
-
st.title("Language Learning App")
|
| 9 |
-
st.write("
|
| 10 |
|
| 11 |
# Sidebar Options
|
| 12 |
st.sidebar.header("Choose an Operation")
|
|
@@ -16,33 +16,55 @@ operation = st.sidebar.selectbox("Operation", options)
|
|
| 16 |
# Input Text
|
| 17 |
text = st.text_area("Enter your text here:")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Translation Functionality
|
| 20 |
if operation == "Translate Text":
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
if st.button("Translate"):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Grammar Correction Functionality
|
| 30 |
elif operation == "Correct Grammar":
|
| 31 |
if st.button("Correct Grammar"):
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Pronunciation Practice Functionality
|
| 38 |
elif operation == "Practice Pronunciation":
|
|
|
|
|
|
|
| 39 |
if st.button("Generate Audio"):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Prompt for Text Input
|
| 48 |
else:
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
# Title and Introduction
|
| 8 |
+
st.title("Advanced Language Learning App")
|
| 9 |
+
st.write("Enhance your language skills with multilingual translation, grammar correction, and pronunciation practice!")
|
| 10 |
|
| 11 |
# Sidebar Options
|
| 12 |
st.sidebar.header("Choose an Operation")
|
|
|
|
| 16 |
# Input Text
|
| 17 |
text = st.text_area("Enter your text here:")
|
| 18 |
|
| 19 |
+
# Supported Languages
|
| 20 |
+
languages = {
|
| 21 |
+
"English": "en", "French": "fr", "Spanish": "es", "German": "de", "Chinese": "zh", "Japanese": "ja",
|
| 22 |
+
"Arabic": "ar", "Russian": "ru", "Hindi": "hi", "Urdu": "ur", "Portuguese": "pt", "Italian": "it",
|
| 23 |
+
"Dutch": "nl", "Korean": "ko", "Swedish": "sv", "Turkish": "tr", "Polish": "pl", "Danish": "da",
|
| 24 |
+
"Finnish": "fi", "Norwegian": "no", "Greek": "el", "Hebrew": "he", "Thai": "th", "Vietnamese": "vi",
|
| 25 |
+
"Czech": "cs", "Hungarian": "hu", "Indonesian": "id", "Malay": "ms", "Filipino": "tl", "Swahili": "sw"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
# Translation Functionality
|
| 29 |
if operation == "Translate Text":
|
| 30 |
+
source_language = st.selectbox("Select Source Language", list(languages.keys()))
|
| 31 |
+
target_language = st.selectbox("Select Target Language", list(languages.keys()))
|
| 32 |
|
| 33 |
if st.button("Translate"):
|
| 34 |
+
try:
|
| 35 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-{src}-{tgt}".format(
|
| 36 |
+
src=languages[source_language], tgt=languages[target_language]))
|
| 37 |
+
translation = translator(text, max_length=400)[0]['translation_text']
|
| 38 |
+
st.write("### Translation:")
|
| 39 |
+
st.write(translation)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"Translation failed: {e}")
|
| 42 |
|
| 43 |
# Grammar Correction Functionality
|
| 44 |
elif operation == "Correct Grammar":
|
| 45 |
if st.button("Correct Grammar"):
|
| 46 |
+
try:
|
| 47 |
+
corrector = pipeline("text2text-generation", model="prithivida/grammar-error-correction")
|
| 48 |
+
corrected_text = corrector(text, max_length=400)[0]['generated_text']
|
| 49 |
+
st.write("### Corrected Text:")
|
| 50 |
+
st.write(corrected_text)
|
| 51 |
+
except Exception as e:
|
| 52 |
+
st.error(f"Grammar correction failed: {e}")
|
| 53 |
|
| 54 |
# Pronunciation Practice Functionality
|
| 55 |
elif operation == "Practice Pronunciation":
|
| 56 |
+
language = st.selectbox("Select Pronunciation Language", list(languages.keys()))
|
| 57 |
+
|
| 58 |
if st.button("Generate Audio"):
|
| 59 |
+
try:
|
| 60 |
+
tts = gTTS(text=text, lang=languages[language])
|
| 61 |
+
audio_file = BytesIO()
|
| 62 |
+
tts.write_to_fp(audio_file)
|
| 63 |
+
audio_file.seek(0)
|
| 64 |
+
st.audio(audio_file, format="audio/mp3")
|
| 65 |
+
st.write("### Listen to the pronunciation!")
|
| 66 |
+
except Exception as e:
|
| 67 |
+
st.error(f"Pronunciation generation failed: {e}")
|
| 68 |
|
| 69 |
# Prompt for Text Input
|
| 70 |
else:
|