Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from lyrics_translator import LyricsTranslator
3
+
4
+
5
+ config = {"GENIUS_ACCESS_TOKEN": st.secrets["GENIUS_ACCESS_TOKEN"]}
6
+
7
+
8
+ info = """
9
+ The "Lyrics Translator" downloads lyrics from Genius and uses 🤗 Hugging Face to translate the lyrics into a language of your choice!
10
+ """
11
+
12
+ title = "🎵 Lyrics Translator"
13
+
14
+ language_mapper = {
15
+ "German": "de",
16
+ "Swedish": "sv",
17
+ "Italian": "it",
18
+ "French": "fr",
19
+ }
20
+
21
+ st.title(title)
22
+ st.info(info, icon="ℹ️")
23
+
24
+
25
+ with st.sidebar:
26
+ st.subheader("Automated lyrics translation!")
27
+
28
+ song = st.text_input("Choose a track:", "One More Time")
29
+ artist = st.text_input("Choose an artist:", "Daft Punk")
30
+ language_original = st.radio("Choose a language:", tuple(language_mapper.keys()))
31
+
32
+ is_button_results = st.button("Translate!")
33
+
34
+
35
+ language = language_mapper.get(language_original, None)
36
+
37
+
38
+ @st.cache_resource
39
+ def load_translator(language):
40
+ translator = LyricsTranslator(language=language, config=config)
41
+ return translator
42
+
43
+
44
+ if is_button_results:
45
+ with st.spinner("Download the model this can take a while..."):
46
+ translator = load_translator(language)
47
+
48
+ col1, col2 = st.columns(2)
49
+
50
+ with col1.container():
51
+ with st.spinner("Fetching the song lyrics, this can take a while..."):
52
+ try:
53
+ lyrics = translator.get_song_lyrics(song, artist)
54
+ is_success = True
55
+ except ValueError:
56
+ col1.error("No lyrics found for this song!")
57
+
58
+ if is_success:
59
+ col1.success(f"Found lyrics for '{song}' by '{artist}'!")
60
+ col1.text(lyrics)
61
+
62
+ with col2.container():
63
+ with st.spinner("Song is being translated, this can take a while..."):
64
+ try:
65
+ text = translator.get_song_translation(song, artist)
66
+ is_success = True
67
+ except ValueError:
68
+ col2.error("No lyrics found for this song!")
69
+
70
+ if is_success:
71
+ col2.success(
72
+ f"Translated lyrics for '{song}' by '{artist}' to '{language_original}'!"
73
+ )
74
+ col2.text(text)