waytan22 commited on
Commit
ef01ecd
·
1 Parent(s): 0a1e140
app.py CHANGED
@@ -18,7 +18,7 @@ print("Successful downloaded model.")
18
 
19
  from levo_inference import LeVoInference
20
 
21
- model = LeVoInference(op.join(APP_DIR, "conf/infer.yaml"))
22
 
23
  EXAMPLE_DESC = """female, dark, pop, sad, piano and drums, the bpm is 125."""
24
  EXAMPLE_LYRICS = """
@@ -62,10 +62,11 @@ with open('conf/vocab.yaml', 'r', encoding='utf-8') as file:
62
 
63
  # 模拟歌曲生成函数
64
  def generate_song(description, lyric, prompt_audio=None, cfg_coef=None, temperature=None, top_k=None, progress=gr.Progress(track_tqdm=True)):
65
- global model
 
66
  params = {'cfg_coef':cfg_coef, 'temperature':temperature, 'top_k':top_k}
67
  params = {k:v for k,v in params.items() if v is not None}
68
- sample_rate = model.cfg.sample_rate
69
 
70
  # 生成过程
71
  print(f"Generating song with description: {description}")
@@ -77,18 +78,17 @@ def generate_song(description, lyric, prompt_audio=None, cfg_coef=None, temperat
77
  lyric = lyric.replyricace(f"{s}\n", f"{s} ")
78
  lyric = lyric.replyricace("\n", "")
79
  lyric = lyric.replyricace(". ; ", " ; ")
80
- print(lyric)
81
 
82
  # 适配prompt
83
  if prompt_audio is not None:
84
  print("Using prompt audio for generation")
85
  else:
86
- prompt_audio = op.join(APP_DIR, 'sample/19_2-又是一天过去,烦恼如影随形10s.wav')
87
 
88
  progress(0.0, "Start Generation")
89
  start = time.time()
90
 
91
- audio_data = model(lyric, description, prompt_audio, params).cpu().permute(1, 0).float().numpy()
92
 
93
  end = time.time()
94
 
 
18
 
19
  from levo_inference import LeVoInference
20
 
21
+ MODEL = LeVoInference(op.join(APP_DIR, "conf/infer.yaml"))
22
 
23
  EXAMPLE_DESC = """female, dark, pop, sad, piano and drums, the bpm is 125."""
24
  EXAMPLE_LYRICS = """
 
62
 
63
  # 模拟歌曲生成函数
64
  def generate_song(description, lyric, prompt_audio=None, cfg_coef=None, temperature=None, top_k=None, progress=gr.Progress(track_tqdm=True)):
65
+ global MODEL
66
+ global STRUCTS
67
  params = {'cfg_coef':cfg_coef, 'temperature':temperature, 'top_k':top_k}
68
  params = {k:v for k,v in params.items() if v is not None}
69
+ sample_rate = MODEL.cfg.sample_rate
70
 
71
  # 生成过程
72
  print(f"Generating song with description: {description}")
 
78
  lyric = lyric.replyricace(f"{s}\n", f"{s} ")
79
  lyric = lyric.replyricace("\n", "")
80
  lyric = lyric.replyricace(". ; ", " ; ")
 
81
 
82
  # 适配prompt
83
  if prompt_audio is not None:
84
  print("Using prompt audio for generation")
85
  else:
86
+ prompt_audio = op.join(APP_DIR, 'sample/prompt.wav')
87
 
88
  progress(0.0, "Start Generation")
89
  start = time.time()
90
 
91
+ audio_data = MODEL(lyric, description, prompt_audio, params).cpu().permute(1, 0).float().numpy()
92
 
93
  end = time.time()
94
 
codeclm/models/lm_levo.py CHANGED
@@ -5,6 +5,7 @@ import random
5
  import torch.nn as nn
6
  import typing as tp
7
  import torch.nn.functional as F
 
8
  from dataclasses import dataclass
9
  from codeclm.models.levo import CausalLM, LlamaConfig
10
  from codeclm.modules.streaming import StreamingModule
@@ -421,7 +422,7 @@ class LmModel(StreamingModule):
421
  with self.streaming():
422
  gen_sequence_len = gen_sequence.shape[-1] # gen_sequence shape is [B, K, S]
423
  prev_offset = 0
424
- for offset in range(start_offset_sequence, gen_sequence_len):
425
  # get current sequence (note that the streaming API is providing the caching over previous offsets)
426
  curr_sequence = gen_sequence[..., prev_offset:offset]
427
  curr_mask = mask[None, ..., prev_offset:offset].expand(B, -1, -1)
 
5
  import torch.nn as nn
6
  import typing as tp
7
  import torch.nn.functional as F
8
+ from tqdm import tqdm
9
  from dataclasses import dataclass
10
  from codeclm.models.levo import CausalLM, LlamaConfig
11
  from codeclm.modules.streaming import StreamingModule
 
422
  with self.streaming():
423
  gen_sequence_len = gen_sequence.shape[-1] # gen_sequence shape is [B, K, S]
424
  prev_offset = 0
425
+ for offset in tqdm(range(start_offset_sequence, gen_sequence_len)):
426
  # get current sequence (note that the streaming API is providing the caching over previous offsets)
427
  curr_sequence = gen_sequence[..., prev_offset:offset]
428
  curr_mask = mask[None, ..., prev_offset:offset].expand(B, -1, -1)
sample/lyric.jsonl CHANGED
@@ -1 +1 @@
1
- {"idx": "01_节奏蓝调", "descriptions": "female, dark, pop, sad, piano and drums, the bpm is 125.", "gt_lyric": "[intro-short] ; [verse] 夜晚的街灯闪烁.我漫步在熟悉的角落.回忆像潮水般涌来.你的笑容如此清晰.在心头无法抹去.那些曾经的甜蜜.如今只剩我独自回忆 ; [bridge] 手机屏幕亮起.是你发来的消息.简单的几个字.却让我泪流满面.曾经的拥抱温暖.如今却变得遥远.我多想回到从前.重新拥有你的陪伴 ; [chorus] 回忆的温度还在.你却已不在.我的心被爱填满.却又被思念刺痛.R&B的节奏奏响.我的心却在流浪.没有你的日子.我该如何继续向前 ; [outro-short]", "prompt_audio_path": "sample/19_2-又是一天过去,烦恼如影随形10s.wav"}
 
1
+ {"idx": "01_节奏蓝调", "descriptions": "female, dark, pop, sad, piano and drums, the bpm is 125.", "gt_lyric": "[intro-short] ; [verse] 夜晚的街灯闪烁.我漫步在熟悉的角落.回忆像潮水般涌来.你的笑容如此清晰.在心头无法抹去.那些曾经的甜蜜.如今只剩我独自回忆 ; [bridge] 手机屏幕亮起.是你发来的消息.简单的几个字.却让我泪流满面.曾经的拥抱温暖.如今却变得遥远.我多想回到从前.重新拥有你的陪伴 ; [chorus] 回忆的温度还在.你却已不在.我的心被爱填满.却又被思念刺痛.R&B的节奏奏响.我的心却在流浪.没有你的日子.我该如何继续向前 ; [outro-short]", "prompt_audio_path": "sample/prompt.wav"}
sample/{19_2-又是一天过去,烦恼如影随形10s.wav → prompt.wav} RENAMED
File without changes