import streamlit as st
import streamlit.components.v1 as components
import re
import os
import glob
import base64
st.set_page_config(layout="wide")
def get_image_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode()
def process_line(line):
chord_images = {
'Em': 'Em.png',
'D': 'D.png',
'C': 'C.png'
}
def replace_chord(match):
chord = match.group(0)
image_base64 = get_image_base64(chord_images.get(chord, 'default.png'))
return f"{chord}"
pattern = r'\b(' + '|'.join(re.escape(chord) for chord in chord_images.keys()) + r')\b'
line = re.sub(pattern, replace_chord, 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 load_song_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()
def create_search_url_wikipedia(artist_song):
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
def create_search_url_youtube(artist_song):
base_url = "https://www.youtube.com/results?search_query="
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
def create_search_url_chords(artist_song):
base_url = "https://www.ultimate-guitar.com/search.php?search_type=title&value="
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
def create_search_url_lyrics(artist_song):
base_url = "https://www.google.com/search?q="
return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and') + '+lyrics'
def display_chord_sheet_in_two_page_view(chord_sheet):
css_content = """
"""
html_content = f"""
{css_content}