AdeebaZahra's picture
Create app.py
f5f5122 verified
raw
history blame
1.13 kB
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()