Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import re
|
3 |
import os
|
4 |
import glob
|
|
|
5 |
st.set_page_config(layout="wide")
|
6 |
def process_line(line):
|
7 |
if re.search(r'\b[A-G][#b]?m?\b', line):
|
@@ -33,10 +35,14 @@ def load_song_file2(filename):
|
|
33 |
st.session_state['chord_sheet'] = chord_sheet
|
34 |
processed_sheet = process_chord_sheet(chord_sheet)
|
35 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
36 |
-
def load_song_file(filename):
|
37 |
-
with open(filename, "r") as file:
|
|
|
|
|
|
|
|
|
38 |
chord_sheet = file.read()
|
39 |
-
|
40 |
def song_update():
|
41 |
if 'selected_file' in st.session_state:
|
42 |
song_name, artist_name = parse_filename(st.session_state.selected_file)
|
@@ -57,6 +63,8 @@ def auto_save():
|
|
57 |
file.write(chord_sheet_text)
|
58 |
st.session_state['char_count'] = len(chord_sheet)
|
59 |
st.success(f"Auto-saved to {filename}")
|
|
|
|
|
60 |
def main():
|
61 |
col1, col3 = st.columns([3, 5])
|
62 |
with col1:
|
@@ -96,18 +104,22 @@ def main():
|
|
96 |
"""
|
97 |
st.markdown(table_md)
|
98 |
with col3:
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
if
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
111 |
# Load chord sheet from selected file into the text area
|
112 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
113 |
load_song_file(st.session_state.selected_file)
|
|
|
1 |
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
import re
|
4 |
import os
|
5 |
import glob
|
6 |
+
|
7 |
st.set_page_config(layout="wide")
|
8 |
def process_line(line):
|
9 |
if re.search(r'\b[A-G][#b]?m?\b', line):
|
|
|
35 |
st.session_state['chord_sheet'] = chord_sheet
|
36 |
processed_sheet = process_chord_sheet(chord_sheet)
|
37 |
st.markdown(processed_sheet, unsafe_allow_html=True)
|
38 |
+
#def load_song_file(filename):
|
39 |
+
# with open(filename, "r") as file:
|
40 |
+
# chord_sheet = file.read()
|
41 |
+
# return chord_sheet
|
42 |
+
def load_song_file(file_path):
|
43 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
44 |
chord_sheet = file.read()
|
45 |
+
return chord_sheet
|
46 |
def song_update():
|
47 |
if 'selected_file' in st.session_state:
|
48 |
song_name, artist_name = parse_filename(st.session_state.selected_file)
|
|
|
63 |
file.write(chord_sheet_text)
|
64 |
st.session_state['char_count'] = len(chord_sheet)
|
65 |
st.success(f"Auto-saved to {filename}")
|
66 |
+
|
67 |
+
|
68 |
def main():
|
69 |
col1, col3 = st.columns([3, 5])
|
70 |
with col1:
|
|
|
104 |
"""
|
105 |
st.markdown(table_md)
|
106 |
with col3:
|
107 |
+
subcol1, subcol2 = st.columns([1, 5])
|
108 |
+
with subcol2:
|
109 |
+
chord_sheet_area = st.text_area("Chord Sheet", value=st.session_state.get('chord_sheet', ''), height=1600, key='chord_sheet', on_change=auto_save)
|
110 |
+
with subcol1:
|
111 |
+
# Save functionality
|
112 |
+
if st.button("💾 Save", key="save_song"):
|
113 |
+
if song_name_input and artist_name_input:
|
114 |
+
filename = song_name_input + " by " + artist_name_input + ".txt"
|
115 |
+
with open(filename, "w") as file:
|
116 |
+
file.write(chord_sheet_area)
|
117 |
+
st.success("Chord sheet saved to file: " + filename)
|
118 |
+
else:
|
119 |
+
st.error("Both Song Name and Artist Name are required.")
|
120 |
+
char_count_msg = f"Character Count: {st.session_state.get('char_count', 0)}"
|
121 |
+
st.write(char_count_msg)
|
122 |
+
|
123 |
# Load chord sheet from selected file into the text area
|
124 |
if 'selected_file' in st.session_state and st.session_state.selected_file:
|
125 |
load_song_file(st.session_state.selected_file)
|