Spaces:
Sleeping
Sleeping
Update backupapp.py
Browse files- backupapp.py +54 -97
backupapp.py
CHANGED
@@ -1,115 +1,72 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import re
|
3 |
import os
|
4 |
import glob
|
|
|
|
|
5 |
st.set_page_config(layout="wide")
|
|
|
6 |
def process_line(line):
|
7 |
if re.search(r'\b[A-G][#b]?m?\b', line):
|
8 |
line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
|
9 |
return line
|
|
|
10 |
def process_chord_sheet(chord_sheet):
|
11 |
-
processed_lines = []
|
12 |
-
for line in chord_sheet.split('\n'):
|
13 |
-
processed_line = process_line(line)
|
14 |
-
processed_lines.append(processed_line)
|
15 |
return '<br>'.join(processed_lines)
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
def parse_filename(filename):
|
46 |
-
base_name = os.path.splitext(filename)[0]
|
47 |
-
song_name, artist_name = base_name.split(' by ')
|
48 |
-
return song_name.replace("_", " "), artist_name.replace("_", " ")
|
49 |
-
def auto_save():
|
50 |
-
song_name = st.session_state.get('song_name', '')
|
51 |
-
artist_name = st.session_state.get('artist_name', '')
|
52 |
-
chord_sheet = st.session_state.get('chord_sheet', '')
|
53 |
-
if song_name and artist_name and chord_sheet:
|
54 |
-
filename = song_name + " by " + artist_name + ".txt"
|
55 |
-
with open(filename, "w") as file:
|
56 |
-
chord_sheet_text = st.session_state.get('chord_sheet', '')
|
57 |
-
file.write(chord_sheet_text)
|
58 |
-
st.session_state['char_count'] = len(chord_sheet)
|
59 |
-
st.success(f"Auto-saved to {filename}")
|
60 |
def main():
|
61 |
col1, col3 = st.columns([3, 5])
|
|
|
62 |
with col1:
|
63 |
-
st.markdown('### π΅
|
64 |
with st.expander("Select Song:", expanded=True):
|
65 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
66 |
-
selected_file = st.selectbox("Choose: ", all_files,
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
st.
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
table_md = f"""
|
77 |
-
| Wikipedia | YouTube | Chords | Lyrics |
|
78 |
-
| --------- | ------- | ------ | ------ |
|
79 |
-
| [π]({create_search_url_wikipedia(song_info)}) | [π₯]({create_search_url_youtube(song_info)}) | [πΈ]({create_search_url_chords(song_info)}) | [πΆ]({create_search_url_lyrics(song_info)}) |
|
80 |
-
"""
|
81 |
-
st.markdown(table_md)
|
82 |
-
st.header("πΌ Available Songs")
|
83 |
-
for file in all_files:
|
84 |
-
song_info = os.path.splitext(file)[0].replace("_", " ")
|
85 |
-
icol1, icol2 = st.columns([1, 3])
|
86 |
-
with icol1:
|
87 |
-
st.markdown("**" + song_info + "**")
|
88 |
-
load_song_file(file)
|
89 |
-
song_info = os.path.splitext(file)[0].replace("_", " ")
|
90 |
-
with icol2:
|
91 |
-
# Create a markdown table with links for each song file
|
92 |
-
table_md = f"""
|
93 |
-
| Wikipedia | YouTube | Chords | Lyrics |
|
94 |
-
| --------- | ------- | ------ | ------ |
|
95 |
-
| [π]({create_search_url_wikipedia(song_info)}) | [π₯]({create_search_url_youtube(song_info)}) | [πΈ]({create_search_url_chords(song_info)}) | [πΆ]({create_search_url_lyrics(song_info)}) |
|
96 |
-
"""
|
97 |
-
st.markdown(table_md)
|
98 |
with col3:
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
filename = song_name_input + " by " + artist_name_input + ".txt"
|
106 |
-
with open(filename, "w") as file:
|
107 |
-
file.write(chord_sheet_area)
|
108 |
-
st.success("Chord sheet saved to file: " + filename)
|
109 |
-
else:
|
110 |
-
st.error("Both Song Name and Artist Name are required.")
|
111 |
-
# Load chord sheet from selected file into the text area
|
112 |
-
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
113 |
-
load_song_file(st.session_state.selected_file)
|
114 |
if __name__ == '__main__':
|
115 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
import re
|
4 |
import os
|
5 |
import glob
|
6 |
+
|
7 |
+
# Set Streamlit page configuration
|
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 load_song_file(file_path):
|
20 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
21 |
+
return file.read()
|
22 |
+
|
23 |
+
def display_chord_sheet_in_two_page_view(chord_sheet):
|
24 |
+
# CSS for multi-column layout
|
25 |
+
css_content = """
|
26 |
+
<style>
|
27 |
+
.multi-column {
|
28 |
+
column-count: 2;
|
29 |
+
column-gap: 1em;
|
30 |
+
column-rule: thin solid black;
|
31 |
+
overflow: auto;
|
32 |
+
white-space: pre-wrap;
|
33 |
+
font-size: small;
|
34 |
+
}
|
35 |
+
</style>
|
36 |
+
"""
|
37 |
+
|
38 |
+
# HTML structure with multi-column layout
|
39 |
+
html_content = f"""
|
40 |
+
{css_content}
|
41 |
+
<div class="multi-column">
|
42 |
+
{chord_sheet}
|
43 |
+
</div>
|
44 |
+
"""
|
45 |
+
components.html(html_content, height=1200)
|
46 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def main():
|
48 |
col1, col3 = st.columns([3, 5])
|
49 |
+
|
50 |
with col1:
|
51 |
+
st.markdown('### π΅ πPromptπ₯πΈChord SheetπΆ AI Prompt Authoring App')
|
52 |
with st.expander("Select Song:", expanded=True):
|
53 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
54 |
+
selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
|
55 |
+
|
56 |
+
if selected_file:
|
57 |
+
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
58 |
+
st.header("πΌ Current Song")
|
59 |
+
st.markdown("**" + song_info + "**")
|
60 |
+
chord_sheet = load_song_file(selected_file)
|
61 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
62 |
+
st.markdown(processed_sheet, unsafe_allow_html=True)
|
63 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
with col3:
|
65 |
+
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
66 |
+
# Display chord sheet in multi-column view
|
67 |
+
chord_sheet = load_song_file(st.session_state.selected_file)
|
68 |
+
processed_sheet = process_chord_sheet(chord_sheet)
|
69 |
+
display_chord_sheet_in_two_page_view(processed_sheet)
|
70 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
if __name__ == '__main__':
|
72 |
+
main()
|