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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -42
app.py CHANGED
@@ -3,59 +3,28 @@ 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
- import base64
11
-
12
  def get_image_base64(image_path):
13
  with open(image_path, "rb") as image_file:
14
  return base64.b64encode(image_file.read()).decode()
 
15
  def process_line(line):
16
- # Define a dictionary for chord-to-image mapping
17
  chord_images = {
18
  'Em': 'Em.png',
19
  'D': 'D.png',
20
  'C': 'C.png'
21
  }
22
-
23
- # Function to replace chord with base64 image
24
  def replace_chord(match):
25
  chord = match.group(0)
26
  image_base64 = get_image_base64(chord_images.get(chord, 'default.png'))
27
- return f"<img src='data:image/png;base64,{image_base64}' style='height:20px;'>"
28
-
29
- # Use regular expression to find and replace chords
30
- pattern = r'\b(' + '|'.join(re.escape(chord) for chord in chord_images.keys()) + r')\b'
31
- line = re.sub(pattern, replace_chord, line)
32
- return line
33
-
34
-
35
- def process_line_old2(line):
36
- # Define a dictionary for chord-to-image mapping
37
- chord_images = {
38
- 'Em': 'Em.png',
39
- 'D': 'D.png',
40
- 'C': 'C.png'
41
- }
42
-
43
- # Function to replace chord with image
44
- def replace_chord(match):
45
- chord = match.group(0)
46
- return f"<img src='{chord_images.get(chord, 'default.png')}' style='height:20px;'>"
47
-
48
- # Use regular expression to find and replace chords
49
  pattern = r'\b(' + '|'.join(re.escape(chord) for chord in chord_images.keys()) + r')\b'
50
  line = re.sub(pattern, replace_chord, line)
51
  return line
52
 
53
-
54
- def process_line_old(line):
55
- if re.search(r'\b[A-G][#b]?m?\b', line):
56
- line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\Em.png' style='height:20px;'>", line)
57
- return line
58
-
59
  def process_chord_sheet(chord_sheet):
60
  processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
61
  return '<br>'.join(processed_lines)
@@ -81,7 +50,6 @@ def create_search_url_lyrics(artist_song):
81
  return base_url + artist_song.replace(' ', '+').replace('โ€“', '%E2%80%93').replace('&', 'and') + '+lyrics'
82
 
83
  def display_chord_sheet_in_two_page_view(chord_sheet):
84
- # CSS for multi-column layout
85
  css_content = """
86
  <style>
87
  .multi-column {
@@ -94,8 +62,6 @@ def display_chord_sheet_in_two_page_view(chord_sheet):
94
  }
95
  </style>
96
  """
97
-
98
- # HTML structure with multi-column layout
99
  html_content = f"""
100
  {css_content}
101
  <div class="multi-column">
@@ -106,7 +72,6 @@ def display_chord_sheet_in_two_page_view(chord_sheet):
106
 
107
  def main():
108
  col1, col3 = st.columns([3, 5])
109
-
110
  with col1:
111
  st.markdown('### ๐ŸŽต ๐Ÿ“šPrompt๐ŸŽฅ๐ŸŽธChord Sheet๐ŸŽถ AI Prompt Authoring App')
112
  with st.expander("Select Song:", expanded=True):
@@ -125,7 +90,6 @@ def main():
125
  | [๐Ÿ“š]({create_search_url_wikipedia(song_info)}) | [๐ŸŽฅ]({create_search_url_youtube(song_info)}) | [๐ŸŽธ]({create_search_url_chords(song_info)}) | [๐ŸŽถ]({create_search_url_lyrics(song_info)}) |
126
  """
127
  st.markdown(table_md)
128
-
129
  st.header("๐ŸŽผ Available Songs")
130
  for file in all_files:
131
  song_info = os.path.splitext(file)[0].replace("_", " ")
@@ -139,13 +103,11 @@ def main():
139
  | [๐Ÿ“š]({create_search_url_wikipedia(song_info)}) | [๐ŸŽฅ]({create_search_url_youtube(song_info)}) | [๐ŸŽธ]({create_search_url_chords(song_info)}) | [๐ŸŽถ]({create_search_url_lyrics(song_info)}) |
140
  """
141
  st.markdown(table_md)
142
-
143
  with col3:
144
  if 'selected_file' in st.session_state and st.session_state.selected_file:
145
- # Display chord sheet in multi-column view
146
  chord_sheet = load_song_file(st.session_state.selected_file)
147
  processed_sheet = process_chord_sheet(chord_sheet)
148
  display_chord_sheet_in_two_page_view(processed_sheet)
149
 
150
  if __name__ == '__main__':
151
- 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):
29
  processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
30
  return '<br>'.join(processed_lines)
 
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):
 
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("_", " ")
 
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()