Update app.py
Browse files
app.py
CHANGED
@@ -82,22 +82,16 @@ def main():
|
|
82 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
83 |
selected_file = st.selectbox("Choose a file", all_files, on_change=song_update, key='selected_file')
|
84 |
|
85 |
-
col1, col2 = st.columns([
|
86 |
|
87 |
with col1:
|
88 |
-
song_name_input = st.text_input("🎵 Song
|
89 |
-
artist_name_input = st.text_input("🎤 Artist
|
90 |
|
91 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
92 |
# Update the session state before creating the text area widget
|
93 |
st.session_state['chord_sheet'] = load_song_file(st.session_state.selected_file)
|
94 |
|
95 |
-
# Now create the text area widget with the updated session state
|
96 |
-
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=300, key='chord_sheet', on_change=auto_save)
|
97 |
-
|
98 |
-
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
99 |
-
st.write(char_count_msg)
|
100 |
-
|
101 |
# Save functionality
|
102 |
if st.button("💾 Save", key="save_song"):
|
103 |
if song_name_input and artist_name_input:
|
@@ -108,30 +102,39 @@ def main():
|
|
108 |
else:
|
109 |
st.error("Both Song Name and Artist Name are required.")
|
110 |
|
|
|
|
|
|
|
111 |
st.header("🎼 Available Songs")
|
112 |
for file in all_files:
|
113 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
114 |
-
icol1, icol2 = st.columns([4,
|
115 |
with icol1:
|
116 |
st.markdown(f"* {song_info}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
with icol2:
|
118 |
-
st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
|
119 |
-
st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
|
120 |
-
st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
|
121 |
-
st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
-
with
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
|
132 |
-
st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
|
133 |
-
st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
|
134 |
|
|
|
|
|
|
|
|
|
135 |
|
136 |
# Load chord sheet from selected file into the text area
|
137 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
|
|
82 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
83 |
selected_file = st.selectbox("Choose a file", all_files, on_change=song_update, key='selected_file')
|
84 |
|
85 |
+
col1, col2, col3 = st.columns([1, 1, 4])
|
86 |
|
87 |
with col1:
|
88 |
+
song_name_input = st.text_input("🎵 Song:", key='song_name', on_change=auto_save)
|
89 |
+
artist_name_input = st.text_input("🎤 Artist:", key='artist_name', on_change=auto_save)
|
90 |
|
91 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
92 |
# Update the session state before creating the text area widget
|
93 |
st.session_state['chord_sheet'] = load_song_file(st.session_state.selected_file)
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Save functionality
|
96 |
if st.button("💾 Save", key="save_song"):
|
97 |
if song_name_input and artist_name_input:
|
|
|
102 |
else:
|
103 |
st.error("Both Song Name and Artist Name are required.")
|
104 |
|
105 |
+
|
106 |
+
with col2:
|
107 |
+
|
108 |
st.header("🎼 Available Songs")
|
109 |
for file in all_files:
|
110 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
111 |
+
icol1, icol2 = st.columns([4, 2])
|
112 |
with icol1:
|
113 |
st.markdown(f"* {song_info}")
|
114 |
+
|
115 |
+
if selected_file:
|
116 |
+
st.markdown(f"**Selected Song:** {song_info}")
|
117 |
+
|
118 |
+
load_song_file(selected_file)
|
119 |
+
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
120 |
+
|
121 |
with icol2:
|
|
|
|
|
|
|
|
|
122 |
|
123 |
+
if selected_file:
|
124 |
+
st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
|
125 |
+
st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
|
126 |
+
st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
|
127 |
+
st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
|
128 |
|
129 |
+
with col3:
|
130 |
+
|
131 |
+
# Now create the text area widget with the updated session state
|
132 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=600, key='chord_sheet', on_change=auto_save)
|
|
|
|
|
|
|
133 |
|
134 |
+
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
135 |
+
st.write(char_count_msg)
|
136 |
+
|
137 |
+
|
138 |
|
139 |
# Load chord sheet from selected file into the text area
|
140 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|