Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,22 @@ def load_song_file(file_path):
|
|
20 |
with open(file_path, 'r', encoding='utf-8') as file:
|
21 |
return file.read()
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def display_chord_sheet_in_two_page_view(chord_sheet):
|
24 |
# CSS for multi-column layout
|
25 |
css_content = """
|
@@ -52,14 +68,33 @@ def main():
|
|
52 |
with st.expander("Select Song:", expanded=True):
|
53 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
54 |
selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
st.
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
with col3:
|
65 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
|
|
20 |
with open(file_path, 'r', encoding='utf-8') as file:
|
21 |
return file.read()
|
22 |
|
23 |
+
def create_search_url_wikipedia(artist_song):
|
24 |
+
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
|
25 |
+
return base_url + artist_song.replace(' ', '+').replace('β', '%E2%80%93').replace('&', 'and')
|
26 |
+
|
27 |
+
def create_search_url_youtube(artist_song):
|
28 |
+
base_url = "https://www.youtube.com/results?search_query="
|
29 |
+
return base_url + artist_song.replace(' ', '+').replace('β', '%E2%80%93').replace('&', 'and')
|
30 |
+
|
31 |
+
def create_search_url_chords(artist_song):
|
32 |
+
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
|
33 |
+
return base_url + artist_song.replace(' ', '+').replace('β', '%E2%80%93').replace('&', 'and')
|
34 |
+
|
35 |
+
def create_search_url_lyrics(artist_song):
|
36 |
+
base_url = "https://www.google.com/search?q="
|
37 |
+
return base_url + artist_song.replace(' ', '+').replace('β', '%E2%80%93').replace('&', 'and') + '+lyrics'
|
38 |
+
|
39 |
def display_chord_sheet_in_two_page_view(chord_sheet):
|
40 |
# CSS for multi-column layout
|
41 |
css_content = """
|
|
|
68 |
with st.expander("Select Song:", expanded=True):
|
69 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
70 |
selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
|
71 |
+
if selected_file:
|
72 |
+
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
73 |
+
st.header("πΌ Current Song")
|
74 |
+
st.markdown("**" + song_info + "**")
|
75 |
+
chord_sheet = load_song_file(selected_file)
|
76 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
77 |
+
st.markdown(processed_sheet, unsafe_allow_html=True)
|
78 |
+
table_md = f"""
|
79 |
+
| Wikipedia | YouTube | Chords | Lyrics |
|
80 |
+
| --------- | ------- | ------ | ------ |
|
81 |
+
| [π]({create_search_url_wikipedia(song_info)}) | [π₯]({create_search_url_youtube(song_info)}) | [πΈ]({create_search_url_chords(song_info)}) | [πΆ]({create_search_url_lyrics(song_info)}) |
|
82 |
+
"""
|
83 |
+
st.markdown(table_md)
|
84 |
|
85 |
+
st.header("πΌ Available Songs")
|
86 |
+
for file in all_files:
|
87 |
+
song_info = os.path.splitext(file)[0].replace("_", " ")
|
88 |
+
icol1, icol2 = st.columns([1, 3])
|
89 |
+
with icol1:
|
90 |
+
st.markdown("**" + song_info + "**")
|
91 |
+
with icol2:
|
92 |
+
table_md = f"""
|
93 |
+
| Wikipedia | YouTube | Chords | Lyrics |
|
94 |
+
| --------- | ------- | ------ | ------ |
|
95 |
+
| [π]({create_search_url_wikipedia(song_info)}) | [π₯]({create_search_url_youtube(song_info)}) | [πΈ]({create_search_url_chords(song_info)}) | [πΆ]({create_search_url_lyrics(song_info)}) |
|
96 |
+
"""
|
97 |
+
st.markdown(table_md)
|
98 |
|
99 |
with col3:
|
100 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|