awacke1 commited on
Commit
be19b0b
1 Parent(s): df0c374

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +31 -8
backupapp.py CHANGED
@@ -39,12 +39,21 @@ def songupdate():
39
  def load_song_file(filename):
40
  with open(filename, "r") as file:
41
  chord_sheet = file.read()
42
- st.text_area(label="Enhanced Chord Sheet", value=chord_sheet, height=300, key="EnhancedChordSheet", help="This text can be read due to alternating chord lines and lyric lines.", label_visibility="visible", on_change=songupdate )
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):
49
  all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
50
  selected_file = st.selectbox("Choose a file", all_files)
@@ -54,25 +63,31 @@ def main():
54
  artist_name = artist_name.replace("_", " ")
55
  else:
56
  song_name, artist_name = "", ""
 
57
  col1, col2 = st.columns([4, 1])
58
  with col1:
59
- song_name_input = st.text_input("🎵 Song Name", value=song_name)
60
- artist_name_input = st.text_input("🎤 Artist Name", value=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
- chord_sheet_area = st.text_area("Chord Sheet", value=chord_sheet_input, height=300)
68
 
69
  # Save functionality
70
  if st.button("💾 Save", key="save_song"):
71
- if song_name_input and artist_name_input:
72
- filename = f"{song_name_input} by {artist_name_input}.txt".replace(" ", "_")
73
  with open(filename, "w") as file:
74
  file.write(chord_sheet_area)
75
  st.success("Chord sheet saved.")
 
 
 
 
76
  else:
77
  st.error("Both Song Name and Artist Name are required.")
78
 
@@ -98,5 +113,13 @@ def main():
98
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
99
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
100
 
 
 
 
 
 
 
 
 
101
  if __name__ == '__main__':
102
  main()
 
39
  def load_song_file(filename):
40
  with open(filename, "r") as file:
41
  chord_sheet = file.read()
42
+
43
+ st.text_area(label="Enhanced Chord Sheet", value=chord_sheet, height=300, key="EnhancedChordSheet", help="This text can be read due to alternating chord lines and lyric lines.", label_visibility="visible", on_change=songupdate )
44
+ processed_sheet = process_chord_sheet(chord_sheet)
45
+ st.markdown(processed_sheet, unsafe_allow_html=True)
46
+
47
+ st.session_state['selected_file'] = filename
48
+ st.session_state['chord_sheet'] = chord_sheet
49
+ st.session_state['song_name'], st.session_state['artist_name'] = os.path.splitext(filename)[0].split(' by ')
50
+
51
+ def update_display():
52
+ st.session_state['display_sheet'] = process_chord_sheet(st.session_state['chord_sheet'])
53
 
54
  def main():
55
  st.title('🎵 Song Files')
56
+
57
  with st.expander("Select Song File", expanded=True):
58
  all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
59
  selected_file = st.selectbox("Choose a file", all_files)
 
63
  artist_name = artist_name.replace("_", " ")
64
  else:
65
  song_name, artist_name = "", ""
66
+
67
  col1, col2 = st.columns([4, 1])
68
  with col1:
69
+ song_name = st.text_input("🎵 Song Name", value=st.session_state.get('song_name', ''))
70
+ artist_name = st.text_input("🎤 Artist Name", value=st.session_state.get('artist_name', ''))
71
+ chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=300, on_change=update_display)
72
 
73
  # Load chord sheet from selected file into the text area
74
  chord_sheet_input = ""
75
  if selected_file:
76
  with open(selected_file, "r") as file:
77
  chord_sheet_input = file.read()
78
+ #chord_sheet_area = st.text_area("Chord Sheet", value=chord_sheet_input, height=300)
79
 
80
  # Save functionality
81
  if st.button("💾 Save", key="save_song"):
82
+ if song_name and artist_name:
83
+ filename = f"{song_name} by {artist_name}.txt".replace(" ", "_")
84
  with open(filename, "w") as file:
85
  file.write(chord_sheet_area)
86
  st.success("Chord sheet saved.")
87
+ # Refresh the file list and selected file
88
+ st.session_state['selected_file'] = filename
89
+ st.session_state['chord_sheet'] = chord_sheet_area
90
+ update_display()
91
  else:
92
  st.error("Both Song Name and Artist Name are required.")
93
 
 
113
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
114
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
115
 
116
+ # Initialize session state variables if not already set
117
+ if 'display_sheet' not in st.session_state:
118
+ st.session_state['display_sheet'] = ''
119
+ st.session_state['chord_sheet'] = ''
120
+ st.session_state['selected_file'] = ''
121
+ st.session_state['song_name'] = ''
122
+ st.session_state['artist_name'] = ''
123
+
124
  if __name__ == '__main__':
125
  main()