Spaces:
Building
on
L40S
Building
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -77,33 +77,26 @@ def calculate_generation_params(lyrics):
|
|
77 |
}
|
78 |
|
79 |
total_duration = sum(section_durations.values())
|
|
|
80 |
|
81 |
-
#
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
-
tokens_per_second = 100
|
86 |
-
base_tokens = int(total_duration * tokens_per_second)
|
87 |
-
|
88 |
-
# ์ฝ๋ฌ์ค๊ฐ ์๋ ๊ฒฝ์ฐ ์ถ๊ฐ ํ ํฐ ํ ๋น
|
89 |
-
if sections['chorus'] > 0:
|
90 |
-
chorus_tokens = int(section_durations['chorus'] * tokens_per_second * 1.5)
|
91 |
-
total_tokens = base_tokens + chorus_tokens
|
92 |
-
else:
|
93 |
-
total_tokens = base_tokens
|
94 |
|
95 |
# ์น์
๊ธฐ๋ฐ ์ธ๊ทธ๋จผํธ ์ ๊ณ์ฐ
|
96 |
if sections['chorus'] > 0:
|
97 |
-
num_segments =
|
98 |
else:
|
99 |
-
num_segments =
|
100 |
|
101 |
-
# ํ ํฐ ์ ์ ํ
|
102 |
-
max_tokens = min(
|
103 |
|
104 |
return {
|
105 |
'max_tokens': max_tokens,
|
106 |
-
'num_segments':
|
107 |
'sections': sections,
|
108 |
'section_lines': section_lines,
|
109 |
'estimated_duration': total_duration,
|
@@ -294,14 +287,17 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
294 |
# ์ฝ๋ฌ์ค ์น์
ํ์ธ ๋ฐ ๋ก๊น
|
295 |
has_chorus = params['sections']['chorus'] > 0
|
296 |
estimated_duration = params.get('estimated_duration', 90)
|
297 |
-
|
|
|
298 |
# ํ ํฐ ์์ ์ธ๊ทธ๋จผํธ ์ ์กฐ์
|
299 |
if has_chorus:
|
300 |
-
actual_max_tokens = int(config['max_tokens'] * 1.
|
301 |
-
actual_num_segments =
|
302 |
else:
|
303 |
actual_max_tokens = config['max_tokens']
|
304 |
-
actual_num_segments =
|
|
|
|
|
305 |
|
306 |
logging.info(f"Estimated duration: {estimated_duration} seconds")
|
307 |
logging.info(f"Has chorus sections: {has_chorus}")
|
@@ -314,7 +310,6 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
314 |
output_dir = "./output"
|
315 |
os.makedirs(output_dir, exist_ok=True)
|
316 |
empty_output_folder(output_dir)
|
317 |
-
|
318 |
# ๊ธฐ๋ณธ ๋ช
๋ น์ด ๊ตฌ์ฑ
|
319 |
command = [
|
320 |
"python", "infer.py",
|
@@ -323,7 +318,7 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
323 |
"--genre_txt", genre_txt_path,
|
324 |
"--lyrics_txt", lyrics_txt_path,
|
325 |
"--run_n_segments", str(actual_num_segments),
|
326 |
-
"--stage2_batch_size",
|
327 |
"--output_dir", output_dir,
|
328 |
"--cuda_idx", "0",
|
329 |
"--max_new_tokens", str(actual_max_tokens)
|
@@ -331,9 +326,9 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
331 |
|
332 |
# GPU ์ค์
|
333 |
if torch.cuda.is_available():
|
334 |
-
command.
|
335 |
-
|
336 |
-
|
337 |
|
338 |
# CUDA ํ๊ฒฝ ๋ณ์ ์ค์
|
339 |
env = os.environ.copy()
|
|
|
77 |
}
|
78 |
|
79 |
total_duration = sum(section_durations.values())
|
80 |
+
total_duration = max(60, total_duration) # ์ต์ 60์ด
|
81 |
|
82 |
+
# ํ ํฐ ๊ณ์ฐ (๋ ๋ณด์์ ์ธ ๊ฐ ์ฌ์ฉ)
|
83 |
+
base_tokens = 3000 # ๊ธฐ๋ณธ ํ ํฐ ์
|
84 |
+
tokens_per_line = 200 # ์ค๋น ํ ํฐ ์
|
85 |
|
86 |
+
total_tokens = base_tokens + (total_lines * tokens_per_line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
# ์น์
๊ธฐ๋ฐ ์ธ๊ทธ๋จผํธ ์ ๊ณ์ฐ
|
89 |
if sections['chorus'] > 0:
|
90 |
+
num_segments = 3 # ์ฝ๋ฌ์ค๊ฐ ์๋ ๊ฒฝ์ฐ 3๊ฐ ์ธ๊ทธ๋จผํธ
|
91 |
else:
|
92 |
+
num_segments = 2 # ์ฝ๋ฌ์ค๊ฐ ์๋ ๊ฒฝ์ฐ 2๊ฐ ์ธ๊ทธ๋จผํธ
|
93 |
|
94 |
+
# ํ ํฐ ์ ์ ํ
|
95 |
+
max_tokens = min(8000, total_tokens) # ์ต๋ 8000 ํ ํฐ์ผ๋ก ์ ํ
|
96 |
|
97 |
return {
|
98 |
'max_tokens': max_tokens,
|
99 |
+
'num_segments': num_segments,
|
100 |
'sections': sections,
|
101 |
'section_lines': section_lines,
|
102 |
'estimated_duration': total_duration,
|
|
|
287 |
# ์ฝ๋ฌ์ค ์น์
ํ์ธ ๋ฐ ๋ก๊น
|
288 |
has_chorus = params['sections']['chorus'] > 0
|
289 |
estimated_duration = params.get('estimated_duration', 90)
|
290 |
+
|
291 |
+
|
292 |
# ํ ํฐ ์์ ์ธ๊ทธ๋จผํธ ์ ์กฐ์
|
293 |
if has_chorus:
|
294 |
+
actual_max_tokens = min(8000, int(config['max_tokens'] * 1.2)) # 20% ์ฆ๊ฐ, ์ต๋ 8000
|
295 |
+
actual_num_segments = 3
|
296 |
else:
|
297 |
actual_max_tokens = config['max_tokens']
|
298 |
+
actual_num_segments = 2
|
299 |
+
|
300 |
+
|
301 |
|
302 |
logging.info(f"Estimated duration: {estimated_duration} seconds")
|
303 |
logging.info(f"Has chorus sections: {has_chorus}")
|
|
|
310 |
output_dir = "./output"
|
311 |
os.makedirs(output_dir, exist_ok=True)
|
312 |
empty_output_folder(output_dir)
|
|
|
313 |
# ๊ธฐ๋ณธ ๋ช
๋ น์ด ๊ตฌ์ฑ
|
314 |
command = [
|
315 |
"python", "infer.py",
|
|
|
318 |
"--genre_txt", genre_txt_path,
|
319 |
"--lyrics_txt", lyrics_txt_path,
|
320 |
"--run_n_segments", str(actual_num_segments),
|
321 |
+
"--stage2_batch_size", "4", # ๋ฐฐ์น ์ฌ์ด์ฆ ๊ฐ์
|
322 |
"--output_dir", output_dir,
|
323 |
"--cuda_idx", "0",
|
324 |
"--max_new_tokens", str(actual_max_tokens)
|
|
|
326 |
|
327 |
# GPU ์ค์
|
328 |
if torch.cuda.is_available():
|
329 |
+
command.append("--disable_offload_model")
|
330 |
+
# GPU ์ค์
|
331 |
+
|
332 |
|
333 |
# CUDA ํ๊ฒฝ ๋ณ์ ์ค์
|
334 |
env = os.environ.copy()
|