Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,84 +8,58 @@ import glob
|
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
10 |
def process_line(line):
|
11 |
-
# Process each line to replace chords with images
|
12 |
if re.search(r'\b[A-G][#b]?m?\b', line):
|
13 |
line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
|
14 |
return line
|
15 |
|
16 |
def process_chord_sheet(chord_sheet):
|
17 |
-
# Process the entire chord sheet
|
18 |
processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
|
19 |
return '<br>'.join(processed_lines)
|
20 |
|
21 |
def create_search_url(base_url, artist_song):
|
22 |
-
# Create search URL with appropriate character replacements
|
23 |
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
|
24 |
|
25 |
def load_song_file(file_path):
|
26 |
-
# Load a song file and return its content
|
27 |
with open(file_path, 'r', encoding='utf-8') as file:
|
28 |
return file.read()
|
29 |
|
30 |
-
def
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def main():
|
37 |
col1, col3 = st.columns([3, 5])
|
38 |
|
39 |
with col1:
|
40 |
st.markdown('### 🎵 📚Prompt🎥🎸Chord Sheet🎶 AI Prompt Authoring App')
|
41 |
-
|
42 |
-
# Expander for selecting the song
|
43 |
with st.expander("Select Song:", expanded=True):
|
44 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
45 |
selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
|
46 |
-
|
47 |
-
# Input fields for song and artist names
|
48 |
-
song_name_input = st.text_input("🎵 Song:", key='song_name')
|
49 |
-
artist_name_input = st.text_input("🎤 Artist:", key='artist_name')
|
50 |
-
|
51 |
if selected_file:
|
52 |
-
# Display the current song
|
53 |
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
54 |
st.header("🎼 Current Song")
|
55 |
st.markdown("**" + song_info + "**")
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
# Markdown table with links
|
60 |
-
table_md = f"""
|
61 |
-
| Wikipedia | YouTube | Chords | Lyrics |
|
62 |
-
| --------- | ------- | ------ | ------ |
|
63 |
-
| [📚]({create_search_url("https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search=", song_info)}) | [🎥]({create_search_url("https://www.youtube.com/results?search_query=", song_info)}) | [🎸]({create_search_url("https://www.ultimate-guitar.com/search.php?search_type=title&value=", song_info)}) | [🎶]({create_search_url("https://www.google.com/search?q=", song_info + '+lyrics')}) |
|
64 |
-
"""
|
65 |
-
st.markdown(table_md)
|
66 |
-
|
67 |
-
st.header("🎼 Available Songs")
|
68 |
-
for file in all_files:
|
69 |
-
song_info = os.path.splitext(file)[0].replace("_", " ")
|
70 |
-
icol1, icol2 = st.columns([1, 3])
|
71 |
-
with icol1:
|
72 |
-
st.markdown("**" + song_info + "**")
|
73 |
-
processed_sheet = process_chord_sheet(load_song_file(file))
|
74 |
-
components.html(processed_sheet, height=150) # Displaying processed chord sheets
|
75 |
|
76 |
with col3:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
if song_name_input and artist_name_input:
|
83 |
-
filename = song_name_input + " by " + artist_name_input + ".txt"
|
84 |
-
with open(filename, "w") as file:
|
85 |
-
file.write(chord_sheet_area)
|
86 |
-
st.success("Chord sheet saved to file: " + filename)
|
87 |
-
else:
|
88 |
-
st.error("Both Song Name and Artist Name are required.")
|
89 |
|
90 |
if __name__ == '__main__':
|
91 |
main()
|
|
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
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 |
def process_chord_sheet(chord_sheet):
|
|
|
16 |
processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
|
17 |
return '<br>'.join(processed_lines)
|
18 |
|
19 |
def create_search_url(base_url, artist_song):
|
|
|
20 |
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
|
21 |
|
22 |
def load_song_file(file_path):
|
|
|
23 |
with open(file_path, 'r', encoding='utf-8') as file:
|
24 |
return file.read()
|
25 |
|
26 |
+
def display_chord_sheet_in_two_page_view(chord_sheet):
|
27 |
+
# HTML structure for two-page view
|
28 |
+
html_content = f"""
|
29 |
+
<div style="display: flex; justify-content: space-between;">
|
30 |
+
<div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
|
31 |
+
{chord_sheet}
|
32 |
+
</div>
|
33 |
+
<div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
|
34 |
+
{chord_sheet}
|
35 |
+
</div>
|
36 |
+
</div>
|
37 |
+
"""
|
38 |
+
components.html(html_content, height=600)
|
39 |
|
40 |
def main():
|
41 |
col1, col3 = st.columns([3, 5])
|
42 |
|
43 |
with col1:
|
44 |
st.markdown('### 🎵 📚Prompt🎥🎸Chord Sheet🎶 AI Prompt Authoring App')
|
|
|
|
|
45 |
with st.expander("Select Song:", expanded=True):
|
46 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
47 |
selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
|
48 |
+
|
|
|
|
|
|
|
|
|
49 |
if selected_file:
|
|
|
50 |
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
51 |
st.header("🎼 Current Song")
|
52 |
st.markdown("**" + song_info + "**")
|
53 |
+
chord_sheet = load_song_file(selected_file)
|
54 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
55 |
+
st.markdown(processed_sheet, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
with col3:
|
58 |
+
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
59 |
+
# Display chord sheet in two-page view
|
60 |
+
chord_sheet = load_song_file(st.session_state.selected_file)
|
61 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
62 |
+
display_chord_sheet_in_two_page_view(processed_sheet)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
if __name__ == '__main__':
|
65 |
main()
|