Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,11 @@ import glob
|
|
7 |
# Set Streamlit page configuration
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
def process_line(line):
|
11 |
# Define a dictionary for chord-to-image mapping
|
12 |
chord_images = {
|
@@ -15,6 +20,26 @@ def process_line(line):
|
|
15 |
'C': 'C.png'
|
16 |
}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Function to replace chord with image
|
19 |
def replace_chord(match):
|
20 |
chord = match.group(0)
|
|
|
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 = {
|
|
|
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)
|