awacke1 commited on
Commit
53e4086
โ€ข
1 Parent(s): a8eba6e

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +59 -18
backupapp.py CHANGED
@@ -3,13 +3,26 @@ 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):
@@ -20,8 +33,23 @@ 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 {
@@ -34,8 +62,6 @@ def display_chord_sheet_in_two_page_view(chord_sheet):
34
  }
35
  </style>
36
  """
37
-
38
- # HTML structure with multi-column layout
39
  html_content = f"""
40
  {css_content}
41
  <div class="multi-column">
@@ -46,27 +72,42 @@ def display_chord_sheet_in_two_page_view(chord_sheet):
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()
 
3
  import re
4
  import os
5
  import glob
6
+ import base64
7
 
 
8
  st.set_page_config(layout="wide")
9
 
10
+ def get_image_base64(image_path):
11
+ with open(image_path, "rb") as image_file:
12
+ return base64.b64encode(image_file.read()).decode()
13
+
14
  def process_line(line):
15
+ chord_images = {
16
+ 'Em': 'Em.png',
17
+ 'D': 'D.png',
18
+ 'C': 'C.png'
19
+ }
20
+ def replace_chord(match):
21
+ chord = match.group(0)
22
+ image_base64 = get_image_base64(chord_images.get(chord, 'default.png'))
23
+ return f"<strong>{chord}</strong><img src='data:image/png;base64,{image_base64}' style='height:20px;'>"
24
+ pattern = r'\b(' + '|'.join(re.escape(chord) for chord in chord_images.keys()) + r')\b'
25
+ line = re.sub(pattern, replace_chord, line)
26
  return line
27
 
28
  def process_chord_sheet(chord_sheet):
 
33
  with open(file_path, 'r', encoding='utf-8') as file:
34
  return file.read()
35
 
36
+ def create_search_url_wikipedia(artist_song):
37
+ base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
38
+ return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')
39
+
40
+ def create_search_url_youtube(artist_song):
41
+ base_url = "https://www.youtube.com/results?search_query="
42
+ return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')
43
+
44
+ def create_search_url_chords(artist_song):
45
+ base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
46
+ return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and')
47
+
48
+ def create_search_url_lyrics(artist_song):
49
+ base_url = "https://www.google.com/search?q="
50
+ return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and') + '+lyrics'
51
+
52
  def display_chord_sheet_in_two_page_view(chord_sheet):
 
53
  css_content = """
54
  <style>
55
  .multi-column {
 
62
  }
63
  </style>
64
  """
 
 
65
  html_content = f"""
66
  {css_content}
67
  <div class="multi-column">
 
72
 
73
  def main():
74
  col1, col3 = st.columns([3, 5])
 
75
  with col1:
76
  st.markdown('### ๐ŸŽต ๐Ÿ“šPrompt๐ŸŽฅ๐ŸŽธChord Sheet๐ŸŽถ AI Prompt Authoring App')
77
  with st.expander("Select Song:", expanded=True):
78
  all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
79
  selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
80
+ if selected_file:
81
+ song_info = os.path.splitext(selected_file)[0].replace("_", " ")
82
+ st.header("๐ŸŽผ Current Song")
83
+ st.markdown("**" + song_info + "**")
84
+ chord_sheet = load_song_file(selected_file)
85
+ processed_sheet = process_chord_sheet(chord_sheet)
86
+ #st.markdown(processed_sheet, unsafe_allow_html=True)
87
+ table_md = f"""
88
+ | Wikipedia | YouTube | Chords | Lyrics |
89
+ | --------- | ------- | ------ | ------ |
90
+ | [๐Ÿ“š]({create_search_url_wikipedia(song_info)}) | [๐ŸŽฅ]({create_search_url_youtube(song_info)}) | [๐ŸŽธ]({create_search_url_chords(song_info)}) | [๐ŸŽถ]({create_search_url_lyrics(song_info)}) |
91
+ """
92
+ st.markdown(table_md)
93
+ st.header("๐ŸŽผ Available Songs")
94
+ for file in all_files:
95
+ song_info = os.path.splitext(file)[0].replace("_", " ")
96
+ icol1, icol2 = st.columns([1, 3])
97
+ with icol1:
98
+ st.markdown("**" + song_info + "**")
99
+ with icol2:
100
+ table_md = f"""
101
+ | Wikipedia | YouTube | Chords | Lyrics |
102
+ | --------- | ------- | ------ | ------ |
103
+ | [๐Ÿ“š]({create_search_url_wikipedia(song_info)}) | [๐ŸŽฅ]({create_search_url_youtube(song_info)}) | [๐ŸŽธ]({create_search_url_chords(song_info)}) | [๐ŸŽถ]({create_search_url_lyrics(song_info)}) |
104
+ """
105
+ st.markdown(table_md)
106
  with col3:
107
  if 'selected_file' in st.session_state and st.session_state.selected_file:
 
108
  chord_sheet = load_song_file(st.session_state.selected_file)
109
  processed_sheet = process_chord_sheet(chord_sheet)
110
  display_chord_sheet_in_two_page_view(processed_sheet)
111
 
112
  if __name__ == '__main__':
113
+ main()