Update backupapp.py
Browse files- backupapp.py +80 -55
backupapp.py
CHANGED
@@ -36,86 +36,111 @@ def create_search_url_lyrics(artist_song):
|
|
36 |
def songupdate():
|
37 |
st.write(st.session_state.EnhancedChordSheet)
|
38 |
|
39 |
-
def
|
40 |
with open(filename, "r") as file:
|
41 |
chord_sheet = file.read()
|
42 |
-
st.
|
43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
chord_sheet = st.session_state['chord_sheet']
|
51 |
|
52 |
-
|
53 |
-
st.
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
with open(filename, "w") as file:
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
def main():
|
62 |
-
st.
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
if selected_file:
|
67 |
-
song_name, artist_name = os.path.splitext(selected_file)[0].split(' by ')
|
68 |
-
song_name = song_name.replace("_", " ")
|
69 |
-
artist_name = artist_name.replace("_", " ")
|
70 |
-
else:
|
71 |
-
song_name, artist_name = "", ""
|
72 |
-
col1, col2 = st.columns([4, 1])
|
73 |
with col1:
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
chord_sheet_area = st.text_area("Chord Sheet", height=300, key='chord_sheet', on_change=auto_save)
|
85 |
|
86 |
# Save functionality
|
87 |
if st.button("💾 Save", key="save_song"):
|
88 |
if song_name_input and artist_name_input:
|
89 |
-
filename =
|
90 |
with open(filename, "w") as file:
|
91 |
file.write(chord_sheet_area)
|
92 |
-
st.success("Chord sheet saved
|
93 |
else:
|
94 |
st.error("Both Song Name and Artist Name are required.")
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
st.header("🎼 Available Songs")
|
97 |
for file in all_files:
|
98 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
99 |
-
icol1, icol2 = st.columns([
|
100 |
with icol1:
|
101 |
-
st.markdown(
|
|
|
|
|
102 |
with icol2:
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
119 |
|
120 |
|
121 |
if __name__ == '__main__':
|
|
|
36 |
def songupdate():
|
37 |
st.write(st.session_state.EnhancedChordSheet)
|
38 |
|
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():
|
52 |
+
if 'selected_file' in st.session_state:
|
53 |
+
song_name, artist_name = parse_filename(st.session_state.selected_file)
|
54 |
+
st.session_state.song_name = song_name
|
55 |
+
st.session_state.artist_name = artist_name
|
56 |
|
57 |
+
def parse_filename(filename):
|
58 |
+
base_name = os.path.splitext(filename)[0]
|
59 |
+
song_name, artist_name = base_name.split(' by ')
|
60 |
+
return song_name.replace("_", " "), artist_name.replace("_", " ")
|
61 |
+
|
62 |
+
def auto_save():
|
63 |
+
song_name = st.session_state.get('song_name', '')
|
64 |
+
artist_name = st.session_state.get('artist_name', '')
|
65 |
+
chord_sheet = st.session_state.get('chord_sheet', '')
|
66 |
+
|
67 |
+
if song_name and artist_name and chord_sheet:
|
68 |
+
filename = song_name + " by " + artist_name + ".txt"
|
69 |
with open(filename, "w") as file:
|
70 |
+
|
71 |
+
|
72 |
+
chord_sheet_text = st.session_state.get('chord_sheet', '')
|
73 |
+
file.write(chord_sheet_text)
|
74 |
+
|
75 |
+
st.session_state['char_count'] = len(chord_sheet)
|
76 |
+
st.success(f"Auto-saved to {filename}")
|
77 |
|
78 |
def main():
|
79 |
+
st.markdown('### 🎵 ChordSheet - Music Playing and Authoring App')
|
80 |
+
|
81 |
+
col1, col3 = st.columns([3, 5])
|
82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
with col1:
|
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 |
+
|
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:
|
98 |
+
filename = song_name_input + " by " + artist_name_input + ".txt"
|
99 |
with open(filename, "w") as file:
|
100 |
file.write(chord_sheet_area)
|
101 |
+
st.success("Chord sheet saved to file: " + filename)
|
102 |
else:
|
103 |
st.error("Both Song Name and Artist Name are required.")
|
104 |
|
105 |
+
st.header("🎼 Current Song")
|
106 |
+
load_song_file(selected_file)
|
107 |
+
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
108 |
+
st.markdown("**" + song_info + "**")
|
109 |
+
table_md = f"""
|
110 |
+
| Wikipedia | YouTube | Chords | Lyrics |
|
111 |
+
| --------- | ------- | ------ | ------ |
|
112 |
+
| [📚]({create_search_url_wikipedia(song_info)}) | [🎥]({create_search_url_youtube(song_info)}) | [🎸]({create_search_url_chords(song_info)}) | [🎶]({create_search_url_lyrics(song_info)}) |
|
113 |
+
"""
|
114 |
+
st.markdown(table_md)
|
115 |
+
|
116 |
+
|
117 |
st.header("🎼 Available Songs")
|
118 |
for file in all_files:
|
119 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
120 |
+
icol1, icol2 = st.columns([1, 3])
|
121 |
with icol1:
|
122 |
+
st.markdown("**" + song_info + "**")
|
123 |
+
load_song_file(file)
|
124 |
+
song_info = os.path.splitext(file)[0].replace("_", " ")
|
125 |
with icol2:
|
126 |
+
# Create a markdown table with links for each song file
|
127 |
+
table_md = f"""
|
128 |
+
| Wikipedia | YouTube | Chords | Lyrics |
|
129 |
+
| --------- | ------- | ------ | ------ |
|
130 |
+
| [📚]({create_search_url_wikipedia(song_info)}) | [🎥]({create_search_url_youtube(song_info)}) | [🎸]({create_search_url_chords(song_info)}) | [🎶]({create_search_url_lyrics(song_info)}) |
|
131 |
+
"""
|
132 |
+
st.markdown(table_md)
|
133 |
+
|
134 |
+
with col3:
|
135 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=1200, key='chord_sheet', on_change=auto_save)
|
136 |
+
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
137 |
+
st.write(char_count_msg)
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
# Load chord sheet from selected file into the text area
|
142 |
+
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
143 |
+
load_song_file(st.session_state.selected_file)
|
144 |
|
145 |
|
146 |
if __name__ == '__main__':
|