File size: 2,436 Bytes
a1de66d
ce879dc
a1de66d
fbfdf9e
a830900
29a1d82
 
a830900
29a1d82
a1de66d
 
 
 
29a1d82
a1de66d
29a1d82
a1de66d
29a1d82
 
fbfdf9e
29a1d82
ce879dc
 
29a1d82
 
e12508c
 
 
 
 
 
 
 
 
 
 
 
 
29a1d82
a1de66d
092fa31
29a1d82
4da4ce9
5583fd4
feffd36
 
29a1d82
e12508c
29a1d82
 
 
 
e12508c
 
 
29a1d82
7692c5b
e12508c
 
 
 
 
29a1d82
6f681ea
29a1d82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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"<img src='\1.png' style='height:20px;'>", line)
    return line

def process_chord_sheet(chord_sheet):
    processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
    return '<br>'.join(processed_lines)

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):
    # HTML structure for two-page view
    html_content = f"""
    <div style="display: flex; justify-content: space-between;">
        <div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
            {chord_sheet}
        </div>
        <div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
            {chord_sheet}
        </div>
    </div>
    """
    components.html(html_content, height=600)

def main():
    col1, col3 = st.columns([3, 5])

    with col1:
        st.markdown('### 🎵 📚Prompt🎥🎸Chord Sheet🎶 AI Prompt Authoring App')
        with st.expander("Select Song:", expanded=True):
            all_files = [f for f in glob.glob("*.txt") if ' by ' in f]
            selected_file = st.selectbox("Choose: ", all_files, key='selected_file')
        
        if selected_file:
            song_info = os.path.splitext(selected_file)[0].replace("_", " ")
            st.header("🎼 Current Song")
            st.markdown("**" + song_info + "**")
            chord_sheet = load_song_file(selected_file)
            processed_sheet = process_chord_sheet(chord_sheet)
            st.markdown(processed_sheet, unsafe_allow_html=True)

    with col3:
        if 'selected_file' in st.session_state and st.session_state.selected_file:
            # Display chord sheet in two-page view
            chord_sheet = load_song_file(st.session_state.selected_file)
            processed_sheet = process_chord_sheet(chord_sheet)
            display_chord_sheet_in_two_page_view(processed_sheet)

if __name__ == '__main__':
    main()