import streamlit as st
import streamlit.components.v1 as components
import re
import os
import glob
# Set Streamlit page configuration
st.set_page_config(layout="wide")
def process_line(line):
if re.search(r'\b[A-G][#b]?m?\b', line):
line = re.sub(r'\b([A-G][#b]?m?)\b', r"", line)
return line
def process_chord_sheet(chord_sheet):
processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
return '
'.join(processed_lines)
def split_text(text, split_ratio=0.5):
lines = text.split('\n')
total_chars = len(text)
cumulative_chars = 0
split_point = 0
for i, line in enumerate(lines):
cumulative_chars += len(line) + 1 # Adding 1 for the newline character
if cumulative_chars >= total_chars * split_ratio:
split_point = i
break
return '\n'.join(lines[:split_point]), '\n'.join(lines[split_point:])
def create_search_url(base_url, artist_song):
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
def load_song_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
def display_chord_sheet_in_two_page_view(chord_sheet):
# Splitting the text for more balanced two-page view
first_half, second_half = split_text(chord_sheet)
# HTML structure for two-page view
html_content = f"""