Spaces:
Sleeping
Sleeping
Update backupapp.py
Browse files- backupapp.py +11 -43
backupapp.py
CHANGED
|
@@ -2,106 +2,73 @@ import streamlit as st
|
|
| 2 |
import re
|
| 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'):
|
| 16 |
processed_line = process_line(line)
|
| 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')
|
| 23 |
-
|
| 24 |
def create_search_url_youtube(artist_song):
|
| 25 |
base_url = "https://www.youtube.com/results?search_query="
|
| 26 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and')
|
| 27 |
-
|
| 28 |
def create_search_url_chords(artist_song):
|
| 29 |
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
|
| 30 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and')
|
| 31 |
-
|
| 32 |
def create_search_url_lyrics(artist_song):
|
| 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_file2(filename):
|
| 40 |
with open(filename, "r") as file:
|
| 41 |
chord_sheet = file.read()
|
| 42 |
st.session_state['chord_sheet'] = chord_sheet
|
| 43 |
processed_sheet = process_chord_sheet(chord_sheet)
|
| 44 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
| 45 |
-
|
| 46 |
def load_song_file(filename):
|
| 47 |
with open(filename, "r") as file:
|
| 48 |
chord_sheet = file.read()
|
| 49 |
return chord_sheet
|
| 50 |
-
|
| 51 |
def song_update():
|
| 52 |
if 'selected_file' in st.session_state:
|
| 53 |
song_name, artist_name = parse_filename(st.session_state.selected_file)
|
| 54 |
st.session_state.song_name = song_name
|
| 55 |
st.session_state.artist_name = artist_name
|
| 56 |
-
|
| 57 |
def parse_filename(filename):
|
| 58 |
base_name = os.path.splitext(filename)[0]
|
| 59 |
song_name, artist_name = base_name.split(' by ')
|
| 60 |
return song_name.replace("_", " "), artist_name.replace("_", " ")
|
| 61 |
-
|
| 62 |
def auto_save():
|
| 63 |
song_name = st.session_state.get('song_name', '')
|
| 64 |
artist_name = st.session_state.get('artist_name', '')
|
| 65 |
chord_sheet = st.session_state.get('chord_sheet', '')
|
| 66 |
-
|
| 67 |
if song_name and artist_name and chord_sheet:
|
| 68 |
filename = song_name + " by " + artist_name + ".txt"
|
| 69 |
with open(filename, "w") as file:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
chord_sheet_text = st.session_state.get('chord_sheet', '')
|
| 73 |
file.write(chord_sheet_text)
|
| 74 |
-
|
| 75 |
st.session_state['char_count'] = len(chord_sheet)
|
| 76 |
st.success(f"Auto-saved to {filename}")
|
| 77 |
-
|
| 78 |
def main():
|
| 79 |
-
st.markdown('### ๐ต ChordSheet - Music Playing and Authoring App')
|
| 80 |
-
|
| 81 |
col1, col3 = st.columns([3, 5])
|
| 82 |
-
|
| 83 |
with col1:
|
|
|
|
| 84 |
with st.expander("Select Song:", expanded=True):
|
| 85 |
all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
|
| 86 |
selected_file = st.selectbox("Choose: ", all_files, on_change=song_update, key='selected_file')
|
| 87 |
-
|
| 88 |
song_name_input = st.text_input("๐ต Song:", key='song_name', on_change=auto_save)
|
| 89 |
artist_name_input = st.text_input("๐ค Artist:", key='artist_name', on_change=auto_save)
|
| 90 |
-
|
| 91 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
| 92 |
# Update the session state before creating the text area widget
|
| 93 |
st.session_state['chord_sheet'] = load_song_file(st.session_state.selected_file)
|
| 94 |
-
|
| 95 |
-
# Save functionality
|
| 96 |
-
if st.button("๐พ Save", key="save_song"):
|
| 97 |
-
if song_name_input and artist_name_input:
|
| 98 |
-
filename = song_name_input + " by " + artist_name_input + ".txt"
|
| 99 |
-
with open(filename, "w") as file:
|
| 100 |
-
file.write(chord_sheet_area)
|
| 101 |
-
st.success("Chord sheet saved to file: " + filename)
|
| 102 |
-
else:
|
| 103 |
-
st.error("Both Song Name and Artist Name are required.")
|
| 104 |
-
|
| 105 |
st.header("๐ผ Current Song")
|
| 106 |
load_song_file(selected_file)
|
| 107 |
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
|
@@ -112,8 +79,6 @@ def main():
|
|
| 112 |
| [๐]({create_search_url_wikipedia(song_info)}) | [๐ฅ]({create_search_url_youtube(song_info)}) | [๐ธ]({create_search_url_chords(song_info)}) | [๐ถ]({create_search_url_lyrics(song_info)}) |
|
| 113 |
"""
|
| 114 |
st.markdown(table_md)
|
| 115 |
-
|
| 116 |
-
|
| 117 |
st.header("๐ผ Available Songs")
|
| 118 |
for file in all_files:
|
| 119 |
song_info = os.path.splitext(file)[0].replace("_", " ")
|
|
@@ -130,18 +95,21 @@ def main():
|
|
| 130 |
| [๐]({create_search_url_wikipedia(song_info)}) | [๐ฅ]({create_search_url_youtube(song_info)}) | [๐ธ]({create_search_url_chords(song_info)}) | [๐ถ]({create_search_url_lyrics(song_info)}) |
|
| 131 |
"""
|
| 132 |
st.markdown(table_md)
|
| 133 |
-
|
| 134 |
with col3:
|
| 135 |
-
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=
|
| 136 |
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
| 137 |
st.write(char_count_msg)
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Load chord sheet from selected file into the text area
|
| 142 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
| 143 |
load_song_file(st.session_state.selected_file)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
if __name__ == '__main__':
|
| 147 |
main()
|
|
|
|
| 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 |
def create_search_url_wikipedia(artist_song):
|
| 17 |
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
|
| 18 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and')
|
|
|
|
| 19 |
def create_search_url_youtube(artist_song):
|
| 20 |
base_url = "https://www.youtube.com/results?search_query="
|
| 21 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and')
|
|
|
|
| 22 |
def create_search_url_chords(artist_song):
|
| 23 |
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
|
| 24 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and')
|
|
|
|
| 25 |
def create_search_url_lyrics(artist_song):
|
| 26 |
base_url = "https://www.google.com/search?q="
|
| 27 |
return base_url + artist_song.replace(' ', '+').replace('โ', '%E2%80%93').replace('&', 'and') + '+lyrics'
|
|
|
|
| 28 |
def songupdate():
|
| 29 |
st.write(st.session_state.EnhancedChordSheet)
|
|
|
|
| 30 |
def load_song_file2(filename):
|
| 31 |
with open(filename, "r") as file:
|
| 32 |
chord_sheet = file.read()
|
| 33 |
st.session_state['chord_sheet'] = chord_sheet
|
| 34 |
processed_sheet = process_chord_sheet(chord_sheet)
|
| 35 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
|
|
|
| 36 |
def load_song_file(filename):
|
| 37 |
with open(filename, "r") as file:
|
| 38 |
chord_sheet = file.read()
|
| 39 |
return chord_sheet
|
|
|
|
| 40 |
def song_update():
|
| 41 |
if 'selected_file' in st.session_state:
|
| 42 |
song_name, artist_name = parse_filename(st.session_state.selected_file)
|
| 43 |
st.session_state.song_name = song_name
|
| 44 |
st.session_state.artist_name = artist_name
|
|
|
|
| 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('### ๐ต ChordSheet - Music Playing and Authoring App')
|
| 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, on_change=song_update, key='selected_file')
|
|
|
|
| 67 |
song_name_input = st.text_input("๐ต Song:", key='song_name', on_change=auto_save)
|
| 68 |
artist_name_input = st.text_input("๐ค Artist:", key='artist_name', on_change=auto_save)
|
|
|
|
| 69 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
| 70 |
# Update the session state before creating the text area widget
|
| 71 |
st.session_state['chord_sheet'] = load_song_file(st.session_state.selected_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
st.header("๐ผ Current Song")
|
| 73 |
load_song_file(selected_file)
|
| 74 |
song_info = os.path.splitext(selected_file)[0].replace("_", " ")
|
|
|
|
| 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("_", " ")
|
|
|
|
| 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 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=1600, key='chord_sheet', on_change=auto_save)
|
| 100 |
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
| 101 |
st.write(char_count_msg)
|
| 102 |
+
# Save functionality
|
| 103 |
+
if st.button("๐พ Save", key="save_song"):
|
| 104 |
+
if song_name_input and artist_name_input:
|
| 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()
|