import streamlit as st from lyrics_translator import LyricsTranslator config = {"GENIUS_ACCESS_TOKEN": st.secrets["GENIUS_ACCESS_TOKEN"]} info = """ The "Lyrics Translator" downloads lyrics from Genius and uses 🤗 Hugging Face to translate the lyrics into a language of your choice! """ title = "🎵 Lyrics Translator" language_mapper = { "German": "de", "Swedish": "sv", "Italian": "it", "French": "fr", } st.title(title) st.info(info, icon="ℹ️") with st.sidebar: st.subheader("Automated lyrics translation!") song = st.text_input("Choose a track:", "One More Time") artist = st.text_input("Choose an artist:", "Daft Punk") language_original = st.radio("Choose a language:", tuple(language_mapper.keys())) is_button_results = st.button("Translate!") language = language_mapper.get(language_original, None) @st.cache_resource def load_translator(language): translator = LyricsTranslator(language=language, config=config) return translator if is_button_results: with st.spinner("Download the model this can take a while..."): translator = load_translator(language) col1, col2 = st.columns(2) with col1.container(): with st.spinner("Fetching the song lyrics, this can take a while..."): try: lyrics = translator.get_song_lyrics(song, artist) is_success = True except ValueError: col1.error("No lyrics found for this song!") if is_success: col1.success(f"Found lyrics for '{song}' by '{artist}'!") col1.text(lyrics) with col2.container(): with st.spinner("Song is being translated, this can take a while..."): try: text = translator.get_song_translation(song, artist) is_success = True except ValueError: col2.error("No lyrics found for this song!") if is_success: col2.success( f"Translated lyrics for '{song}' by '{artist}' to '{language_original}'!" ) col2.text(text)