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

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +54 -53
backupapp.py CHANGED
@@ -3,16 +3,13 @@ import re
3
  import os
4
  import glob
5
 
6
- # Set Streamlit page configuration to wide mode
7
  st.set_page_config(layout="wide")
8
 
9
- # Function to process each line of the chord sheet
10
  def process_line(line):
11
  if re.search(r'\b[A-G][#b]?m?\b', line):
12
  line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
13
  return line
14
 
15
- # Function to process the entire chord sheet
16
  def process_chord_sheet(chord_sheet):
17
  processed_lines = []
18
  for line in chord_sheet.split('\n'):
@@ -20,7 +17,6 @@ def process_chord_sheet(chord_sheet):
20
  processed_lines.append(processed_line)
21
  return '<br>'.join(processed_lines)
22
 
23
- # Functions to create search URLs
24
  def create_search_url_wikipedia(artist_song):
25
  base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
26
  return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
@@ -37,65 +33,70 @@ def create_search_url_lyrics(artist_song):
37
  base_url = "https://www.google.com/search?q="
38
  return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') + '+lyrics'
39
 
40
- # Streamlit app
41
- def main():
42
- # Sidebar with file loader
43
- with st.sidebar:
44
- st.title('🎵 Song Files')
45
- with st.expander("Select Song File"):
46
- all_files = glob.glob("*.txt")
47
- selected_file = st.selectbox("Choose a file", all_files)
48
 
49
- # Main area layout
50
- col1, col2 = st.columns([2, 1])
 
 
 
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  with col1:
53
- with st.expander("🎶 Song and Artist"):
54
- song_name = st.text_input("🎵 Song Name")
55
- artist_name = st.text_input("🎤 Artist Name")
56
- chord_sheet_input = st.text_area("Chord Sheet", height=300)
57
- if st.button("💾 Save", key="save_song"):
58
- if song_name and artist_name:
59
- filename = f"{song_name} by {artist_name}.txt".replace(" ", "_")
60
- with open(filename, "w") as file:
61
- file.write(chord_sheet_input)
62
- st.success("Chord sheet saved.")
63
- else:
64
- st.error("Both Song Name and Artist Name are required.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  with col2:
67
  if selected_file:
68
- song_name_artist = os.path.splitext(selected_file)[0].replace("_", " ")
69
- st.markdown(f"**Selected Song:** {song_name_artist}")
70
- st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_name_artist)})")
71
- st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_name_artist)})")
72
- st.markdown(f"[🎸Chords]({create_search_url_chords(song_name_artist)})")
73
- st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_name_artist)})")
74
  load_song_file(selected_file)
75
-
76
- # Displaying song files
77
- st.header("🎼 Available Songs")
78
- for file in all_files:
79
- song_info = os.path.splitext(file)[0].replace("_", " ")
80
- col1, col2, col3, col4, col5 = st.columns([4, 1, 1, 1, 1])
81
- with col1:
82
- st.markdown(f"* {song_info}")
83
- with col2:
84
  st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
85
- with col3:
86
  st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
87
- with col4:
88
  st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
89
- with col5:
90
  st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
91
 
92
- # Function to load and display the selected song file
93
- def load_song_file(filename):
94
- with open(filename, "r") as file:
95
- chord_sheet = file.read()
96
- st.text_area("Chord Sheet", chord_sheet, height=300)
97
- processed_sheet = process_chord_sheet(chord_sheet)
98
- st.markdown(processed_sheet, unsafe_allow_html=True)
99
-
100
  if __name__ == '__main__':
101
- main()
 
3
  import os
4
  import glob
5
 
 
6
  st.set_page_config(layout="wide")
7
 
 
8
  def process_line(line):
9
  if re.search(r'\b[A-G][#b]?m?\b', line):
10
  line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
11
  return line
12
 
 
13
  def process_chord_sheet(chord_sheet):
14
  processed_lines = []
15
  for line in chord_sheet.split('\n'):
 
17
  processed_lines.append(processed_line)
18
  return '<br>'.join(processed_lines)
19
 
 
20
  def create_search_url_wikipedia(artist_song):
21
  base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
22
  return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
 
33
  base_url = "https://www.google.com/search?q="
34
  return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') + '+lyrics'
35
 
36
+ def songupdate():
37
+ st.write(st.session_state.EnhancedChordSheet)
 
 
 
 
 
 
38
 
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)
51
+ if selected_file:
52
+ song_name, artist_name = os.path.splitext(selected_file)[0].split(' by ')
53
+ song_name = song_name.replace("_", " ")
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
+
79
+ st.header("🎼 Available Songs")
80
+ for file in all_files:
81
+ song_info = os.path.splitext(file)[0].replace("_", " ")
82
+ icol1, icol2 = st.columns([4, 1])
83
+ with icol1:
84
+ st.markdown(f"* {song_info}")
85
+ with icol2:
86
+ st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
87
+ st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
88
+ st.markdown(f"[🎸Chords]({create_search_url_chords(song_info)})")
89
+ st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_info)})")
90
 
91
  with col2:
92
  if selected_file:
 
 
 
 
 
 
93
  load_song_file(selected_file)
94
+ song_info = os.path.splitext(selected_file)[0].replace("_", " ")
95
+ st.markdown(f"**Selected Song:** {song_info}")
 
 
 
 
 
 
 
96
  st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_info)})")
 
97
  st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_info)})")
 
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()