ginipick commited on
Commit
0eff675
ยท
verified ยท
1 Parent(s): 4326638

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -51,58 +51,53 @@ def analyze_lyrics(lyrics, repeat_chorus=2):
51
  'total_lines': len(lines)
52
  }
53
 
 
54
  current_section = None
 
 
55
  section_lines = {
56
  'verse': [],
57
  'chorus': [],
58
  'bridge': []
59
  }
60
- last_section = None
61
-
62
- for i, line in enumerate(lines):
63
- if '[verse]' in line.lower() or '[chorus]' in line.lower() or '[bridge]' in line.lower():
64
- last_section = i
65
 
 
66
  for i, line in enumerate(lines):
67
  lower_line = line.lower()
68
-
69
  if '[verse]' in lower_line:
70
- if current_section:
71
  section_lines[current_section].extend(lines[last_section_start:i])
72
  current_section = 'verse'
73
  sections['verse'] += 1
74
  last_section_start = i + 1
75
- continue
76
  elif '[chorus]' in lower_line:
77
- if current_section:
78
  section_lines[current_section].extend(lines[last_section_start:i])
79
  current_section = 'chorus'
80
  sections['chorus'] += 1
81
  last_section_start = i + 1
82
- continue
83
  elif '[bridge]' in lower_line:
84
- if current_section:
85
  section_lines[current_section].extend(lines[last_section_start:i])
86
  current_section = 'bridge'
87
  sections['bridge'] += 1
88
  last_section_start = i + 1
89
- continue
90
 
91
- if current_section and 'last_section_start' in locals() and last_section_start < len(lines):
 
92
  section_lines[current_section].extend(lines[last_section_start:])
93
 
 
94
  if sections['chorus'] > 0 and repeat_chorus > 1:
95
- original_chorus = section_lines['chorus'][:]
96
  for _ in range(repeat_chorus - 1):
97
  section_lines['chorus'].extend(original_chorus)
98
 
99
- logging.info(
100
- f"Section line counts - Verse: {len(section_lines['verse'])}, "
101
- f"Chorus: {len(section_lines['chorus'])}, "
102
- f"Bridge: {len(section_lines['bridge'])}"
103
- )
104
 
105
- return sections, (sections['verse'] + sections['chorus'] + sections['bridge']), len(lines), section_lines
106
 
107
  def calculate_generation_params(lyrics):
108
  sections, total_sections, total_lines, section_lines = analyze_lyrics(lyrics)
 
51
  'total_lines': len(lines)
52
  }
53
 
54
+ # ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
55
  current_section = None
56
+ last_section_start = 0
57
+
58
  section_lines = {
59
  'verse': [],
60
  'chorus': [],
61
  'bridge': []
62
  }
 
 
 
 
 
63
 
64
+ # ๋ฃจํ”„๋ฅผ ๋Œ๋ฉฐ ํƒœ๊ทธ๊ฐ€ ๋“ฑ์žฅํ•˜๋ฉด ํ•ด๋‹น ํƒœ๊ทธ ์ „๊นŒ์ง€์˜ ๋ผ์ธ์„ ์ด์ „ ์„น์…˜์— ์ €์žฅ
65
  for i, line in enumerate(lines):
66
  lower_line = line.lower()
67
+
68
  if '[verse]' in lower_line:
69
+ if current_section is not None:
70
  section_lines[current_section].extend(lines[last_section_start:i])
71
  current_section = 'verse'
72
  sections['verse'] += 1
73
  last_section_start = i + 1
74
+
75
  elif '[chorus]' in lower_line:
76
+ if current_section is not None:
77
  section_lines[current_section].extend(lines[last_section_start:i])
78
  current_section = 'chorus'
79
  sections['chorus'] += 1
80
  last_section_start = i + 1
81
+
82
  elif '[bridge]' in lower_line:
83
+ if current_section is not None:
84
  section_lines[current_section].extend(lines[last_section_start:i])
85
  current_section = 'bridge'
86
  sections['bridge'] += 1
87
  last_section_start = i + 1
 
88
 
89
+ # ๋งˆ์ง€๋ง‰ ๋‚จ์€ ๋ผ์ธ๋“ค์„ ํ˜„์žฌ ์„น์…˜์— ์ถ”๊ฐ€
90
+ if current_section is not None:
91
  section_lines[current_section].extend(lines[last_section_start:])
92
 
93
+ # ์ฝ”๋Ÿฌ์Šค ๋ฐ˜๋ณต ๋“ฑ ์ถ”๊ฐ€ ์ฒ˜๋ฆฌ
94
  if sections['chorus'] > 0 and repeat_chorus > 1:
95
+ original_chorus = list(section_lines['chorus'])
96
  for _ in range(repeat_chorus - 1):
97
  section_lines['chorus'].extend(original_chorus)
98
 
99
+ return sections, sum(sections[sec] for sec in ('verse','chorus','bridge')), len(lines), section_lines
 
 
 
 
100
 
 
101
 
102
  def calculate_generation_params(lyrics):
103
  sections, total_sections, total_lines, section_lines = analyze_lyrics(lyrics)