Update app.py
Browse files
app.py
CHANGED
@@ -43,6 +43,21 @@ def load_song_file(filename):
|
|
43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def main():
|
47 |
st.title('🎵 Song Files')
|
48 |
with st.expander("Select Song File", expanded=True):
|
@@ -56,15 +71,17 @@ def main():
|
|
56 |
song_name, artist_name = "", ""
|
57 |
col1, col2 = st.columns([4, 1])
|
58 |
with col1:
|
59 |
-
song_name_input = st.text_input("🎵 Song Name",
|
60 |
-
artist_name_input = st.text_input("🎤 Artist Name",
|
61 |
|
62 |
# Load chord sheet from selected file into the text area
|
63 |
-
chord_sheet_input = ""
|
64 |
if selected_file:
|
65 |
with open(selected_file, "r") as file:
|
66 |
chord_sheet_input = file.read()
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
# Save functionality
|
70 |
if st.button("💾 Save", key="save_song"):
|
|
|
43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
45 |
|
46 |
+
# Automatic save function
|
47 |
+
def auto_save():
|
48 |
+
song_name = st.session_state['song_name']
|
49 |
+
artist_name = st.session_state['artist_name']
|
50 |
+
chord_sheet = st.session_state['chord_sheet']
|
51 |
+
|
52 |
+
# Display the character count
|
53 |
+
st.sidebar.write("Character Count:", len(chord_sheet))
|
54 |
+
|
55 |
+
if song_name and artist_name:
|
56 |
+
filename = f"{song_name} by {artist_name}.txt".replace(" ", "_")
|
57 |
+
with open(filename, "w") as file:
|
58 |
+
file.write(chord_sheet)
|
59 |
+
st.sidebar.success("Chord sheet auto-saved.")
|
60 |
+
|
61 |
def main():
|
62 |
st.title('🎵 Song Files')
|
63 |
with st.expander("Select Song File", expanded=True):
|
|
|
71 |
song_name, artist_name = "", ""
|
72 |
col1, col2 = st.columns([4, 1])
|
73 |
with col1:
|
74 |
+
song_name_input = st.text_input("🎵 Song Name", key='song_name')
|
75 |
+
artist_name_input = st.text_input("🎤 Artist Name", key='artist_name')
|
76 |
|
77 |
# Load chord sheet from selected file into the text area
|
|
|
78 |
if selected_file:
|
79 |
with open(selected_file, "r") as file:
|
80 |
chord_sheet_input = file.read()
|
81 |
+
st.session_state['chord_sheet'] = chord_sheet_input
|
82 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=chord_sheet_input, height=300, key='chord_sheet', on_change=auto_save)
|
83 |
+
else:
|
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"):
|