Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st from transformers import pipeline from gtts import gTTS import os
|
2 |
+
|
3 |
+
def translate_text(text, src_lang, tgt_lang): translator = pipeline("translation_{}-to-{}".format(src_lang, tgt_lang)) result = translator(text, max_length=100)[0]['translation_text'] return result
|
4 |
+
|
5 |
+
def text_to_speech(text, lang): tts = gTTS(text=text, lang=lang) tts.save("output.mp3") return "output.mp3"
|
6 |
+
|
7 |
+
def main(): st.title("Language Learning App") st.sidebar.header("Settings") src_lang = st.sidebar.selectbox("Select Source Language", ["en", "fr", "es", "de"]) tgt_lang = st.sidebar.selectbox("Select Target Language", ["en", "fr", "es", "de"])
|
8 |
+
|
9 |
+
st.header("Translation")
|
10 |
+
user_input = st.text_area("Enter text to translate:")
|
11 |
+
if st.button("Translate"):
|
12 |
+
if user_input:
|
13 |
+
translation = translate_text(user_input, src_lang, tgt_lang)
|
14 |
+
st.success("Translated Text: " + translation)
|
15 |
+
|
16 |
+
if st.button("Listen to Translation"):
|
17 |
+
audio_file = text_to_speech(translation, tgt_lang)
|
18 |
+
st.audio(audio_file)
|
19 |
+
|
20 |
+
st.header("Vocabulary Practice")
|
21 |
+
st.write("(Coming Soon!)")
|
22 |
+
|
23 |
+
if name == "main": main()
|