awacke1 commited on
Commit
a830900
1 Parent(s): fbfdf9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -36
app.py CHANGED
@@ -1,12 +1,14 @@
1
  import streamlit as st
2
  import re
3
  import os
 
 
 
 
4
 
5
  # Function to process each line of the chord sheet
6
  def process_line(line):
7
- # Check if the line is a chord line (contains chord symbols)
8
  if re.search(r'\b[A-G][#b]?m?\b', line):
9
- # Replace chord symbols with image tags
10
  line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
11
  return line
12
 
@@ -37,45 +39,63 @@ def create_search_url_lyrics(artist_song):
37
 
38
  # Streamlit app
39
  def main():
40
- st.title('Chord Sheet Processor')
41
-
42
- # Song name and artist input
43
- song_name_artist = st.text_input("Song Name by Music Artist", value="Hold On, Hold On by Neko Case")
 
 
44
 
45
- # File operations
46
- filename = song_name_artist.replace(", ", "_").replace(" ", "_").lower() + ".txt"
47
- if st.button('Open Chord Sheet'):
48
- if os.path.exists(filename):
49
- with open(filename, "r") as file:
50
- chord_sheet = file.read()
51
- st.text_area("Chord Sheet", chord_sheet, height=300)
52
- processed_sheet = process_chord_sheet(chord_sheet)
53
- st.markdown(processed_sheet, unsafe_allow_html=True)
54
- else:
55
- st.error("File not found.")
56
 
57
- # Text area for user to input the chord sheet
58
- chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300)
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- if st.button('Save Chord Sheet'):
61
- with open(filename, "w") as file:
62
- file.write(chord_sheet_input)
63
- st.success("Chord sheet saved.")
 
 
 
 
 
64
 
65
- if st.button('Process Chord Sheet'):
66
- if chord_sheet_input:
67
- # Processing the chord sheet
68
- processed_sheet = process_chord_sheet(chord_sheet_input)
69
- # Displaying the processed chord sheet
70
- st.markdown(processed_sheet, unsafe_allow_html=True)
71
- else:
72
- st.error("Please input a chord sheet to process.")
 
 
 
 
 
 
 
73
 
74
- # Displaying links
75
- st.markdown(f"[📚Wikipedia]({create_search_url_wikipedia(song_name_artist)})")
76
- st.markdown(f"[🎥YouTube]({create_search_url_youtube(song_name_artist)})")
77
- st.markdown(f"[🎸Chords]({create_search_url_chords(song_name_artist)})")
78
- st.markdown(f"[🎶Lyrics]({create_search_url_lyrics(song_name_artist)})")
 
 
79
 
80
  if __name__ == '__main__':
81
  main()
 
1
  import streamlit as st
2
  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
 
 
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()