Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,27 +41,42 @@ def optimize_gpu_settings():
|
|
| 41 |
if 'L40S' in torch.cuda.get_device_name(0):
|
| 42 |
torch.cuda.set_per_process_memory_fraction(0.95)
|
| 43 |
|
|
|
|
|
|
|
| 44 |
def analyze_lyrics(lyrics, repeat_chorus=2):
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
sections = {
|
| 48 |
'verse': 0,
|
| 49 |
'chorus': 0,
|
| 50 |
'bridge': 0,
|
| 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 |
|
|
@@ -86,17 +101,26 @@ def analyze_lyrics(lyrics, repeat_chorus=2):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
def calculate_generation_params(lyrics):
|
|
|
|
| 41 |
if 'L40S' in torch.cuda.get_device_name(0):
|
| 42 |
torch.cuda.set_per_process_memory_fraction(0.95)
|
| 43 |
|
| 44 |
+
import logging
|
| 45 |
+
|
| 46 |
def analyze_lyrics(lyrics, repeat_chorus=2):
|
| 47 |
+
# ๋จผ์ ๋ผ์ธ๋ณ๋ก ๋ถ๋ฆฌํ๊ณ , ๊ณต๋ฐฑ ์ค ์ ๊ฑฐ
|
| 48 |
+
lines = [line.strip() for line in lyrics.split('\n')]
|
| 49 |
+
lines = [line for line in lines if line]
|
| 50 |
|
| 51 |
+
# ๋ง์ฝ ์ ์ฒด๊ฐ ๋น์ด์๋ค๋ฉด ๊ฐ์ ๋ก '.' ํ ์ค ์ถ๊ฐ
|
| 52 |
+
if not lines:
|
| 53 |
+
lines = ['.']
|
| 54 |
+
else:
|
| 55 |
+
# ๋ง์ง๋ง ์ค์ด [verse], [chorus], [bridge] ํ๊ทธ๋ก๋ง ๋๋๋ฉด
|
| 56 |
+
# ์์๋ก '.' ํ ์ค์ ์ถ๊ฐํ์ฌ ์ค์ ๊ฐ์ฌ ๋ผ์ธ์ด ๋๋๋ก ์ฒ๋ฆฌ
|
| 57 |
+
last_line_lower = lines[-1].lower()
|
| 58 |
+
if last_line_lower in ['[verse]', '[chorus]', '[bridge]']:
|
| 59 |
+
lines.append('.')
|
| 60 |
+
|
| 61 |
+
# ๊ธฐ๋ณธ ์น์
์ ๋ณด
|
| 62 |
sections = {
|
| 63 |
'verse': 0,
|
| 64 |
'chorus': 0,
|
| 65 |
'bridge': 0,
|
| 66 |
'total_lines': len(lines)
|
| 67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
# ์น์
๋ผ์ธ๋ค์ ๋ด์ ๋์
๋๋ฆฌ
|
| 70 |
section_lines = {
|
| 71 |
'verse': [],
|
| 72 |
'chorus': [],
|
| 73 |
'bridge': []
|
| 74 |
}
|
| 75 |
|
| 76 |
+
current_section = None
|
| 77 |
+
last_section_start = 0
|
| 78 |
+
|
| 79 |
+
# [verse], [chorus], [bridge] ํ๊ทธ๊ฐ ๋์ค๋ฉด ์น์
์ ๊ตฌ๋ถํ์ฌ ๋ผ์ธ์ ์ ์ฅ
|
| 80 |
for i, line in enumerate(lines):
|
| 81 |
lower_line = line.lower()
|
| 82 |
|
|
|
|
| 101 |
sections['bridge'] += 1
|
| 102 |
last_section_start = i + 1
|
| 103 |
|
| 104 |
+
# ๋ง์ง๋ง ์น์
์ ๋จ์ ์๋ ๋ผ์ธ๋ค์ ์ถ๊ฐ
|
| 105 |
+
if current_section is not None and last_section_start < len(lines):
|
| 106 |
section_lines[current_section].extend(lines[last_section_start:])
|
| 107 |
|
| 108 |
+
# ์ฝ๋ฌ์ค ๋ฐ๋ณต ์ฒ๋ฆฌ
|
| 109 |
if sections['chorus'] > 0 and repeat_chorus > 1:
|
| 110 |
original_chorus = list(section_lines['chorus'])
|
| 111 |
for _ in range(repeat_chorus - 1):
|
| 112 |
section_lines['chorus'].extend(original_chorus)
|
| 113 |
|
| 114 |
+
# ์น์
๋ณ ๋ผ์ธ์ ๋ก๊น
|
| 115 |
+
logging.info(
|
| 116 |
+
f"Section line counts - Verse: {len(section_lines['verse'])}, "
|
| 117 |
+
f"Chorus: {len(section_lines['chorus'])}, "
|
| 118 |
+
f"Bridge: {len(section_lines['bridge'])}"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# ๋ฐํ: ์น์
์ ๋ณด, ์ ์ฒด ์น์
์, ์ ์ฒด ๋ผ์ธ ์, ๊ฐ ์น์
๋ณ ๋ผ์ธ ๋์
๋๋ฆฌ
|
| 122 |
+
return sections, (sections['verse'] + sections['chorus'] + sections['bridge']), len(lines), section_lines
|
| 123 |
+
|
| 124 |
|
| 125 |
|
| 126 |
def calculate_generation_params(lyrics):
|