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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -18,7 +18,16 @@ def process_chord_sheet(chord_sheet):
18
 
19
  def split_text(text, split_ratio=0.5):
20
  lines = text.split('\n')
21
- split_point = int(len(lines) * split_ratio)
 
 
 
 
 
 
 
 
 
22
  return '\n'.join(lines[:split_point]), '\n'.join(lines[split_point:])
23
 
24
  def create_search_url(base_url, artist_song):
@@ -29,7 +38,7 @@ def load_song_file(file_path):
29
  return file.read()
30
 
31
  def display_chord_sheet_in_two_page_view(chord_sheet):
32
- # Splitting the text into two halves
33
  first_half, second_half = split_text(chord_sheet)
34
 
35
  # HTML structure for two-page view
 
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):
 
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