awacke1 commited on
Commit
da6b368
1 Parent(s): 49acd1b

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +29 -32
backupapp.py CHANGED
@@ -39,21 +39,27 @@ def songupdate():
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,31 +69,27 @@ def main():
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
 
@@ -103,23 +105,18 @@ def main():
103
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
104
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
105
 
106
- with col2:
107
  if selected_file:
108
  load_song_file(selected_file)
109
  song_info = os.path.splitext(selected_file)[0].replace("_", " ")
 
 
 
110
  st.markdown(f"**Selected Song:** {song_info}")
111
  st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
112
  st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
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()
 
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
+ # 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):
64
  all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
65
  selected_file = st.selectbox("Choose a file", all_files)
 
69
  artist_name = artist_name.replace("_", " ")
70
  else:
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"):
88
+ if song_name_input and artist_name_input:
89
+ filename = f"{song_name_input} by {artist_name_input}.txt".replace(" ", "_")
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
 
 
105
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
106
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
107
 
 
108
  if selected_file:
109
  load_song_file(selected_file)
110
  song_info = os.path.splitext(selected_file)[0].replace("_", " ")
111
+
112
+ with col2:
113
+ if selected_file:
114
  st.markdown(f"**Selected Song:** {song_info}")
115
  st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
116
  st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
117
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
118
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
119
 
120
+
 
 
 
 
 
 
 
121
  if __name__ == '__main__':
122
  main()