Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,37 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
from zipfile import ZipFile
|
4 |
-
import os
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
for i, img in enumerate(image_tags):
|
25 |
-
img_url = img['src'] # Assuming 'src' contains the image URL
|
26 |
-
img_data = requests.get(img_url).content
|
27 |
-
img_filename = f'chord_images/image_{i}.jpg'
|
28 |
-
with open(img_filename, 'wb') as f:
|
29 |
-
f.write(img_data)
|
30 |
-
zipf.write(img_filename)
|
31 |
-
|
32 |
-
print("Images saved and zipped.")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import re
|
|
|
|
|
3 |
|
4 |
+
# Function to process each line of the chord sheet
|
5 |
+
def process_line(line):
|
6 |
+
# Check if the line is a chord line (contains chord symbols)
|
7 |
+
if re.search(r'\b[A-G][#b]?m?\b', line):
|
8 |
+
# Replace chord symbols with image tags
|
9 |
+
line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line)
|
10 |
+
return line
|
11 |
|
12 |
+
# Function to process the entire chord sheet
|
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 |
+
# Streamlit app
|
21 |
+
def main():
|
22 |
+
st.title('Chord Sheet Processor')
|
23 |
|
24 |
+
# Text area for user to input the chord sheet
|
25 |
+
chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300)
|
26 |
|
27 |
+
if st.button('Process Chord Sheet'):
|
28 |
+
if chord_sheet_input:
|
29 |
+
# Processing the chord sheet
|
30 |
+
processed_sheet = process_chord_sheet(chord_sheet_input)
|
31 |
+
# Displaying the processed chord sheet
|
32 |
+
st.markdown(processed_sheet, unsafe_allow_html=True)
|
33 |
+
else:
|
34 |
+
st.error("Please input a chord sheet to process.")
|
35 |
|
36 |
+
if __name__ == '__main__':
|
37 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|