cocktailpeanut commited on
Commit
3fdd456
Β·
1 Parent(s): 0bb5645

text prompt support

Browse files
Files changed (2) hide show
  1. app.py +18 -4
  2. diffrhythm/infer/infer_utils.py +5 -1
app.py CHANGED
@@ -30,12 +30,18 @@ device=devicetorch.get(torch)
30
  cfm, tokenizer, muq, vae = prepare_model(device)
31
  #cfm = torch.compile(cfm)
32
 
 
 
 
 
 
 
33
  #@spaces.GPU
34
- def infer_music(lrc, ref_audio_path, steps, file_type, max_frames=2048):
35
 
36
  sway_sampling_coef = -1 if steps < 32 else None
37
  lrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)
38
- style_prompt = get_style_prompt(muq, ref_audio_path)
39
  negative_style_prompt = get_negative_style_prompt(device)
40
  latent_prompt = get_reference_latent(device, max_frames)
41
  print(">0")
@@ -191,7 +197,15 @@ with gr.Blocks(css=css) as demo:
191
  elem_classes="lyrics-scroll-box",
192
  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"""
193
  )
194
- audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./src/prompt/default.wav")
 
 
 
 
 
 
 
 
195
 
196
  with gr.Column():
197
 
@@ -333,7 +347,7 @@ with gr.Blocks(css=css) as demo:
333
 
334
  lyrics_btn.click(
335
  fn=infer_music,
336
- inputs=[lrc, audio_prompt, steps, file_type],
337
  outputs=audio_output
338
  )
339
 
 
30
  cfm, tokenizer, muq, vae = prepare_model(device)
31
  #cfm = torch.compile(cfm)
32
 
33
+ def clear_audio():
34
+ return gr.update(value=None) # Clears the audio field
35
+
36
+ def clear_text():
37
+ return gr.update(value="") # Clears the text field
38
+
39
  #@spaces.GPU
40
+ def infer_music(lrc, ref_audio_path, steps, file_type, prompt=None, max_frames=2048):
41
 
42
  sway_sampling_coef = -1 if steps < 32 else None
43
  lrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)
44
+ style_prompt = get_style_prompt(muq, ref_audio_path, prompt)
45
  negative_style_prompt = get_negative_style_prompt(device)
46
  latent_prompt = get_reference_latent(device, max_frames)
47
  print(">0")
 
197
  elem_classes="lyrics-scroll-box",
198
  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"""
199
  )
200
+ with gr.Group():
201
+ gr.HTML("<h5>Generate a song from</h5>")
202
+ with gr.Row():
203
+ with gr.Tab("Audio"):
204
+ audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./src/prompt/default.wav")
205
+ with gr.Tab("Text Description"):
206
+ text_prompt = gr.Textbox(label="Text Prompt", placeholder="Describe the song")
207
+ text_prompt.input(clear_audio, inputs=[], outputs=audio_prompt)
208
+ audio_prompt.input(clear_text, inputs=[], outputs=text_prompt)
209
 
210
  with gr.Column():
211
 
 
347
 
348
  lyrics_btn.click(
349
  fn=infer_music,
350
+ inputs=[lrc, audio_prompt, steps, file_type, text_prompt],
351
  outputs=audio_output
352
  )
353
 
diffrhythm/infer/infer_utils.py CHANGED
@@ -51,8 +51,12 @@ def get_negative_style_prompt(device):
51
 
52
  return vocal_stlye
53
 
54
- def get_style_prompt(model, wav_path):
 
55
  mulan = model
 
 
 
56
 
57
  ext = os.path.splitext(wav_path)[-1].lower()
58
  if ext == '.mp3':
 
51
 
52
  return vocal_stlye
53
 
54
+ @torch.no_grad()
55
+ def get_style_prompt(model, wav_path, prompt):
56
  mulan = model
57
+
58
+ if prompt is not None:
59
+ return mulan(texts=prompt).half()
60
 
61
  ext = os.path.splitext(wav_path)[-1].lower()
62
  if ext == '.mp3':