Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,14 +39,13 @@ def songupdate():
|
|
39 |
def load_song_file2(filename):
|
40 |
with open(filename, "r") as file:
|
41 |
chord_sheet = file.read()
|
42 |
-
st.session_state['chord_sheet'] = chord_sheet
|
43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
45 |
|
46 |
def load_song_file(filename):
|
47 |
with open(filename, "r") as file:
|
48 |
chord_sheet = file.read()
|
49 |
-
# Instead of directly modifying the session state, return the chord sheet content
|
50 |
return chord_sheet
|
51 |
|
52 |
def song_update():
|
@@ -77,14 +76,15 @@ def auto_save():
|
|
77 |
st.success(f"Auto-saved to {filename}")
|
78 |
|
79 |
def main():
|
80 |
-
st.title('๐ต Song Files')
|
81 |
-
with st.expander("Select Song File", expanded=True):
|
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([
|
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 |
|
@@ -102,13 +102,12 @@ def main():
|
|
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([
|
112 |
with icol1:
|
113 |
#st.markdown(f"* {song_info}")
|
114 |
|
@@ -122,16 +121,15 @@ def main():
|
|
122 |
with icol2:
|
123 |
|
124 |
if selected_file:
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
|
130 |
with col3:
|
131 |
-
|
132 |
-
# Now create the text area widget with the updated session state
|
133 |
-
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=600, key='chord_sheet', on_change=auto_save)
|
134 |
-
|
135 |
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
136 |
st.write(char_count_msg)
|
137 |
|
|
|
39 |
def load_song_file2(filename):
|
40 |
with open(filename, "r") as file:
|
41 |
chord_sheet = file.read()
|
42 |
+
st.session_state['chord_sheet'] = chord_sheet
|
43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
45 |
|
46 |
def load_song_file(filename):
|
47 |
with open(filename, "r") as file:
|
48 |
chord_sheet = file.read()
|
|
|
49 |
return chord_sheet
|
50 |
|
51 |
def song_update():
|
|
|
76 |
st.success(f"Auto-saved to {filename}")
|
77 |
|
78 |
def main():
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
col1, col2, col3 = st.columns([2, 3, 4])
|
81 |
|
82 |
with col1:
|
83 |
+
st.markdown('### ๐ต ChordSheet - Music Playing & Authoring')
|
84 |
+
with st.expander("Select Song:", expanded=True):
|
85 |
+
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
86 |
+
selected_file = st.selectbox("Choose: ", all_files, on_change=song_update, key='selected_file')
|
87 |
+
|
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 |
|
|
|
102 |
else:
|
103 |
st.error("Both Song Name and Artist Name are required.")
|
104 |
|
|
|
105 |
with col2:
|
106 |
|
107 |
st.header("๐ผ Available Songs")
|
108 |
for file in all_files:
|
109 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
110 |
+
icol1, icol2 = st.columns([1, 3])
|
111 |
with icol1:
|
112 |
#st.markdown(f"* {song_info}")
|
113 |
|
|
|
121 |
with icol2:
|
122 |
|
123 |
if selected_file:
|
124 |
+
table_md = f"""
|
125 |
+
| Wikipedia | YouTube | Chords | Lyrics |
|
126 |
+
| --------- | ------- | ------ | ------ |
|
127 |
+
| [๐]({create_search_url_wikipedia(song_info)}) | [๐ฅ]({create_search_url_youtube(song_info)}) | [๐ธ]({create_search_url_chords(song_info)}) | [๐ถ]({create_search_url_lyrics(song_info)}) |
|
128 |
+
"""
|
129 |
+
st.markdown(table_md)
|
130 |
|
131 |
with col3:
|
132 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=1200, key='chord_sheet', on_change=auto_save)
|
|
|
|
|
|
|
133 |
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
134 |
st.write(char_count_msg)
|
135 |
|