Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
| 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 |
-
|
| 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 |
-
|
|
|
|
| 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 |
-
|
| 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)
|