Spaces:
Running
on
L40S
Running
on
L40S
root
commited on
Commit
·
3c8f8cf
1
Parent(s):
723b4d3
format lyric input
Browse files
app.py
CHANGED
|
@@ -63,18 +63,32 @@ def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_co
|
|
| 63 |
params = {k:v for k,v in params.items() if v is not None}
|
| 64 |
sample_rate = MODEL.cfg.sample_rate
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
lyric = re.sub(r"[^\w\s\[\]\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af\u00c0-\u017f]", "", lyric)
|
| 68 |
-
lyric = lyric.lower()
|
| 69 |
lyric = lyric.replace("[intro]", "[intro-short]").replace("[inst]", "[inst-short]").replace("[outro]", "[outro-short]")
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if prompt_audio is not None:
|
| 79 |
genre = None
|
| 80 |
description = None
|
|
@@ -84,13 +98,13 @@ def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_co
|
|
| 84 |
progress(0.0, "Start Generation")
|
| 85 |
start = time.time()
|
| 86 |
|
| 87 |
-
audio_data = MODEL(
|
| 88 |
|
| 89 |
end = time.time()
|
| 90 |
|
| 91 |
# 创建输入配置的JSON
|
| 92 |
input_config = {
|
| 93 |
-
"lyric":
|
| 94 |
"genre": genre,
|
| 95 |
"prompt_audio": prompt_audio,
|
| 96 |
"description": description,
|
|
@@ -125,8 +139,8 @@ lyrics
|
|
| 125 |
'''
|
| 126 |
1. One paragraph represents one segments, starting with a structure tag and ending with a blank line
|
| 127 |
2. One line represents one sentence, punctuation is not recommended inside the sentence
|
| 128 |
-
3. The following segments should not contain lyrics: [intro-short]
|
| 129 |
-
4. The following segments require lyrics: [verse]
|
| 130 |
"""
|
| 131 |
)
|
| 132 |
|
|
@@ -186,7 +200,7 @@ lyrics
|
|
| 186 |
|
| 187 |
with gr.Column():
|
| 188 |
output_audio = gr.Audio(label="Generated Song", type="numpy")
|
| 189 |
-
output_json = gr.JSON(label="
|
| 190 |
|
| 191 |
# # 示例按钮
|
| 192 |
# examples = gr.Examples(
|
|
|
|
| 63 |
params = {k:v for k,v in params.items() if v is not None}
|
| 64 |
sample_rate = MODEL.cfg.sample_rate
|
| 65 |
|
| 66 |
+
# format lyric
|
|
|
|
|
|
|
| 67 |
lyric = lyric.replace("[intro]", "[intro-short]").replace("[inst]", "[inst-short]").replace("[outro]", "[outro-short]")
|
| 68 |
+
paragraphs = [p.strip() for p in lyric.strip().split('\n\n') if p.strip()]
|
| 69 |
+
paragraphs_norm = []
|
| 70 |
+
for para in paragraphs:
|
| 71 |
+
lines = para.splitlines()
|
| 72 |
+
struct_tag = lines[0].strip().lower()
|
| 73 |
+
if struct_tag not in STRUCTS:
|
| 74 |
+
return None, json.dumps(f"segments should start with a structure tag in {STRUCTS}")
|
| 75 |
+
if struct_tag in ['[verse]', '[chorus]', '[bridge]']:
|
| 76 |
+
if len(lines) < 2 or not [line.strip() for line in lines[1:] if line.strip()]:
|
| 77 |
+
return None, json.dumps("The following segments require lyrics: [verse], [chorus], [bridge]")
|
| 78 |
+
else:
|
| 79 |
+
new_para_list = []
|
| 80 |
+
for line in lines[1:]:
|
| 81 |
+
new_para_list.append(re.sub(r"[^\w\s\[\]\-\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af\u00c0-\u017f]", "", line))
|
| 82 |
+
new_para_str = f"{struct_tag} {'.'.join(new_para_list)}"
|
| 83 |
+
else:
|
| 84 |
+
if len(lines) > 1:
|
| 85 |
+
return None, json.dumps("The following segments should not contain lyrics: [intro], [intro-short], [intro-medium], [inst], [inst-short], [inst-medium], [outro], [outro-short], [outro-medium]")
|
| 86 |
+
else:
|
| 87 |
+
new_para_str = struct_tag
|
| 88 |
+
paragraphs_norm.append(new_para_str)
|
| 89 |
+
lyric_norm = " ; ".join(paragraphs_norm)
|
| 90 |
+
|
| 91 |
+
# format prompt
|
| 92 |
if prompt_audio is not None:
|
| 93 |
genre = None
|
| 94 |
description = None
|
|
|
|
| 98 |
progress(0.0, "Start Generation")
|
| 99 |
start = time.time()
|
| 100 |
|
| 101 |
+
audio_data = MODEL(lyric_norm, description, prompt_audio, genre, op.join(APP_DIR, "ckpt/prompt.pt"), params).cpu().permute(1, 0).float().numpy()
|
| 102 |
|
| 103 |
end = time.time()
|
| 104 |
|
| 105 |
# 创建输入配置的JSON
|
| 106 |
input_config = {
|
| 107 |
+
"lyric": lyric_norm,
|
| 108 |
"genre": genre,
|
| 109 |
"prompt_audio": prompt_audio,
|
| 110 |
"description": description,
|
|
|
|
| 139 |
'''
|
| 140 |
1. One paragraph represents one segments, starting with a structure tag and ending with a blank line
|
| 141 |
2. One line represents one sentence, punctuation is not recommended inside the sentence
|
| 142 |
+
3. The following segments should not contain lyrics: [intro-short], [intro-medium], [inst-short], [inst-medium], [outro-short], [outro-medium]
|
| 143 |
+
4. The following segments require lyrics: [verse], [chorus], [bridge]
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
|
|
|
|
| 200 |
|
| 201 |
with gr.Column():
|
| 202 |
output_audio = gr.Audio(label="Generated Song", type="numpy")
|
| 203 |
+
output_json = gr.JSON(label="Generated Info")
|
| 204 |
|
| 205 |
# # 示例按钮
|
| 206 |
# examples = gr.Examples(
|