Spaces:
Running
on
Zero
Running
on
Zero
readme
Browse files- README.md +1 -1
- app.py +26 -14
- diffrhythm/infer/infer.py +14 -19
- diffrhythm/infer/infer_utils.py +1 -1
- prompt/gift_of_the_world.wav +0 -0
- prompt/little_happiness.wav +0 -0
- prompt/little_talks.wav +0 -0
- prompt/ltwyl.wav +0 -0
- prompt/most_beautiful_expectation.wav +0 -0
- src/DiffRhythm.jpg +0 -0
- {prompt → src}/negative_prompt.npy +0 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: DiffRhythm
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: DiffRhythm
|
3 |
+
emoji: 🎶
|
4 |
colorFrom: green
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
CHANGED
@@ -29,7 +29,7 @@ cfm, tokenizer, muq, vae = prepare_model(device)
|
|
29 |
cfm = torch.compile(cfm)
|
30 |
|
31 |
@spaces.GPU
|
32 |
-
def infer_music(lrc, ref_audio_path, steps, max_frames=2048, device='cuda'):
|
33 |
|
34 |
sway_sampling_coef = -1 if steps < 32 else None
|
35 |
lrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)
|
@@ -45,7 +45,8 @@ def infer_music(lrc, ref_audio_path, steps, max_frames=2048, device='cuda'):
|
|
45 |
negative_style_prompt=negative_style_prompt,
|
46 |
steps=steps,
|
47 |
sway_sampling_coef=sway_sampling_coef,
|
48 |
-
start_time=start_time
|
|
|
49 |
)
|
50 |
return generated_song
|
51 |
|
@@ -174,12 +175,16 @@ with gr.Blocks(css=css) as demo:
|
|
174 |
lines=12,
|
175 |
max_lines=50,
|
176 |
elem_classes="lyrics-scroll-box",
|
177 |
-
value="""[00:
|
178 |
)
|
179 |
-
audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./prompt/
|
180 |
|
181 |
with gr.Column():
|
182 |
-
|
|
|
|
|
|
|
|
|
183 |
minimum=10,
|
184 |
maximum=100,
|
185 |
value=32,
|
@@ -188,16 +193,23 @@ with gr.Blocks(css=css) as demo:
|
|
188 |
interactive=True,
|
189 |
elem_id="step_slider"
|
190 |
)
|
191 |
-
|
192 |
-
audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")
|
193 |
|
194 |
|
195 |
|
196 |
gr.Examples(
|
197 |
examples=[
|
198 |
-
["./prompt/
|
199 |
-
["./prompt/
|
200 |
-
["./prompt/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
],
|
202 |
inputs=[audio_prompt],
|
203 |
label="Audio Examples",
|
@@ -207,9 +219,10 @@ with gr.Blocks(css=css) as demo:
|
|
207 |
|
208 |
gr.Examples(
|
209 |
examples=[
|
210 |
-
["""[00:
|
211 |
-
["""[00:
|
212 |
],
|
|
|
213 |
inputs=[lrc],
|
214 |
label="Lrc Examples",
|
215 |
examples_per_page=2,
|
@@ -227,7 +240,6 @@ with gr.Blocks(css=css) as demo:
|
|
227 |
gr.Markdown("### Method 1: Generate from Theme")
|
228 |
theme = gr.Textbox(label="theme", placeholder="Enter song theme, e.g. Love and Heartbreak")
|
229 |
tags_gen = gr.Textbox(label="tags", placeholder="Example: male pop confidence healing")
|
230 |
-
# language = gr.Dropdown(["zh", "en"], label="language", value="en")
|
231 |
language = gr.Radio(["zh", "en"], label="Language", value="en")
|
232 |
gen_from_theme_btn = gr.Button("Generate LRC (From Theme)", variant="primary")
|
233 |
|
@@ -307,7 +319,7 @@ with gr.Blocks(css=css) as demo:
|
|
307 |
|
308 |
lyrics_btn.click(
|
309 |
fn=infer_music,
|
310 |
-
inputs=[lrc, audio_prompt, steps],
|
311 |
outputs=audio_output
|
312 |
)
|
313 |
|
|
|
29 |
cfm = torch.compile(cfm)
|
30 |
|
31 |
@spaces.GPU
|
32 |
+
def infer_music(lrc, ref_audio_path, steps, file_type, max_frames=2048, device='cuda'):
|
33 |
|
34 |
sway_sampling_coef = -1 if steps < 32 else None
|
35 |
lrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)
|
|
|
45 |
negative_style_prompt=negative_style_prompt,
|
46 |
steps=steps,
|
47 |
sway_sampling_coef=sway_sampling_coef,
|
48 |
+
start_time=start_time,
|
49 |
+
file_type=file_type
|
50 |
)
|
51 |
return generated_song
|
52 |
|
|
|
175 |
lines=12,
|
176 |
max_lines=50,
|
177 |
elem_classes="lyrics-scroll-box",
|
178 |
+
value="""[00:10.00]Moonlight spills through broken blinds\n[00:13.20]Your shadow dances on the dashboard shrine\n[00:16.85]Neon ghosts in gasoline rain\n[00:20.40]I hear your laughter down the midnight train\n[00:24.15]Static whispers through frayed wires\n[00:27.65]Guitar strings hum our cathedral choirs\n[00:31.30]Flicker screens show reruns of June\n[00:34.90]I'm drowning in this mercury lagoon\n[00:38.55]Electric veins pulse through concrete skies\n[00:42.10]Your name echoes in the hollow where my heartbeat lies\n[00:45.75]We're satellites trapped in parallel light\n[00:49.25]Burning through the atmosphere of endless night\n[01:00.00]Dusty vinyl spins reverse\n[01:03.45]Our polaroid timeline bleeds through the verse\n[01:07.10]Telescope aimed at dead stars\n[01:10.65]Still tracing constellations through prison bars\n[01:14.30]Electric veins pulse through concrete skies\n[01:17.85]Your name echoes in the hollow where my heartbeat lies\n[01:21.50]We're satellites trapped in parallel light\n[01:25.05]Burning through the atmosphere of endless night\n[02:10.00]Clockwork gears grind moonbeams to rust\n[02:13.50]Our fingerprint smudged by interstellar dust\n[02:17.15]Velvet thunder rolls through my veins\n[02:20.70]Chasing phantom trains through solar plane\n[02:24.35]Electric veins pulse through concrete skies\n[02:27.90]Your name echoes in the hollow where my heartbeat lies"""
|
179 |
)
|
180 |
+
audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./src/prompt/default.wav")
|
181 |
|
182 |
with gr.Column():
|
183 |
+
|
184 |
+
lyrics_btn = gr.Button("Submit", variant="primary")
|
185 |
+
audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")
|
186 |
+
with gr.Accordion("Advanced Settings", open=False):
|
187 |
+
steps = gr.Slider(
|
188 |
minimum=10,
|
189 |
maximum=100,
|
190 |
value=32,
|
|
|
193 |
interactive=True,
|
194 |
elem_id="step_slider"
|
195 |
)
|
196 |
+
file_type = gr.Dropdown(["wav", "mp3", "ogg"], label="Music File Type", value="wav")
|
|
|
197 |
|
198 |
|
199 |
|
200 |
gr.Examples(
|
201 |
examples=[
|
202 |
+
["./src/prompt/pop_cn.wav"],
|
203 |
+
["./src/prompt/pop_en.wav"],
|
204 |
+
["./src/prompt/rock_cn.wav"],
|
205 |
+
["./src/prompt/rock_en.wav"],
|
206 |
+
["./src/prompt/country_cn.wav"],
|
207 |
+
["./src/prompt/country_en.wav"],
|
208 |
+
["./src/prompt/classic_cn.wav"],
|
209 |
+
["./src/prompt/classic_en.wav"],
|
210 |
+
["./src/prompt/jazz_cn.wav"],
|
211 |
+
["./src/prompt/jazz_en.wav"],
|
212 |
+
["./src/prompt/default.wav"]
|
213 |
],
|
214 |
inputs=[audio_prompt],
|
215 |
label="Audio Examples",
|
|
|
219 |
|
220 |
gr.Examples(
|
221 |
examples=[
|
222 |
+
["""[00:10.00]Moonlight spills through broken blinds\n[00:13.20]Your shadow dances on the dashboard shrine\n[00:16.85]Neon ghosts in gasoline rain\n[00:20.40]I hear your laughter down the midnight train\n[00:24.15]Static whispers through frayed wires\n[00:27.65]Guitar strings hum our cathedral choirs\n[00:31.30]Flicker screens show reruns of June\n[00:34.90]I'm drowning in this mercury lagoon\n[00:38.55]Electric veins pulse through concrete skies\n[00:42.10]Your name echoes in the hollow where my heartbeat lies\n[00:45.75]We're satellites trapped in parallel light\n[00:49.25]Burning through the atmosphere of endless night\n[01:00.00]Dusty vinyl spins reverse\n[01:03.45]Our polaroid timeline bleeds through the verse\n[01:07.10]Telescope aimed at dead stars\n[01:10.65]Still tracing constellations through prison bars\n[01:14.30]Electric veins pulse through concrete skies\n[01:17.85]Your name echoes in the hollow where my heartbeat lies\n[01:21.50]We're satellites trapped in parallel light\n[01:25.05]Burning through the atmosphere of endless night\n[02:10.00]Clockwork gears grind moonbeams to rust\n[02:13.50]Our fingerprint smudged by interstellar dust\n[02:17.15]Velvet thunder rolls through my veins\n[02:20.70]Chasing phantom trains through solar plane\n[02:24.35]Electric veins pulse through concrete skies\n[02:27.90]Your name echoes in the hollow where my heartbeat lies"""],
|
223 |
+
["""[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"""]
|
224 |
],
|
225 |
+
|
226 |
inputs=[lrc],
|
227 |
label="Lrc Examples",
|
228 |
examples_per_page=2,
|
|
|
240 |
gr.Markdown("### Method 1: Generate from Theme")
|
241 |
theme = gr.Textbox(label="theme", placeholder="Enter song theme, e.g. Love and Heartbreak")
|
242 |
tags_gen = gr.Textbox(label="tags", placeholder="Example: male pop confidence healing")
|
|
|
243 |
language = gr.Radio(["zh", "en"], label="Language", value="en")
|
244 |
gen_from_theme_btn = gr.Button("Generate LRC (From Theme)", variant="primary")
|
245 |
|
|
|
319 |
|
320 |
lyrics_btn.click(
|
321 |
fn=infer_music,
|
322 |
+
inputs=[lrc, audio_prompt, steps, file_type],
|
323 |
outputs=audio_output
|
324 |
)
|
325 |
|
diffrhythm/infer/infer.py
CHANGED
@@ -74,9 +74,8 @@ def decode_audio(latents, vae_model, chunked=False, overlap=32, chunk_size=128):
|
|
74 |
y_final[:,:,t_start:t_end] = y_chunk[:,:,chunk_start:chunk_end]
|
75 |
return y_final
|
76 |
|
77 |
-
def inference(cfm_model, vae_model, cond, text, duration, style_prompt, negative_style_prompt, steps, sway_sampling_coef, start_time):
|
78 |
-
|
79 |
-
s_t = time.time()
|
80 |
with torch.inference_mode():
|
81 |
generated, _ = cfm_model.sample(
|
82 |
cond=cond,
|
@@ -92,28 +91,24 @@ def inference(cfm_model, vae_model, cond, text, duration, style_prompt, negative
|
|
92 |
|
93 |
generated = generated.to(torch.float32)
|
94 |
latent = generated.transpose(1, 2) # [b d t]
|
95 |
-
e_t = time.time()
|
96 |
-
print(f"**** cfm time : {e_t-s_t} ****")
|
97 |
-
print(latent.mean(), latent.min(), latent.max(), latent.std())
|
98 |
output = decode_audio(latent, vae_model, chunked=False)
|
99 |
-
print(output.mean(), output.min(), output.max(), output.std())
|
100 |
|
101 |
# Rearrange audio batch to a single sequence
|
102 |
output = rearrange(output, "b d n -> d (b n)")
|
103 |
output_tensor = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).cpu()
|
104 |
output_np = output_tensor.numpy().T.astype(np.float32)
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
|
119 |
if __name__ == "__main__":
|
|
|
74 |
y_final[:,:,t_start:t_end] = y_chunk[:,:,chunk_start:chunk_end]
|
75 |
return y_final
|
76 |
|
77 |
+
def inference(cfm_model, vae_model, cond, text, duration, style_prompt, negative_style_prompt, steps, sway_sampling_coef, start_time, file_type):
|
78 |
+
|
|
|
79 |
with torch.inference_mode():
|
80 |
generated, _ = cfm_model.sample(
|
81 |
cond=cond,
|
|
|
91 |
|
92 |
generated = generated.to(torch.float32)
|
93 |
latent = generated.transpose(1, 2) # [b d t]
|
|
|
|
|
|
|
94 |
output = decode_audio(latent, vae_model, chunked=False)
|
|
|
95 |
|
96 |
# Rearrange audio batch to a single sequence
|
97 |
output = rearrange(output, "b d n -> d (b n)")
|
98 |
output_tensor = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).cpu()
|
99 |
output_np = output_tensor.numpy().T.astype(np.float32)
|
100 |
+
|
101 |
+
if file_type == 'wav':
|
102 |
+
return (44100, output_np)
|
103 |
+
else:
|
104 |
+
buffer = io.BytesIO()
|
105 |
+
output_np = np.int16(output_np * 2**15)
|
106 |
+
song = pydub.AudioSegment(output_np.tobytes(), frame_rate=44100, sample_width=2, channels=2)
|
107 |
+
if file_type == 'mp3':
|
108 |
+
song.export(buffer, format="mp3", bitrate="320k")
|
109 |
+
else:
|
110 |
+
song.export(buffer, format="ogg", bitrate="320k")
|
111 |
+
return buffer.getvalue()
|
112 |
|
113 |
|
114 |
if __name__ == "__main__":
|
diffrhythm/infer/infer_utils.py
CHANGED
@@ -43,7 +43,7 @@ def get_reference_latent(device, max_frames):
|
|
43 |
return torch.zeros(1, max_frames, 64).to(device)
|
44 |
|
45 |
def get_negative_style_prompt(device):
|
46 |
-
file_path = "./
|
47 |
vocal_stlye = np.load(file_path)
|
48 |
|
49 |
vocal_stlye = torch.from_numpy(vocal_stlye).to(device) # [1, 512]
|
|
|
43 |
return torch.zeros(1, max_frames, 64).to(device)
|
44 |
|
45 |
def get_negative_style_prompt(device):
|
46 |
+
file_path = "./src/negative_prompt.npy"
|
47 |
vocal_stlye = np.load(file_path)
|
48 |
|
49 |
vocal_stlye = torch.from_numpy(vocal_stlye).to(device) # [1, 512]
|
prompt/gift_of_the_world.wav
DELETED
Binary file (960 kB)
|
|
prompt/little_happiness.wav
DELETED
Binary file (960 kB)
|
|
prompt/little_talks.wav
DELETED
Binary file (960 kB)
|
|
prompt/ltwyl.wav
DELETED
Binary file (882 kB)
|
|
prompt/most_beautiful_expectation.wav
DELETED
Binary file (960 kB)
|
|
src/DiffRhythm.jpg
ADDED
![]() |
{prompt → src}/negative_prompt.npy
RENAMED
File without changes
|