awacke1 commited on
Commit
bcf03d0
β€’
1 Parent(s): e333a11

Update backupapp.py

Browse files
Files changed (1) hide show
  1. 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
- 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("_", " ")
75
- st.markdown("**" + song_info + "**")
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
- 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()
 
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()