File size: 2,149 Bytes
54b1fe1
 
ea04319
 
0cf4cf0
a227844
 
 
f712385
a227844
 
 
 
 
 
 
 
 
 
 
6c8a4c2
f712385
6c8a4c2
54b1fe1
 
a227844
 
 
 
0a5a379
54b1fe1
0cf4cf0
54b1fe1
 
a227844
54b1fe1
 
 
 
611653c
54b1fe1
 
 
 
 
 
 
a227844
 
d570f17
 
54b1fe1
d570f17
 
 
 
54b1fe1
d570f17
 
 
54b1fe1
d570f17
 
 
 
 
54b1fe1
d570f17
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)