File size: 1,130 Bytes
f5f5122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import streamlit as st from transformers import pipeline from gtts import gTTS import os

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

def text_to_speech(text, lang): tts = gTTS(text=text, lang=lang) tts.save("output.mp3") return "output.mp3"

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"])

st.header("Translation")
user_input = st.text_area("Enter text to translate:")
if st.button("Translate"):
    if user_input:
        translation = translate_text(user_input, src_lang, tgt_lang)
        st.success("Translated Text: " + translation)
        
        if st.button("Listen to Translation"):
            audio_file = text_to_speech(translation, tgt_lang)
            st.audio(audio_file)

st.header("Vocabulary Practice")
st.write("(Coming Soon!)")

if name == "main": main()