Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,9 @@ except FileNotFoundError:
|
|
44 |
|
45 |
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer'))
|
46 |
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer', 'descriptaudiocodec'))
|
|
|
|
|
|
|
47 |
import argparse
|
48 |
import numpy as np
|
49 |
import json
|
@@ -110,8 +113,17 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
110 |
model.to(device)
|
111 |
model.eval()
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
def generate_music(
|
114 |
-
# stage1_model="m-a-p/YuE-s1-7B-anneal-en-cot",
|
115 |
max_new_tokens=5,
|
116 |
run_n_segments=2,
|
117 |
genre_txt=None,
|
@@ -135,16 +147,6 @@ def generate_music(
|
|
135 |
max_new_tokens = max_new_tokens*100
|
136 |
stage1_output_dir = os.path.join(output_dir, f"stage1")
|
137 |
os.makedirs(stage1_output_dir, exist_ok=True)
|
138 |
-
|
139 |
-
mmtokenizer = _MMSentencePieceTokenizer("./mm_tokenizer_v0.2_hf/tokenizer.model")
|
140 |
-
|
141 |
-
codectool = CodecManipulator("xcodec", 0, 1)
|
142 |
-
model_config = OmegaConf.load(basic_model_config)
|
143 |
-
codec_model = eval(model_config.generator.name)(**model_config.generator.config).to(device)
|
144 |
-
parameter_dict = torch.load(resume_path, map_location='cpu')
|
145 |
-
codec_model.load_state_dict(parameter_dict['codec_model'])
|
146 |
-
codec_model.to(device)
|
147 |
-
codec_model.eval()
|
148 |
|
149 |
class BlockTokenRangeProcessor(LogitsProcessor):
|
150 |
def __init__(self, start_id, end_id):
|
@@ -388,7 +390,7 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments=2, max_new_tokens=
|
|
388 |
print(f"Output folder ensured at: {output_dir}")
|
389 |
|
390 |
empty_output_folder(output_dir)
|
391 |
-
|
392 |
# Execute the command
|
393 |
try:
|
394 |
music = generate_music(genre_txt=genre_txt_content, lyrics_txt=lyrics_txt_content, run_n_segments=num_segments, output_dir=output_dir, cuda_idx=0, max_new_tokens=max_new_tokens)
|
|
|
44 |
|
45 |
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer'))
|
46 |
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'xcodec_mini_infer', 'descriptaudiocodec'))
|
47 |
+
|
48 |
+
# don't change above code
|
49 |
+
|
50 |
import argparse
|
51 |
import numpy as np
|
52 |
import json
|
|
|
113 |
model.to(device)
|
114 |
model.eval()
|
115 |
|
116 |
+
mmtokenizer = _MMSentencePieceTokenizer("./mm_tokenizer_v0.2_hf/tokenizer.model")
|
117 |
+
|
118 |
+
codectool = CodecManipulator("xcodec", 0, 1)
|
119 |
+
model_config = OmegaConf.load(basic_model_config)
|
120 |
+
codec_model = eval(model_config.generator.name)(**model_config.generator.config).to(device)
|
121 |
+
parameter_dict = torch.load(resume_path, map_location='cpu')
|
122 |
+
codec_model.load_state_dict(parameter_dict['codec_model'])
|
123 |
+
codec_model.to(device)
|
124 |
+
codec_model.eval()
|
125 |
+
|
126 |
def generate_music(
|
|
|
127 |
max_new_tokens=5,
|
128 |
run_n_segments=2,
|
129 |
genre_txt=None,
|
|
|
147 |
max_new_tokens = max_new_tokens*100
|
148 |
stage1_output_dir = os.path.join(output_dir, f"stage1")
|
149 |
os.makedirs(stage1_output_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
class BlockTokenRangeProcessor(LogitsProcessor):
|
152 |
def __init__(self, start_id, end_id):
|
|
|
390 |
print(f"Output folder ensured at: {output_dir}")
|
391 |
|
392 |
empty_output_folder(output_dir)
|
393 |
+
|
394 |
# Execute the command
|
395 |
try:
|
396 |
music = generate_music(genre_txt=genre_txt_content, lyrics_txt=lyrics_txt_content, run_n_segments=num_segments, output_dir=output_dir, cuda_idx=0, max_new_tokens=max_new_tokens)
|