awacke1 commited on
Commit
e333a11
β€’
1 Parent(s): 8d1b559

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -29
app.py CHANGED
@@ -16,43 +16,33 @@ def process_chord_sheet(chord_sheet):
16
  processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
17
  return '<br>'.join(processed_lines)
18
 
19
- def split_text(text, split_ratio=0.5):
20
- lines = text.split('\n')
21
- total_chars = len(text)
22
- cumulative_chars = 0
23
- split_point = 0
24
-
25
- for i, line in enumerate(lines):
26
- cumulative_chars += len(line) + 1 # Adding 1 for the newline character
27
- if cumulative_chars >= total_chars * split_ratio:
28
- split_point = i
29
- break
30
-
31
- return '\n'.join(lines[:split_point]), '\n'.join(lines[split_point:])
32
-
33
- def create_search_url(base_url, artist_song):
34
- return base_url + artist_song.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
35
-
36
  def load_song_file(file_path):
37
  with open(file_path, 'r', encoding='utf-8') as file:
38
  return file.read()
39
 
40
  def display_chord_sheet_in_two_page_view(chord_sheet):
41
- # Splitting the text for more balanced two-page view
42
- first_half, second_half = split_text(chord_sheet)
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- # HTML structure for two-page view
45
  html_content = f"""
46
- <div style="display: flex; justify-content: space-between;">
47
- <div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
48
- {first_half}
49
- </div>
50
- <div style="width: 49%; overflow: scroll; white-space: pre-wrap; font-size: small;">
51
- {second_half}
52
- </div>
53
  </div>
54
  """
55
- components.html(html_content, height=1200) # Increased height
56
 
57
  def main():
58
  col1, col3 = st.columns([3, 5])
@@ -73,7 +63,7 @@ def main():
73
 
74
  with col3:
75
  if 'selected_file' in st.session_state and st.session_state.selected_file:
76
- # Display chord sheet in two-page view
77
  chord_sheet = load_song_file(st.session_state.selected_file)
78
  processed_sheet = process_chord_sheet(chord_sheet)
79
  display_chord_sheet_in_two_page_view(processed_sheet)
 
16
  processed_lines = [process_line(line) for line in chord_sheet.split('\n')]
17
  return '<br>'.join(processed_lines)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def load_song_file(file_path):
20
  with open(file_path, 'r', encoding='utf-8') as file:
21
  return file.read()
22
 
23
  def display_chord_sheet_in_two_page_view(chord_sheet):
24
+ # CSS for multi-column layout
25
+ css_content = """
26
+ <style>
27
+ .multi-column {
28
+ column-count: 2;
29
+ column-gap: 1em;
30
+ column-rule: thin solid black;
31
+ overflow: auto;
32
+ white-space: pre-wrap;
33
+ font-size: small;
34
+ }
35
+ </style>
36
+ """
37
 
38
+ # HTML structure with multi-column layout
39
  html_content = f"""
40
+ {css_content}
41
+ <div class="multi-column">
42
+ {chord_sheet}
 
 
 
 
43
  </div>
44
  """
45
+ components.html(html_content, height=1200)
46
 
47
  def main():
48
  col1, col3 = st.columns([3, 5])
 
63
 
64
  with col3:
65
  if 'selected_file' in st.session_state and st.session_state.selected_file:
66
+ # Display chord sheet in multi-column view
67
  chord_sheet = load_song_file(st.session_state.selected_file)
68
  processed_sheet = process_chord_sheet(chord_sheet)
69
  display_chord_sheet_in_two_page_view(processed_sheet)