Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -61,64 +61,91 @@ def analyze_lyrics(lyrics, repeat_chorus=2):
|
|
61 |
'chorus': [],
|
62 |
'bridge': []
|
63 |
}
|
|
|
64 |
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
lower_line = line.lower()
|
|
|
|
|
67 |
if '[verse]' in lower_line:
|
|
|
|
|
68 |
current_section = 'verse'
|
69 |
sections['verse'] += 1
|
|
|
70 |
continue
|
71 |
elif '[chorus]' in lower_line:
|
|
|
|
|
72 |
current_section = 'chorus'
|
73 |
sections['chorus'] += 1
|
|
|
74 |
continue
|
75 |
elif '[bridge]' in lower_line:
|
|
|
|
|
76 |
current_section = 'bridge'
|
77 |
sections['bridge'] += 1
|
|
|
78 |
continue
|
79 |
|
80 |
-
|
81 |
-
|
|
|
82 |
|
83 |
-
|
84 |
-
|
|
|
85 |
for _ in range(repeat_chorus - 1):
|
86 |
-
section_lines['chorus'].extend(
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
91 |
|
92 |
def calculate_generation_params(lyrics):
|
93 |
sections, total_sections, total_lines, section_lines = analyze_lyrics(lyrics)
|
94 |
|
|
|
95 |
time_per_line = {
|
96 |
-
'verse': 4,
|
97 |
-
'chorus': 6,
|
98 |
-
'bridge': 5
|
99 |
}
|
100 |
|
|
|
101 |
section_durations = {}
|
102 |
for section_type in ['verse', 'chorus', 'bridge']:
|
103 |
-
|
104 |
-
|
105 |
-
else:
|
106 |
-
section_durations[section_type] = section_lines[section_type] * time_per_line[section_type]
|
107 |
|
|
|
108 |
total_duration = sum(duration for duration in section_durations.values())
|
109 |
-
total_duration = max(60, total_duration)
|
110 |
|
|
|
111 |
base_tokens = 3000
|
112 |
tokens_per_line = 200
|
|
|
113 |
|
114 |
-
total_tokens = base_tokens + (total_lines * tokens_per_line)
|
115 |
|
|
|
116 |
if sections['chorus'] > 0:
|
117 |
-
num_segments =
|
118 |
else:
|
119 |
-
num_segments =
|
120 |
|
121 |
-
|
|
|
122 |
|
123 |
return {
|
124 |
'max_tokens': max_tokens,
|
@@ -255,14 +282,17 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
255 |
|
256 |
has_chorus = params['sections']['chorus'] > 0
|
257 |
estimated_duration = params.get('estimated_duration', 90)
|
258 |
-
|
|
|
259 |
# ์ธ๊ทธ๋จผํธ ๋ฐ ํ ํฐ ์ ์ค์
|
260 |
if has_chorus:
|
261 |
-
actual_max_tokens = min(
|
262 |
-
actual_num_segments = min(
|
263 |
else:
|
264 |
-
actual_max_tokens = config['max_tokens']
|
265 |
-
actual_num_segments = params['num_segments']
|
|
|
|
|
266 |
|
267 |
logging.info(f"Estimated duration: {estimated_duration} seconds")
|
268 |
logging.info(f"Has chorus sections: {has_chorus}")
|
|
|
61 |
'chorus': [],
|
62 |
'bridge': []
|
63 |
}
|
64 |
+
last_section = None
|
65 |
|
66 |
+
# ๋ง์ง๋ง ์น์
ํ๊ทธ ์ฐพ๊ธฐ
|
67 |
+
for i, line in enumerate(lines):
|
68 |
+
if '[verse]' in line.lower() or '[chorus]' in line.lower() or '[bridge]' in line.lower():
|
69 |
+
last_section = i
|
70 |
+
|
71 |
+
for i, line in enumerate(lines):
|
72 |
lower_line = line.lower()
|
73 |
+
|
74 |
+
# ์น์
ํ๊ทธ ์ฒ๋ฆฌ
|
75 |
if '[verse]' in lower_line:
|
76 |
+
if current_section: # ์ด์ ์น์
์ ๋ผ์ธ๋ค ์ ์ฅ
|
77 |
+
section_lines[current_section].extend(lines[last_section_start:i])
|
78 |
current_section = 'verse'
|
79 |
sections['verse'] += 1
|
80 |
+
last_section_start = i + 1
|
81 |
continue
|
82 |
elif '[chorus]' in lower_line:
|
83 |
+
if current_section:
|
84 |
+
section_lines[current_section].extend(lines[last_section_start:i])
|
85 |
current_section = 'chorus'
|
86 |
sections['chorus'] += 1
|
87 |
+
last_section_start = i + 1
|
88 |
continue
|
89 |
elif '[bridge]' in lower_line:
|
90 |
+
if current_section:
|
91 |
+
section_lines[current_section].extend(lines[last_section_start:i])
|
92 |
current_section = 'bridge'
|
93 |
sections['bridge'] += 1
|
94 |
+
last_section_start = i + 1
|
95 |
continue
|
96 |
|
97 |
+
# ๋ง์ง๋ง ์น์
์ ๋ผ์ธ๋ค ์ถ๊ฐ
|
98 |
+
if current_section and last_section_start < len(lines):
|
99 |
+
section_lines[current_section].extend(lines[last_section_start:])
|
100 |
|
101 |
+
# ์ฝ๋ฌ์ค ๋ฐ๋ณต ์ฒ๋ฆฌ
|
102 |
+
if sections['chorus'] > 0 and repeat_chorus > 1:
|
103 |
+
original_chorus = section_lines['chorus'][:]
|
104 |
for _ in range(repeat_chorus - 1):
|
105 |
+
section_lines['chorus'].extend(original_chorus)
|
106 |
+
|
107 |
+
# ์น์
๋ณ ๋ผ์ธ ์ ํ์ธ ๋ก๊น
|
108 |
+
logging.info(f"Section line counts - Verse: {len(section_lines['verse'])}, "
|
109 |
+
f"Chorus: {len(section_lines['chorus'])}, "
|
110 |
+
f"Bridge: {len(section_lines['bridge'])}")
|
111 |
+
|
112 |
+
return sections, (sections['verse'] + sections['chorus'] + sections['bridge']), len(lines), section_lines
|
113 |
|
114 |
def calculate_generation_params(lyrics):
|
115 |
sections, total_sections, total_lines, section_lines = analyze_lyrics(lyrics)
|
116 |
|
117 |
+
# ๊ธฐ๋ณธ ์๊ฐ ๊ณ์ฐ (์ด ๋จ์)
|
118 |
time_per_line = {
|
119 |
+
'verse': 4, # verse๋ ํ ์ค๋น 4์ด
|
120 |
+
'chorus': 6, # chorus๋ ํ ์ค๋น 6์ด
|
121 |
+
'bridge': 5 # bridge๋ ํ ์ค๋น 5์ด
|
122 |
}
|
123 |
|
124 |
+
# ๊ฐ ์น์
๋ณ ์์ ์๊ฐ ๊ณ์ฐ (๋ง์ง๋ง ์น์
ํฌํจ)
|
125 |
section_durations = {}
|
126 |
for section_type in ['verse', 'chorus', 'bridge']:
|
127 |
+
lines_count = len(section_lines[section_type])
|
128 |
+
section_durations[section_type] = lines_count * time_per_line[section_type]
|
|
|
|
|
129 |
|
130 |
+
# ์ ์ฒด ์๊ฐ ๊ณ์ฐ (์ฌ์ ์๊ฐ ์ถ๊ฐ)
|
131 |
total_duration = sum(duration for duration in section_durations.values())
|
132 |
+
total_duration = max(60, int(total_duration * 1.2)) # 20% ์ฌ์ ์๊ฐ ์ถ๊ฐ
|
133 |
|
134 |
+
# ํ ํฐ ๊ณ์ฐ (๋ง์ง๋ง ์น์
์ ์ํ ์ถ๊ฐ ํ ํฐ)
|
135 |
base_tokens = 3000
|
136 |
tokens_per_line = 200
|
137 |
+
extra_tokens = 1000 # ๋ง์ง๋ง ์น์
์ ์ํ ์ถ๊ฐ ํ ํฐ
|
138 |
|
139 |
+
total_tokens = base_tokens + (total_lines * tokens_per_line) + extra_tokens
|
140 |
|
141 |
+
# ์ธ๊ทธ๋จผํธ ์ ๊ณ์ฐ (๋ง์ง๋ง ์น์
์ ์ํ ์ถ๊ฐ ์ธ๊ทธ๋จผํธ)
|
142 |
if sections['chorus'] > 0:
|
143 |
+
num_segments = 4 # ์ฝ๋ฌ์ค๊ฐ ์๋ ๊ฒฝ์ฐ 4๊ฐ ์ธ๊ทธ๋จผํธ
|
144 |
else:
|
145 |
+
num_segments = 3 # ์ฝ๋ฌ์ค๊ฐ ์๋ ๊ฒฝ์ฐ 3๊ฐ ์ธ๊ทธ๋จผํธ
|
146 |
|
147 |
+
# ํ ํฐ ์ ์ ํ (๋ ํฐ ์ ํ)
|
148 |
+
max_tokens = min(12000, total_tokens) # ์ต๋ ํ ํฐ ์ ์ฆ๊ฐ
|
149 |
|
150 |
return {
|
151 |
'max_tokens': max_tokens,
|
|
|
282 |
|
283 |
has_chorus = params['sections']['chorus'] > 0
|
284 |
estimated_duration = params.get('estimated_duration', 90)
|
285 |
+
|
286 |
+
|
287 |
# ์ธ๊ทธ๋จผํธ ๋ฐ ํ ํฐ ์ ์ค์
|
288 |
if has_chorus:
|
289 |
+
actual_max_tokens = min(12000, int(config['max_tokens'] * 1.3)) # 30% ๋ ๋ง์ ํ ํฐ
|
290 |
+
actual_num_segments = min(5, params['num_segments'] + 2) # ์ถ๊ฐ ์ธ๊ทธ๋จผํธ
|
291 |
else:
|
292 |
+
actual_max_tokens = min(10000, int(config['max_tokens'] * 1.2))
|
293 |
+
actual_num_segments = min(4, params['num_segments'] + 1)
|
294 |
+
|
295 |
+
|
296 |
|
297 |
logging.info(f"Estimated duration: {estimated_duration} seconds")
|
298 |
logging.info(f"Has chorus sections: {has_chorus}")
|