Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from gtts import gTTS
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
# Title and Introduction
|
| 8 |
+
st.title("Language Learning App")
|
| 9 |
+
st.write("Improve your language skills with translation, grammar correction, and pronunciation practice!")
|
| 10 |
+
|
| 11 |
+
# Sidebar Options
|
| 12 |
+
st.sidebar.header("Choose an Operation")
|
| 13 |
+
options = ["Translate Text", "Correct Grammar", "Practice Pronunciation"]
|
| 14 |
+
operation = st.sidebar.selectbox("Operation", options)
|
| 15 |
+
|
| 16 |
+
# Input Text
|
| 17 |
+
text = st.text_area("Enter your text here:")
|
| 18 |
+
|
| 19 |
+
# Translation Functionality
|
| 20 |
+
if operation == "Translate Text":
|
| 21 |
+
target_language = st.selectbox("Select Target Language", ["French", "Spanish", "German", "Chinese", "Japanese"])
|
| 22 |
+
|
| 23 |
+
if st.button("Translate"):
|
| 24 |
+
translator = pipeline("translation_en_to_" + target_language.lower())
|
| 25 |
+
translation = translator(text, max_length=100)[0]['translation_text']
|
| 26 |
+
st.write("### Translation:")
|
| 27 |
+
st.write(translation)
|
| 28 |
+
|
| 29 |
+
# Grammar Correction Functionality
|
| 30 |
+
elif operation == "Correct Grammar":
|
| 31 |
+
if st.button("Correct Grammar"):
|
| 32 |
+
corrector = pipeline("text2text-generation", model="t5-small", task="grammar-correction")
|
| 33 |
+
corrected_text = corrector(text, max_length=100)[0]['generated_text']
|
| 34 |
+
st.write("### Corrected Text:")
|
| 35 |
+
st.write(corrected_text)
|
| 36 |
+
|
| 37 |
+
# Pronunciation Practice Functionality
|
| 38 |
+
elif operation == "Practice Pronunciation":
|
| 39 |
+
if st.button("Generate Audio"):
|
| 40 |
+
tts = gTTS(text=text, lang="en")
|
| 41 |
+
audio_file = BytesIO()
|
| 42 |
+
tts.write_to_fp(audio_file)
|
| 43 |
+
audio_file.seek(0)
|
| 44 |
+
st.audio(audio_file, format="audio/mp3")
|
| 45 |
+
st.write("### Listen to the pronunciation!")
|
| 46 |
+
|
| 47 |
+
# Prompt for Text Input
|
| 48 |
+
else:
|
| 49 |
+
st.write("Please enter text to begin.")
|