Spaces:
Sleeping
Sleeping
import streamlit as st | |
import re | |
# Function to process each line of the chord sheet | |
def process_line(line): | |
# Check if the line is a chord line (contains chord symbols) | |
if re.search(r'\b[A-G][#b]?m?\b', line): | |
# Replace chord symbols with image tags | |
line = re.sub(r'\b([A-G][#b]?m?)\b', r"<img src='\1.png' style='height:20px;'>", line) | |
return line | |
# Function to process the entire chord sheet | |
def process_chord_sheet(chord_sheet): | |
processed_lines = [] | |
for line in chord_sheet.split('\n'): | |
processed_line = process_line(line) | |
processed_lines.append(processed_line) | |
return '<br>'.join(processed_lines) | |
# Streamlit app | |
def main(): | |
st.title('Chord Sheet Processor') | |
# Text area for user to input the chord sheet | |
chord_sheet_input = st.text_area("Enter your chord sheet here:", height=300) | |
if st.button('Process Chord Sheet'): | |
if chord_sheet_input: | |
# Processing the chord sheet | |
processed_sheet = process_chord_sheet(chord_sheet_input) | |
# Displaying the processed chord sheet | |
st.markdown(processed_sheet, unsafe_allow_html=True) | |
else: | |
st.error("Please input a chord sheet to process.") | |
if __name__ == '__main__': | |
main() | |