Spaces:
Running
Running
cpu test
Browse filesFiles changed (2)
- app.py+24-9
- diffrhythm/infer/infer.py+6-5
21 unmodified lines222324252627282930313233343536375 unmodified lines434445464748101 unmodified lines15015115215315415554 unmodified lines21021121221321421521689 unmodified lines30630730830931031131221 unmodified lines)from diffrhythm.infer.infer import inferencedevice='cuda'cfm, tokenizer, muq, vae = prepare_model(device)cfm = torch.compile(cfm)def infer_music(lrc, ref_audio_path, max_frames=2048, device='cuda'):# lrc_list = lrc.split("\n")# print(lrc_list)# return "./gift_of_the_world.wav"lrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)style_prompt = get_style_prompt(muq, ref_audio_path)negative_style_prompt = get_negative_style_prompt(device)5 unmodified linesduration=max_frames,style_prompt=style_prompt,negative_style_prompt=negative_style_prompt,start_time=start_time)return generated_song101 unmodified linesaudio_prompt = gr.Audio(label="Audio Prompt", type="filepath")with gr.Column():lyrics_btn = gr.Button("Submit", variant="primary")audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")54 unmodified lines[01:24.20]Your laughter spins aurora threads[01:28.65]Weaving dawn through featherbed"""]],inputs=[lrc], # 只绑定到歌词输入label="Lrc Examples",examples_per_page=2)89 unmodified lineslyrics_btn.click(fn=infer_music,inputs=[lrc, audio_prompt],outputs=audio_output)21 unmodified lines222324252627282930313233345 unmodified lines4041424344454647101 unmodified lines14915015115215315415515615715815916016116216316416516616716816917054 unmodified lines22522622722822923023189 unmodified lines32132232332432532632721 unmodified lines)from diffrhythm.infer.infer import inferencedevice='cpu'cfm, tokenizer, muq, vae = prepare_model(device)cfm = torch.compile(cfm)def infer_music(lrc, ref_audio_path, steps, sway_sampling_coef_bool, max_frames=2048, device='cpu'):sway_sampling_coef = -1 if sway_sampling_coef_bool else Nonelrc_prompt, start_time = get_lrc_token(lrc, tokenizer, device)style_prompt = get_style_prompt(muq, ref_audio_path)negative_style_prompt = get_negative_style_prompt(device)5 unmodified linesduration=max_frames,style_prompt=style_prompt,negative_style_prompt=negative_style_prompt,steps=steps,sway_sampling_coef=sway_sampling_coef,start_time=start_time)return generated_song101 unmodified linesaudio_prompt = gr.Audio(label="Audio Prompt", type="filepath")with gr.Column():steps = gr.Slider(minimum=10,maximum=40,value=32,step=1,label="Diffusion Steps",interactive=True,elem_id="step_slider")sway_sampling_coef_bool = gr.Radio(choices=[("False", False), ("True", True)],label="Use sway_sampling_coef",value=False,interactive=True,elem_classes="horizontal-radio")lyrics_btn = gr.Button("Submit", variant="primary")audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")54 unmodified lines[01:24.20]Your laughter spins aurora threads[01:28.65]Weaving dawn through featherbed"""]],inputs=[lrc],label="Lrc Examples",examples_per_page=2)89 unmodified lineslyrics_btn.click(fn=infer_music,inputs=[lrc, audio_prompt, steps, sway_sampling_coef_bool],outputs=audio_output)
71 unmodified lines727374757677782 unmodified lines818283848586878811 unmodified lines10010110210310410510610710810971 unmodified linesy_final[:,:,t_start:t_end] = y_chunk[:,:,chunk_start:chunk_end]return y_finaldef inference(cfm_model, vae_model, cond, text, duration, style_prompt, negative_style_prompt, start_time, steps):# import pdb; pdb.set_trace()with torch.inference_mode():generated, _ = cfm_model.sample(2 unmodified linesduration=duration,style_prompt=style_prompt,negative_style_prompt=negative_style_prompt,steps=32,cfg_strength=4.0,start_time=start_time)11 unmodified linesif __name__ == "__main__":parser = argparse.ArgumentParser()parser.add_argument('--lrc-path', type=str, default="/home/node59_tmpdata3/hkchen/DiffRhythm/diffrhythm/diffrhythm/infer/example/eg.lrc") # lyrics of target songparser.add_argument('--ref-audio-path', type=str, default="/home/node59_tmpdata3/hkchen/DiffRhythm/diffrhythm/diffrhythm/infer/example/eg.mp3") # reference audio as style prompt for target songparser.add_argument('--audio-length', type=int, default=95) # length of target songparser.add_argument('--output-dir', type=str, default="/home/node59_tmpdata3/hkchen/DiffRhythm/diffrhythm/diffrhythm/infer/example/output")args = parser.parse_args()device = 'cuda'71 unmodified lines727374757677782 unmodified lines81828384858687888911 unmodified lines10110210310410510610710810911071 unmodified linesy_final[:,:,t_start:t_end] = y_chunk[:,:,chunk_start:chunk_end]return y_finaldef inference(cfm_model, vae_model, cond, text, duration, style_prompt, negative_style_prompt, steps, sway_sampling_coef, start_time):# import pdb; pdb.set_trace()with torch.inference_mode():generated, _ = cfm_model.sample(2 unmodified linesduration=duration,style_prompt=style_prompt,negative_style_prompt=negative_style_prompt,steps=steps,cfg_strength=4.0,sway_sampling_coef=sway_sampling_coef,start_time=start_time)11 unmodified linesif __name__ == "__main__":parser = argparse.ArgumentParser()parser.add_argument('--lrc-path', type=str, default="example/eg.lrc") # lyrics of target songparser.add_argument('--ref-audio-path', type=str, default="example/eg.mp3") # reference audio as style prompt for target songparser.add_argument('--audio-length', type=int, default=95) # length of target songparser.add_argument('--output-dir', type=str, default="example/output")args = parser.parse_args()device = 'cuda'
app.py+24-9
diffrhythm/infer/infer.py+6-5