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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
# from volcenginesdkarkruntime import Ark
|
6 |
+
import torch
|
7 |
+
import torchaudio
|
8 |
+
from einops import rearrange
|
9 |
+
import argparse
|
10 |
+
import json
|
11 |
+
import os
|
12 |
+
import spaces
|
13 |
+
from tqdm import tqdm
|
14 |
+
import random
|
15 |
+
import numpy as np
|
16 |
+
import sys
|
17 |
+
import base64
|
18 |
+
|
19 |
+
from diffrhythm.infer.infer_utils import (
|
20 |
+
get_reference_latent,
|
21 |
+
get_lrc_token,
|
22 |
+
get_audio_style_prompt,
|
23 |
+
get_text_style_prompt,
|
24 |
+
prepare_model,
|
25 |
+
get_negative_style_prompt
|
26 |
+
)
|
27 |
+
from diffrhythm.infer.infer import inference
|
28 |
+
|
29 |
+
MAX_SEED = np.iinfo(np.int32).max
|
30 |
+
device=device = "cpu"
|
31 |
+
cfm, cfm_full, tokenizer, muq, vae = prepare_model(device)
|
32 |
+
cfm = torch.compile(cfm)
|
33 |
+
cfm_full = torch.compile(cfm_full)
|
34 |
+
|
35 |
+
@spaces.GPU(duration=40)
|
36 |
+
def infer_music(lrc, ref_audio_path, text_prompt, current_prompt_type, seed=42, randomize_seed=False, steps=32, cfg_strength=4.0, file_type='wav', odeint_method='euler', Music_Duration='95s', device="cpu" ):
|
37 |
+
# Ensure that inputs like ref_audio_path are processed as tensors
|
38 |
+
if isinstance(ref_audio_path, np.ndarray):
|
39 |
+
ref_audio_path = torch.tensor(ref_audio_path, dtype=torch.float32) # Ensure float32
|
40 |
+
|
41 |
+
# Ensure that any other tensors are consistent with the correct dtype
|
42 |
+
if isinstance(lrc, np.ndarray):
|
43 |
+
lrc = torch.tensor(lrc, dtype=torch.float32)
|
44 |
+
|
45 |
+
if Music_Duration == '95s':
|
46 |
+
max_frames = 2048
|
47 |
+
cfm_model = cfm
|
48 |
+
else:
|
49 |
+
max_frames = 6144
|
50 |
+
cfm_model = cfm_full
|
51 |
+
if randomize_seed:
|
52 |
+
seed = random.randint(0, MAX_SEED)
|
53 |
+
torch.manual_seed(seed)
|
54 |
+
sway_sampling_coef = -1 if steps < 32 else None
|
55 |
+
vocal_flag = False
|
56 |
+
try:
|
57 |
+
lrc_prompt, start_time = get_lrc_token(max_frames, lrc, tokenizer, device)
|
58 |
+
if current_prompt_type == 'audio':
|
59 |
+
style_prompt, vocal_flag = get_audio_style_prompt(muq, ref_audio_path)
|
60 |
+
else:
|
61 |
+
style_prompt = get_text_style_prompt(muq, text_prompt)
|
62 |
+
except Exception as e:
|
63 |
+
print(f"Error details: {e}")
|
64 |
+
raise gr.Error(f"Error: {str(e)}")
|
65 |
+
negative_style_prompt = get_negative_style_prompt(device)
|
66 |
+
latent_prompt = get_reference_latent(device, max_frames)
|
67 |
+
generated_song = inference(cfm_model=cfm_model,
|
68 |
+
vae_model=vae,
|
69 |
+
cond=latent_prompt,
|
70 |
+
text=lrc_prompt,
|
71 |
+
duration=max_frames,
|
72 |
+
style_prompt=style_prompt,
|
73 |
+
negative_style_prompt=negative_style_prompt,
|
74 |
+
steps=steps,
|
75 |
+
cfg_strength=cfg_strength,
|
76 |
+
sway_sampling_coef=sway_sampling_coef,
|
77 |
+
start_time=start_time,
|
78 |
+
file_type=file_type,
|
79 |
+
vocal_flag=vocal_flag,
|
80 |
+
odeint_method=odeint_method,
|
81 |
+
)
|
82 |
+
return generated_song
|
83 |
+
os.environ["PATH"] = "/opt/homebrew/bin:" + os.environ["PATH"]
|
84 |
+
def R1_infer1(theme, tags_gen, language):
|
85 |
+
try:
|
86 |
+
client = OpenAI(api_key=os.getenv('HS_DP_API'), base_url = "https://ark.cn-beijing.volces.com/api/v3")
|
87 |
+
|
88 |
+
llm_prompt = """
|
89 |
+
请围绕"{theme}"主题生成一首符合"{tags}"风格的语言为{language}的完整歌词。严格遵循以下要求:
|
90 |
+
|
91 |
+
### **强制格式规则**
|
92 |
+
1. **仅输出时间戳和歌词**,禁止任何括号、旁白、段落标记(如副歌、间奏、尾奏等注释)。
|
93 |
+
2. 每行格式必须为 `[mm:ss.xx]歌词内容`,时间戳与歌词间无空格,歌词内容需完整连贯。
|
94 |
+
3. 时间戳需自然分布,**第一句歌词起始时间不得为 [00:00.00]**,需考虑前奏空白。
|
95 |
+
|
96 |
+
### **内容与结构要求**
|
97 |
+
1. 歌词应富有变化,使情绪递进,整体连贯有层次感。**每行歌词长度应自然变化**,切勿长度一致,导致很格式化。
|
98 |
+
2. **时间戳分配应根据歌曲的标签、歌词的情感、节奏来合理推测**,而非机械地按照歌词长度分配。
|
99 |
+
3. 间奏/尾奏仅通过时间空白体现(如从 [02:30.00] 直接跳至 [02:50.00]),**无需文字描述**。
|
100 |
+
|
101 |
+
### **负面示例(禁止出现)**
|
102 |
+
- 错误:[01:30.00](钢琴间奏)
|
103 |
+
- 错误:[02:00.00][副歌]
|
104 |
+
- 错误:空行、换行符、注释
|
105 |
+
"""
|
106 |
+
|
107 |
+
response = client.chat.completions.create(
|
108 |
+
model="ep-20250304144033-nr9wl",
|
109 |
+
messages=[
|
110 |
+
{"role": "system", "content": "You are a professional musician who has been invited to make music-related comments."},
|
111 |
+
{"role": "user", "content": llm_prompt.format(theme=theme, tags=tags_gen, language=language)},
|
112 |
+
],
|
113 |
+
stream=False
|
114 |
+
)
|
115 |
+
|
116 |
+
info = response.choices[0].message.content
|
117 |
+
|
118 |
+
return info
|
119 |
+
|
120 |
+
except requests.exceptions.RequestException as e:
|
121 |
+
print(f'请求出错: {e}')
|
122 |
+
return {}
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
def R1_infer2(tags_lyrics, lyrics_input):
|
127 |
+
client = OpenAI(api_key=os.getenv('HS_DP_API'), base_url = "https://ark.cn-beijing.volces.com/api/v3")
|
128 |
+
|
129 |
+
llm_prompt = """
|
130 |
+
{lyrics_input}这是一首歌的歌词,每一行是一句歌词,{tags_lyrics}是我希望这首歌的风格,我现在想要给这首歌的每一句歌词打时间戳得到LRC,我希望时间戳分配应根据歌曲的标签、歌词的情感、节奏来合理推测,而非机械地按照歌词长度分配。第一句歌词的时间戳应考虑前奏长度,避免歌词从 `[00:00.00]` 直接开始。严格按照 LRC 格式输出歌词,每行格式为 `[mm:ss.xx]歌词内容`。最后的结果只输出LRC,不需要其他的解释。
|
131 |
+
"""
|
132 |
+
|
133 |
+
response = client.chat.completions.create(
|
134 |
+
model="ep-20250304144033-nr9wl",
|
135 |
+
messages=[
|
136 |
+
{"role": "system", "content": "You are a professional musician who has been invited to make music-related comments."},
|
137 |
+
{"role": "user", "content": llm_prompt.format(lyrics_input=lyrics_input, tags_lyrics=tags_lyrics)},
|
138 |
+
],
|
139 |
+
stream=False
|
140 |
+
)
|
141 |
+
|
142 |
+
info = response.choices[0].message.content
|
143 |
+
|
144 |
+
return info
|
145 |
+
|
146 |
+
css = """
|
147 |
+
/* Modern music-themed color palette */
|
148 |
+
:root {
|
149 |
+
--primary-pink: #ff69b4;
|
150 |
+
--secondary-pink: #ffb6c1;
|
151 |
+
--dark-purple: #4a154b;
|
152 |
+
--light-purple: #9c27b0;
|
153 |
+
--background: #1a1a1a;
|
154 |
+
--text-light: #ffffff;
|
155 |
+
--text-dark: #333333;
|
156 |
+
}
|
157 |
+
|
158 |
+
/* Global styles */
|
159 |
+
.gradio-container {
|
160 |
+
background: linear-gradient(135deg, #1a1a1a 0%, #2d1f3d 100%);
|
161 |
+
color: var(--text-light);
|
162 |
+
}
|
163 |
+
|
164 |
+
/* Enhanced text area styling */
|
165 |
+
.lyrics-scroll-box textarea {
|
166 |
+
height: 405px !important;
|
167 |
+
max-height: 500px !important;
|
168 |
+
overflow-y: auto !important;
|
169 |
+
white-space: pre-wrap;
|
170 |
+
line-height: 1.6;
|
171 |
+
padding: 15px !important;
|
172 |
+
border-radius: 12px !important;
|
173 |
+
border: 2px solid var(--primary-pink) !important;
|
174 |
+
background-color: rgba(26, 26, 26, 0.9) !important;
|
175 |
+
color: var(--text-light) !important;
|
176 |
+
font-family: 'Source Code Pro', monospace;
|
177 |
+
transition: all 0.3s ease;
|
178 |
+
box-shadow: 0 0 15px rgba(255, 105, 180, 0.2);
|
179 |
+
}
|
180 |
+
|
181 |
+
.lyrics-scroll-box textarea:focus {
|
182 |
+
border-color: var(--secondary-pink) !important;
|
183 |
+
box-shadow: 0 0 20px rgba(255, 105, 180, 0.4);
|
184 |
+
}
|
185 |
+
|
186 |
+
/* Music-themed button styling */
|
187 |
+
button.primary {
|
188 |
+
background: linear-gradient(45deg, var(--primary-pink), var(--light-purple)) !important;
|
189 |
+
border: none !important;
|
190 |
+
border-radius: 25px !important;
|
191 |
+
padding: 12px 24px !important;
|
192 |
+
color: white !important;
|
193 |
+
font-weight: 600 !important;
|
194 |
+
transition: all 0.3s ease;
|
195 |
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
|
196 |
+
box-shadow: 0 4px 15px rgba(255, 105, 180, 0.3);
|
197 |
+
}
|
198 |
+
|
199 |
+
button.primary:hover {
|
200 |
+
transform: translateY(-2px);
|
201 |
+
box-shadow: 0 6px 20px rgba(255, 105, 180, 0.5);
|
202 |
+
}
|
203 |
+
|
204 |
+
/* Tab styling */
|
205 |
+
.tabs {
|
206 |
+
border-radius: 12px;
|
207 |
+
overflow: hidden;
|
208 |
+
background: rgba(26, 26, 26, 0.8);
|
209 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
210 |
+
border: 1px solid rgba(255, 105, 180, 0.2);
|
211 |
+
}
|
212 |
+
|
213 |
+
.tab-selected {
|
214 |
+
background: linear-gradient(45deg, var(--primary-pink), var(--light-purple)) !important;
|
215 |
+
color: white !important;
|
216 |
+
border: none !important;
|
217 |
+
}
|
218 |
+
|
219 |
+
/* Examples section styling */
|
220 |
+
.gr-examples {
|
221 |
+
background: rgba(26, 26, 26, 0.8) !important;
|
222 |
+
border: 1px solid var(--primary-pink) !important;
|
223 |
+
border-radius: 12px;
|
224 |
+
margin: 1rem 0 !important;
|
225 |
+
padding: 1.5rem !important;
|
226 |
+
box-shadow: 0 4px 15px rgba(255, 105, 180, 0.2);
|
227 |
+
}
|
228 |
+
|
229 |
+
/* Slider improvements */
|
230 |
+
.gr-slider {
|
231 |
+
padding: 12px 0;
|
232 |
+
}
|
233 |
+
|
234 |
+
.gr-slider .handle {
|
235 |
+
background: var(--primary-pink) !important;
|
236 |
+
box-shadow: 0 0 10px var(--primary-pink);
|
237 |
+
}
|
238 |
+
|
239 |
+
.gr-slider .track {
|
240 |
+
background: rgba(255, 105, 180, 0.3) !important;
|
241 |
+
}
|
242 |
+
|
243 |
+
/* Accordion styling */
|
244 |
+
.gr-accordion {
|
245 |
+
border: 1px solid var(--primary-pink);
|
246 |
+
border-radius: 12px;
|
247 |
+
margin: 1rem 0;
|
248 |
+
background: rgba(26, 26, 26, 0.8);
|
249 |
+
}
|
250 |
+
|
251 |
+
.gr-accordion summary {
|
252 |
+
padding: 15px;
|
253 |
+
background: rgba(255, 105, 180, 0.1);
|
254 |
+
cursor: pointer;
|
255 |
+
color: var(--text-light);
|
256 |
+
}
|
257 |
+
|
258 |
+
/* Audio player styling */
|
259 |
+
.gr-audio {
|
260 |
+
border-radius: 12px;
|
261 |
+
overflow: hidden;
|
262 |
+
margin: 1rem 0;
|
263 |
+
background: rgba(26, 26, 26, 0.8);
|
264 |
+
border: 1px solid var(--primary-pink);
|
265 |
+
}
|
266 |
+
|
267 |
+
/* Radio button styling */
|
268 |
+
.gr-radio {
|
269 |
+
gap: 12px;
|
270 |
+
}
|
271 |
+
|
272 |
+
.gr-radio label {
|
273 |
+
padding: 10px 20px;
|
274 |
+
border-radius: 25px;
|
275 |
+
transition: all 0.3s ease;
|
276 |
+
background: rgba(255, 105, 180, 0.1);
|
277 |
+
color: var(--text-light);
|
278 |
+
}
|
279 |
+
|
280 |
+
.gr-radio label:hover {
|
281 |
+
background: rgba(255, 105, 180, 0.2);
|
282 |
+
}
|
283 |
+
|
284 |
+
.gr-radio input:checked + label {
|
285 |
+
background: linear-gradient(45deg, var(--primary-pink), var(--light-purple));
|
286 |
+
color: white;
|
287 |
+
}
|
288 |
+
|
289 |
+
/* Input field styling */
|
290 |
+
.gr-input {
|
291 |
+
background: rgba(26, 26, 26, 0.8) !important;
|
292 |
+
border: 2px solid var(--primary-pink) !important;
|
293 |
+
border-radius: 12px !important;
|
294 |
+
color: var(--text-light) !important;
|
295 |
+
padding: 12px !important;
|
296 |
+
}
|
297 |
+
|
298 |
+
.gr-input:focus {
|
299 |
+
box-shadow: 0 0 15px rgba(255, 105, 180, 0.3);
|
300 |
+
}
|
301 |
+
|
302 |
+
/* Dropdown styling */
|
303 |
+
.gr-dropdown {
|
304 |
+
background: rgba(26, 26, 26, 0.8) !important;
|
305 |
+
border: 2px solid var(--primary-pink) !important;
|
306 |
+
border-radius: 12px !important;
|
307 |
+
color: var(--text-light) !important;
|
308 |
+
}
|
309 |
+
|
310 |
+
/* Checkbox styling */
|
311 |
+
.gr-checkbox {
|
312 |
+
accent-color: var(--primary-pink);
|
313 |
+
}
|
314 |
+
|
315 |
+
/* Loading animation */
|
316 |
+
.progress-bar {
|
317 |
+
background: linear-gradient(45deg, var(--primary-pink), var(--light-purple));
|
318 |
+
}
|
319 |
+
|
320 |
+
/* Scrollbar styling */
|
321 |
+
::-webkit-scrollbar {
|
322 |
+
width: 10px;
|
323 |
+
}
|
324 |
+
|
325 |
+
::-webkit-scrollbar-track {
|
326 |
+
background: rgba(26, 26, 26, 0.8);
|
327 |
+
}
|
328 |
+
|
329 |
+
::-webkit-scrollbar-thumb {
|
330 |
+
background: var(--primary-pink);
|
331 |
+
border-radius: 5px;
|
332 |
+
}
|
333 |
+
|
334 |
+
/* Responsive improvements */
|
335 |
+
@media (max-width: 768px) {
|
336 |
+
.gr-examples {
|
337 |
+
padding: 1rem !important;
|
338 |
+
}
|
339 |
+
|
340 |
+
button.primary {
|
341 |
+
width: 100%;
|
342 |
+
}
|
343 |
+
}
|
344 |
+
"""
|
345 |
+
|
346 |
+
|
347 |
+
with gr.Blocks(css=css) as demo:
|
348 |
+
gr.HTML(f"""
|
349 |
+
<div style="text-align: center; margin-bottom: 2rem;">
|
350 |
+
# <div style="display: inline-block; background: rgba(26, 26, 26, 0.9); padding: 25px; border-radius: 20px; box-shadow: 0 0 30px rgba(255, 105, 180, 0.3);">
|
351 |
+
# # <img src=''
|
352 |
+
# # style='width: 200px; height: auto; margin-bottom: 1rem; border-radius: 15px; box-shadow: 0 4px 15px rgba(255, 105, 180, 0.4);'>
|
353 |
+
|
354 |
+
<h1 style="font-size: 2.8em; font-weight: bold; margin: 0.5rem 0; background: linear-gradient(45deg, #ff69b4, #9c27b0); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
|
355 |
+
TuneWeave (Generate Your Music)
|
356 |
+
</h1>
|
357 |
+
|
358 |
+
<div style="display: flex; gap: 15px; justify-content: center; margin-top: 1.5rem;">
|
359 |
+
<a href="https://arxiv.org/abs/2503.01183" style="text-decoration: none;">
|
360 |
+
<button style="background: linear-gradient(45deg, #ff69b4, #9c27b0); color: white; border: none; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(255, 105, 180, 0.3);">
|
361 |
+
📄 Paper
|
362 |
+
</button>
|
363 |
+
</a>
|
364 |
+
<a href="https://github.com/ASLP-lab/DiffRhythm" style="text-decoration: none;">
|
365 |
+
<button style="background: linear-gradient(45deg, #ff69b4, #9c27b0); color: white; border: none; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(255, 105, 180, 0.3);">
|
366 |
+
💻 GitHub
|
367 |
+
</button>
|
368 |
+
</a>
|
369 |
+
<a href="https://aslp-lab.github.io/DiffRhythm.github.io/" style="text-decoration: none;">
|
370 |
+
<button style="background: linear-gradient(45deg, #ff69b4, #9c27b0); color: white; border: none; padding: 10px 20px; border-radius: 25px; cursor: pointer; font-weight: 600; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(255, 105, 180, 0.3);">
|
371 |
+
🌐 Project
|
372 |
+
</button>
|
373 |
+
</a>
|
374 |
+
</div>
|
375 |
+
</div>
|
376 |
+
</div>
|
377 |
+
""")
|
378 |
+
|
379 |
+
with gr.Tabs() as tabs:
|
380 |
+
|
381 |
+
# page 1
|
382 |
+
with gr.Tab("Music Generate", id=0):
|
383 |
+
with gr.Row():
|
384 |
+
with gr.Column():
|
385 |
+
lrc = gr.Textbox(
|
386 |
+
label="Lyrics",
|
387 |
+
placeholder="Input the full lyrics",
|
388 |
+
lines=12,
|
389 |
+
max_lines=50,
|
390 |
+
elem_classes="lyrics-scroll-box",
|
391 |
+
value="""[00:04.34]Tell me that I'm special\n[00:06.57]Tell me I look pretty\n[00:08.46]Tell me I'm a little angel\n[00:10.58]Sweetheart of your city\n[00:13.64]Say what I'm dying to hear\n[00:17.35]Cause I'm dying to hear you\n[00:20.86]Tell me I'm that new thing\n[00:22.93]Tell me that I'm relevant\n[00:24.96]Tell me that I got a big heart\n[00:27.04]Then back it up with evidence\n[00:29.94]I need it and I don't know why\n[00:34.28]This late at night\n[00:36.32]Isn't it lonely\n[00:39.24]I'd do anything to make you want me\n[00:43.40]I'd give it all up if you told me\n[00:47.42]That I'd be\n[00:49.43]The number one girl in your eyes\n[00:52.85]Your one and only\n[00:55.74]So what's it gon' take for you to want me\n[00:59.78]I'd give it all up if you told me\n[01:03.89]That I'd be\n[01:05.94]The number one girl in your eyes\n[01:11.34]Tell me I'm going real big places\n[01:14.32]Down to earth so friendly\n[01:16.30]And even through all the phases\n[01:18.46]Tell me you accept me\n[01:21.56]Well that's all I'm dying to hear\n[01:25.30]Yeah I'm dying to hear you\n[01:28.91]Tell me that you need me\n[01:30.85]Tell me that I'm loved\n[01:32.90]Tell me that I'm worth it\n[01:34.95]And that I'm enough\n[01:37.91]I need it and I don't know why\n[01:42.08]This late at night\n[01:44.24]Isn't it lonely\n[01:47.18]I'd do anything to make you want me\n[01:51.30]I'd give it all up if you told me\n[01:55.32]That I'd be\n[01:57.35]The number one girl in your eyes\n[02:00.72]Your one and only\n[02:03.57]So what's it gon' take for you to want me\n[02:07.78]I'd give it all up if you told me\n[02:11.74]That I'd be\n[02:13.86]The number one girl in your eyes\n[02:17.03]The girl in your eyes\n[02:21.05]The girl in your eyes\n[02:26.30]Tell me I'm the number one girl\n[02:28.44]I'm the number one girl in your eyes\n[02:33.49]The girl in your eyes\n[02:37.58]The girl in your eyes\n[02:42.74]Tell me I'm the number one girl\n[02:44.88]I'm the number one girl in your eyes\n[02:49.91]Well isn't it lonely\n[02:53.19]I'd do anything to make you want me\n[02:57.10]I'd give it all up if you told me\n[03:01.15]That I'd be\n[03:03.31]The number one girl in your eyes\n[03:06.57]Your one and only\n[03:09.42]So what's it gon' take for you to want me\n[03:13.50]I'd give it all up if you told me\n[03:17.56]That I'd be\n[03:19.66]The number one girl in your eyes\n[03:25.74]The number one girl in your eyes"""
|
392 |
+
)
|
393 |
+
|
394 |
+
current_prompt_type = gr.State(value="audio")
|
395 |
+
with gr.Tabs() as inside_tabs:
|
396 |
+
with gr.Tab("Audio Prompt"):
|
397 |
+
audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./src/prompt/default.wav")
|
398 |
+
with gr.Tab("Text Prompt"):
|
399 |
+
text_prompt = gr.Textbox(
|
400 |
+
label="Text Prompt",
|
401 |
+
placeholder="Enter the Text Prompt, eg: emotional piano pop",
|
402 |
+
)
|
403 |
+
def update_prompt_type(evt: gr.SelectData):
|
404 |
+
return "audio" if evt.index == 0 else "text"
|
405 |
+
|
406 |
+
inside_tabs.select(
|
407 |
+
fn=update_prompt_type,
|
408 |
+
outputs=current_prompt_type
|
409 |
+
)
|
410 |
+
|
411 |
+
with gr.Column():
|
412 |
+
with gr.Accordion("Best Practices Guide", open=True):
|
413 |
+
gr.Markdown("""
|
414 |
+
1. **Lyrics Format Requirements**
|
415 |
+
- Each line must follow: `[mm:ss.xx]Lyric content`
|
416 |
+
- Example of valid format:
|
417 |
+
```
|
418 |
+
[00:10.00]Moonlight spills through broken blinds
|
419 |
+
[00:13.20]Your shadow dances on the dashboard shrine
|
420 |
+
```
|
421 |
+
|
422 |
+
2. **Audio Prompt Requirements**
|
423 |
+
- Reference audio should be ≥ 1 second, audio >10 seconds will be randomly clipped into 10 seconds
|
424 |
+
- For optimal results, the 10-second clips should be carefully selected
|
425 |
+
- Shorter clips may lead to incoherent generation
|
426 |
+
3. **Supported Languages**
|
427 |
+
- **Chinese and English**
|
428 |
+
- More languages comming soon
|
429 |
+
|
430 |
+
4. **Others**
|
431 |
+
- If loading audio result is slow, you can select Output Format as mp3 in Advanced Settings.
|
432 |
+
|
433 |
+
""")
|
434 |
+
Music_Duration = gr.Radio(["95s", "285s"], label="Music Duration", value="95s")
|
435 |
+
|
436 |
+
lyrics_btn = gr.Button("Generate", variant="primary")
|
437 |
+
audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")
|
438 |
+
with gr.Accordion("Advanced Settings", open=False):
|
439 |
+
seed = gr.Slider(
|
440 |
+
label="Seed",
|
441 |
+
minimum=0,
|
442 |
+
maximum=MAX_SEED,
|
443 |
+
step=1,
|
444 |
+
value=0,
|
445 |
+
)
|
446 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
447 |
+
|
448 |
+
steps = gr.Slider(
|
449 |
+
minimum=10,
|
450 |
+
maximum=100,
|
451 |
+
value=32,
|
452 |
+
step=1,
|
453 |
+
label="Diffusion Steps",
|
454 |
+
interactive=True,
|
455 |
+
elem_id="step_slider"
|
456 |
+
)
|
457 |
+
cfg_strength = gr.Slider(
|
458 |
+
minimum=1,
|
459 |
+
maximum=10,
|
460 |
+
value=4.0,
|
461 |
+
step=0.5,
|
462 |
+
label="CFG Strength",
|
463 |
+
interactive=True,
|
464 |
+
elem_id="step_slider"
|
465 |
+
)
|
466 |
+
odeint_method = gr.Radio(["euler", "midpoint", "rk4","implicit_adams"], label="ODE Solver", value="euler")
|
467 |
+
file_type = gr.Dropdown(["wav", "mp3", "ogg"], label="Output Format", value="wav")
|
468 |
+
|
469 |
+
|
470 |
+
gr.Examples(
|
471 |
+
examples=[
|
472 |
+
["./src/prompt/pop_cn.wav"],
|
473 |
+
["./src/prompt/pop_en.wav"],
|
474 |
+
["./src/prompt/rock_cn.wav"],
|
475 |
+
["./src/prompt/rock_en.wav"],
|
476 |
+
["./src/prompt/country_cn.wav"],
|
477 |
+
["./src/prompt/country_en.wav"],
|
478 |
+
["./src/prompt/classic_cn.wav"],
|
479 |
+
["./src/prompt/classic_en.wav"],
|
480 |
+
["./src/prompt/jazz_cn.wav"],
|
481 |
+
["./src/prompt/jazz_en.wav"],
|
482 |
+
["./src/prompt/rap_cn.wav"],
|
483 |
+
["./src/prompt/rap_en.wav"],
|
484 |
+
["./src/prompt/default.wav"]
|
485 |
+
],
|
486 |
+
inputs=[audio_prompt],
|
487 |
+
label="Audio Examples",
|
488 |
+
examples_per_page=13,
|
489 |
+
elem_id="audio-examples-container"
|
490 |
+
)
|
491 |
+
|
492 |
+
gr.Examples(
|
493 |
+
examples=[
|
494 |
+
["Pop Emotional Piano"],
|
495 |
+
["流行 情感 钢琴"],
|
496 |
+
["Indie folk ballad, coming-of-age themes, acoustic guitar picking with harmonica interludes"],
|
497 |
+
["独立民谣, 成长主题, 原声吉他弹奏与口琴间奏"]
|
498 |
+
],
|
499 |
+
inputs=[text_prompt],
|
500 |
+
label="Text Examples",
|
501 |
+
examples_per_page=4,
|
502 |
+
elem_id="text-examples-container"
|
503 |
+
)
|
504 |
+
|
505 |
+
gr.Examples(
|
506 |
+
examples=[
|
507 |
+
["""[00:04.34]Tell me that I'm special\n[00:06.57]Tell me I look pretty\n[00:08.46]Tell me I'm a little angel\n[00:10.58]Sweetheart of your city\n[00:13.64]Say what I'm dying to hear\n[00:17.35]Cause I'm dying to hear you\n[00:20.86]Tell me I'm that new thing\n[00:22.93]Tell me that I'm relevant\n[00:24.96]Tell me that I got a big heart\n[00:27.04]Then back it up with evidence\n[00:29.94]I need it and I don't know why\n[00:34.28]This late at night\n[00:36.32]Isn't it lonely\n[00:39.24]I'd do anything to make you want me\n[00:43.40]I'd give it all up if you told me\n[00:47.42]That I'd be\n[00:49.43]The number one girl in your eyes\n[00:52.85]Your one and only\n[00:55.74]So what's it gon' take for you to want me\n[00:59.78]I'd give it all up if you told me\n[01:03.89]That I'd be\n[01:05.94]The number one girl in your eyes\n[01:11.34]Tell me I'm going real big places\n[01:14.32]Down to earth so friendly\n[01:16.30]And even through all the phases\n[01:18.46]Tell me you accept me\n[01:21.56]Well that's all I'm dying to hear\n[01:25.30]Yeah I'm dying to hear you\n[01:28.91]Tell me that you need me\n[01:30.85]Tell me that I'm loved\n[01:32.90]Tell me that I'm worth it\n[01:34.95]And that I'm enough\n[01:37.91]I need it and I don't know why\n[01:42.08]This late at night\n[01:44.24]Isn't it lonely\n[01:47.18]I'd do anything to make you want me\n[01:51.30]I'd give it all up if you told me\n[01:55.32]That I'd be\n[01:57.35]The number one girl in your eyes\n[02:00.72]Your one and only\n[02:03.57]So what's it gon' take for you to want me\n[02:07.78]I'd give it all up if you told me\n[02:11.74]That I'd be\n[02:13.86]The number one girl in your eyes\n[02:17.03]The girl in your eyes\n[02:21.05]The girl in your eyes\n[02:26.30]Tell me I'm the number one girl\n[02:28.44]I'm the number one girl in your eyes\n[02:33.49]The girl in your eyes\n[02:37.58]The girl in your eyes\n[02:42.74]Tell me I'm the number one girl\n[02:44.88]I'm the number one girl in your eyes\n[02:49.91]Well isn't it lonely\n[02:53.19]I'd do anything to make you want me\n[02:57.10]I'd give it all up if you told me\n[03:01.15]That I'd be\n[03:03.31]The number one girl in your eyes\n[03:06.57]Your one and only\n[03:09.42]So what's it gon' take for you to want me\n[03:13.50]I'd give it all up if you told me\n[03:17.56]That I'd be\n[03:19.66]The number one girl in your eyes\n[03:25.74]The number one girl in your eyes"""],
|
508 |
+
["""[00:00.52]Abracadabra abracadabra\n[00:03.97]Ha\n[00:04.66]Abracadabra abracadabra\n[00:12.02]Yeah\n[00:15.80]Pay the toll to the angels\n[00:19.08]Drawin' circles in the clouds\n[00:23.31]Keep your mind on the distance\n[00:26.67]When the devil turns around\n[00:30.95]Hold me in your heart tonight\n[00:34.11]In the magic of the dark moonlight\n[00:38.44]Save me from this empty fight\n[00:43.83]In the game of life\n[00:45.84]Like a poem said by a lady in red\n[00:49.45]You hear the last few words of your life\n[00:53.15]With a haunting dance now you're both in a trance\n[00:56.90]It's time to cast your spell on the night\n[01:01.40]Abracadabra ama-ooh-na-na\n[01:04.88]Abracadabra porta-ooh-ga-ga\n[01:08.92]Abracadabra abra-ooh-na-na\n[01:12.30]In her tongue she's sayin'\n[01:14.76]Death or love tonight\n[01:18.61]Abracadabra abracadabra\n[01:22.18]Abracadabra abracadabra\n[01:26.08]Feel the beat under your feet\n[01:27.82]The floor's on fire\n[01:29.90]Abracadabra abracadabra\n[01:33.78]Choose the road on the west side\n[01:37.09]As the dust flies watch it burn\n[01:41.45]Don't waste time on feeling\n[01:44.64]Your depression won't return\n[01:49.15]Hold me in your heart tonight\n[01:52.21]In the magic of the dark moonlight\n[01:56.54]Save me from this empty fight\n[02:01.77]In the game of life\n[02:03.94]Like a poem said by a lady in red\n[02:07.52]You hear the last few words of your life\n[02:11.19]With a haunting dance now you're both in a trance\n[02:14.95]It's time to cast your spell on the night\n[02:19.53]Abracadabra ama-ooh-na-na\n[02:22.71]Abracadabra porta-ooh-ga-ga\n[02:26.94]Abracadabra abra-ooh-na-na\n[02:30.42]In her tongue she's sayin'\n[02:32.83]Death or love tonight\n[02:36.55]Abracadabra abracadabra\n[02:40.27]Abracadabra abracadabra\n[02:44.19]Feel the beat under your feet\n[02:46.14]The floor's on fire\n[02:47.95]Abracadabra abracadabra\n[02:51.17]Phantom of the dance floor come to me\n[02:58.46]Sing for me a sinful melody\n[03:06.51]Ah-ah-ah-ah-ah ah-ah ah-ah\n[03:13.76]Ah-ah-ah-ah-ah ah-ah ah-ah\n[03:22.39]Abracadabra ama-ooh-na-na\n[03:25.66]Abracadabra porta-ooh-ga-ga\n[03:29.87]Abracadabra abra-ooh-na-na\n[03:33.16]In her tongue she's sayin'\n[03:35.55]Death or love tonight"""],
|
509 |
+
# ["""[00:00.27]只因你太美 baby 只因你太美 baby\n[00:08.95]只因你实在是太美 baby\n[00:13.99]只因你太美 baby\n[00:18.89]迎面走来的你让我如此蠢蠢欲动\n[00:20.88]这种感觉我从未有\n[00:21.79]Cause I got a crush on you who you\n[00:25.74]你是我的我是你的谁\n[00:28.09]再多一眼看一眼就会爆炸\n[00:30.31]再近一点靠近点快被融化\n[00:32.49]想要把你占为己有 baby bae\n[00:34.60]不管走到哪里\n[00:35.44]都会想起的人是你 you you\n[00:38.12]我应该拿你怎样\n[00:39.61]Uh 所有人都在看着你\n[00:42.36]我的心总是不安\n[00:44.18]Oh 我现在已病入膏肓\n[00:46.63]Eh oh\n[00:47.84]难道真的因你而疯狂吗\n[00:51.57]我本来不是这种人\n[00:53.59]因你变成奇怪的人\n[00:55.77]第一次呀变成这样的我\n[01:01.23]不管我怎么去否认\n[01:03.21]只因你太美 baby 只因你太美 baby\n[01:11.46]只因你实在是太美 baby\n[01:16.75]只因你太美 baby\n[01:21.09]Oh eh oh\n[01:22.82]现在确认地告诉我\n[01:25.26]Oh eh oh\n[01:27.31]你到底属于谁\n[01:29.98]Oh eh oh\n[01:31.70]现在确认地告诉我\n[01:34.45]Oh eh oh\n[01:36.35]你到底属于谁\n[01:37.65]就是现在告诉我\n[01:40.00]跟着那节奏 缓缓 make wave\n[01:42.42]甜蜜的奶油 it's your birthday cake\n[01:44.66]男人们的 game call me 你恋人\n[01:46.83]别被欺骗愉快的 I wanna play\n[01:48.83]我的脑海每分每秒为你一人沉醉\n[01:50.90]最迷人让我神魂颠倒是你身上香水\n[01:53.30]Oh right baby I'm fall in love with you\n[01:55.20]我的一切你都拿走\n[01:56.40]只要有你就已足够\n[01:58.56]我到底应该怎样\n[02:00.37]Uh 我心里一直很不安\n[02:03.12]其他男人们的视线\n[02:04.84]Oh 全都只看着你的脸\n[02:07.33]Eh oh\n[02:08.39]难道真的因你而疯狂吗\n[02:12.43]我本来不是这种人\n[02:14.35]因你变成奇怪的人\n[02:16.59]第一次呀变成这样的我\n[02:21.76]不管我怎么去否认\n[02:24.03]只因你太美 baby 只因你太美 baby\n[02:32.37]只因你实在是太美 baby\n[02:37.49]只因你太美 baby\n[02:43.66]我愿意把我的全部都给你\n[02:47.19]我每天在梦里都梦见你\n[02:49.13]还有我闭着眼睛也能看到你\n[02:52.58]现在开始我只准你看我\n[02:56.28]I don't wanna wake up in dream\n[02:57.92]我只想看你这是真心话\n[02:59.86]只因你太美 baby 只因你太美 baby\n[03:08.20]只因你实在是太美 baby\n[03:13.22]只因你太美 baby\n[03:17.69]Oh eh oh\n[03:19.36]现在确认的告诉我\n[03:21.91]Oh eh oh\n[03:23.85]你到底属于谁\n[03:26.58]Oh eh oh\n[03:28.32]现在确认的告诉我\n[03:30.95]Oh eh oh\n[03:32.82]你到底属于谁就是现在告诉我"""]
|
510 |
+
],
|
511 |
+
|
512 |
+
inputs=[lrc],
|
513 |
+
label="Lrc Examples",
|
514 |
+
examples_per_page=3,
|
515 |
+
elem_id="lrc-examples-container",
|
516 |
+
)
|
517 |
+
|
518 |
+
|
519 |
+
# page 2
|
520 |
+
with gr.Tab("Lyrics Generate", id=1):
|
521 |
+
with gr.Row():
|
522 |
+
with gr.Column():
|
523 |
+
with gr.Accordion("Notice", open=False):
|
524 |
+
gr.Markdown("**Two Generation Modes:**\n1. Generate from theme & tags\n2. Add timestamps to existing lyrics")
|
525 |
+
|
526 |
+
with gr.Group():
|
527 |
+
gr.Markdown("### Method 1: Generate from Theme")
|
528 |
+
theme = gr.Textbox(label="theme", placeholder="Enter song theme, e.g: Love and Heartbreak")
|
529 |
+
tags_gen = gr.Textbox(label="tags", placeholder="Enter song tags, e.g: pop confidence healing")
|
530 |
+
language = gr.Radio(["cn", "en"], label="Language", value="en")
|
531 |
+
gen_from_theme_btn = gr.Button("Generate LRC (From Theme)", variant="primary")
|
532 |
+
|
533 |
+
gr.Examples(
|
534 |
+
examples=[
|
535 |
+
[
|
536 |
+
"Love and Heartbreak",
|
537 |
+
"vocal emotional piano pop",
|
538 |
+
"en"
|
539 |
+
],
|
540 |
+
[
|
541 |
+
"Heroic Epic",
|
542 |
+
"choir orchestral powerful",
|
543 |
+
"cn"
|
544 |
+
]
|
545 |
+
],
|
546 |
+
inputs=[theme, tags_gen, language],
|
547 |
+
label="Examples: Generate from Theme"
|
548 |
+
)
|
549 |
+
|
550 |
+
with gr.Group(visible=True):
|
551 |
+
gr.Markdown("### Method 2: Add Timestamps to Lyrics")
|
552 |
+
tags_lyrics = gr.Textbox(label="tags", placeholder="Enter song tags, e.g: ballad piano slow")
|
553 |
+
lyrics_input = gr.Textbox(
|
554 |
+
label="Raw Lyrics (without timestamps)",
|
555 |
+
placeholder="Enter plain lyrics (without timestamps), e.g:\nYesterday\nAll my troubles...",
|
556 |
+
lines=10,
|
557 |
+
max_lines=50,
|
558 |
+
elem_classes="lyrics-scroll-box"
|
559 |
+
)
|
560 |
+
|
561 |
+
gen_from_lyrics_btn = gr.Button("Generate LRC (From Lyrics)", variant="primary")
|
562 |
+
|
563 |
+
gr.Examples(
|
564 |
+
examples=[
|
565 |
+
[
|
566 |
+
"acoustic folk happy",
|
567 |
+
"""I'm sitting here in the boring room\nIt's just another rainy Sunday afternoon"""
|
568 |
+
],
|
569 |
+
[
|
570 |
+
"electronic dance energetic",
|
571 |
+
"""We're living in a material world\nAnd I am a material girl"""
|
572 |
+
]
|
573 |
+
],
|
574 |
+
inputs=[tags_lyrics, lyrics_input],
|
575 |
+
label="Examples: Generate from Lyrics"
|
576 |
+
)
|
577 |
+
|
578 |
+
|
579 |
+
with gr.Column():
|
580 |
+
lrc_output = gr.Textbox(
|
581 |
+
label="Generated LRC",
|
582 |
+
placeholder="Timed lyrics will appear here",
|
583 |
+
lines=57,
|
584 |
+
elem_classes="lrc-output",
|
585 |
+
show_copy_button=True
|
586 |
+
)
|
587 |
+
|
588 |
+
# Bind functions
|
589 |
+
gen_from_theme_btn.click(
|
590 |
+
fn=R1_infer1,
|
591 |
+
inputs=[theme, tags_gen, language],
|
592 |
+
outputs=lrc_output
|
593 |
+
)
|
594 |
+
|
595 |
+
gen_from_lyrics_btn.click(
|
596 |
+
fn=R1_infer2,
|
597 |
+
inputs=[tags_lyrics, lyrics_input],
|
598 |
+
outputs=lrc_output
|
599 |
+
)
|
600 |
+
|
601 |
+
tabs.select(
|
602 |
+
lambda s: None,
|
603 |
+
None,
|
604 |
+
None
|
605 |
+
)
|
606 |
+
|
607 |
+
lyrics_btn.click(
|
608 |
+
fn=infer_music,
|
609 |
+
inputs=[lrc, audio_prompt, text_prompt, current_prompt_type, seed, randomize_seed, steps, cfg_strength, file_type, odeint_method, Music_Duration],
|
610 |
+
outputs=audio_output
|
611 |
+
)
|
612 |
+
|
613 |
+
|
614 |
+
if __name__ == "__main__":
|
615 |
+
demo.launch(share=True)
|