xscdvfaaqqq/DiffRhythm
0
1import gradio as gr2from openai import OpenAI3import requests4import json5# from volcenginesdkarkruntime import Ark6import torch7import torchaudio8from einops import rearrange9import argparse10import json11import os12import spaces13from tqdm import tqdm14import random15import numpy as np16import sys17import base6418from diffrhythm.infer.infer_utils import (19 get_reference_latent,20 get_lrc_token,21 get_audio_style_prompt,22 get_text_style_prompt,23 prepare_model,24 get_negative_style_prompt25)26from diffrhythm.infer.infer import inference27 28MAX_SEED = np.iinfo(np.int32).max29device='cuda'30cfm, tokenizer, muq, vae, eval_model, eval_muq = prepare_model(max_frames=6144, device=device)31cfm = torch.compile(cfm)32 33@spaces.GPU34def infer_music(lrc, ref_audio_path, text_prompt, current_prompt_type, seed=42, 35 randomize_seed=False, steps=32, cfg_strength=4.0, file_type='wav', 36 odeint_method='euler', preference_infer="quality first", Music_Duration=285, edit=False, 37 edit_segments=None, device='cuda'):38 max_frames = 2048 if Music_Duration == 95 else 614439 sway_sampling_coef = -1 if steps < 32 else None40 if randomize_seed:41 seed = random.randint(0, MAX_SEED)42 torch.manual_seed(seed)43 vocal_flag = False44 try:45 lrc_prompt, start_time, end_frame, song_duration = get_lrc_token(max_frames, lrc, tokenizer, Music_Duration, device)46 if ref_audio_path is not None:47 style_prompt, vocal_flag = get_audio_style_prompt(muq, ref_audio_path)48 else:49 style_prompt = get_text_style_prompt(muq, text_prompt)50 except Exception as e:51 raise gr.Error(f"Error: {str(e)}")52 negative_style_prompt = get_negative_style_prompt(device)53 latent_prompt, pred_frames = get_reference_latent(device, max_frames, edit, edit_segments, ref_audio_path, vae)54 55 if preference_infer == "quality first":56 batch_infer_num = 557 else:58 batch_infer_num = 159 60 steps = int(steps)61 generated_song = inference(cfm_model=cfm, 62 vae_model=vae, 63 eval_model=eval_model,64 eval_muq=eval_muq,65 cond=latent_prompt, 66 text=lrc_prompt, 67 duration=end_frame, 68 style_prompt=style_prompt,69 negative_style_prompt=negative_style_prompt,70 steps=steps,71 cfg_strength=cfg_strength,72 sway_sampling_coef=sway_sampling_coef,73 start_time=start_time,74 file_type=file_type,75 vocal_flag=vocal_flag,76 odeint_method=odeint_method,77 pred_frames=pred_frames,78 batch_infer_num=batch_infer_num,79 song_duration=song_duration80 )81 82 # 🌟 新增:将生成的音频转存到 Gradio 完全信任的临时目录83 # if isinstance(generated_song, str) and os.path.exists(generated_song):84 # ext = os.path.splitext(generated_song)[-1] # 获取后缀,如 .mp385 # temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=ext)86 # shutil.copy(generated_song, temp_file.name)87 # return temp_file.name88 return generated_song89 90def R1_infer1(theme, tags_gen, language):91 try:92 client = OpenAI(api_key=os.getenv('HS_DP_API'), base_url = "https://ark.cn-beijing.volces.com/api/v3")93 94 llm_prompt = """95 请围绕"{theme}"主题生成一首符合"{tags}"风格的语言为{language}的完整歌词。严格遵循以下要求:96 97 ### **强制格式规则**98 1. **仅输出时间戳和歌词**,禁止任何括号、旁白、段落标记(如副歌、间奏、尾奏等注释)。99 2. 每行格式必须为 `[mm:ss.xx]歌词内容`,时间戳与歌词间无空格,歌词内容需完整连贯。100 3. 时间戳需自然分布,**第一句歌词起始时间不得为 [00:00.00]**,需考虑前奏空白。101 102 ### **内容与结构要求**103 1. 歌词应富有变化,使情绪递进,整体连贯有层次感。**每行歌词长度应自然变化**,切勿长度一致,导致很格式化。104 2. **时间戳分配应根据歌曲的标签、歌词的情感、节奏来合理推测**,而非机械地按照歌词长度分配。105 3. 间奏/尾奏仅通过时间空白体现(如从 [02:30.00] 直接跳至 [02:50.00]),**无需文字描述**。106 107 ### **负面示例(禁止出现)**108 - 错误:[01:30.00](钢琴间奏)109 - 错误:[02:00.00][副歌]110 - 错误:空行、换行符、注释111 """112 113 response = client.chat.completions.create(114 model="ep-20250304144033-nr9wl",115 messages=[116 {"role": "system", "content": "You are a professional musician who has been invited to make music-related comments."},117 {"role": "user", "content": llm_prompt.format(theme=theme, tags=tags_gen, language=language)},118 ],119 stream=False120 )121 122 info = response.choices[0].message.content123 124 return info125 126 except requests.exceptions.RequestException as e:127 print(f'请求出错: {e}')128 return {}129 130 131 132def R1_infer2(tags_lyrics, lyrics_input):133 client = OpenAI(api_key=os.getenv('HS_DP_API'), base_url = "https://ark.cn-beijing.volces.com/api/v3")134 135 llm_prompt = """136 {lyrics_input}这是一首歌的歌词,每一行是一句歌词,{tags_lyrics}是我希望这首歌的风格,我现在想要给这首歌的每一句歌词打时间戳得到LRC,我希望时间戳分配应根据歌曲的标签、歌词的情感、节奏来合理推测,而非机械地按照歌词长度分配。第一句歌词的时间戳应考虑前奏长度,避免歌词从 `[00:00.00]` 直接开始。严格按照 LRC 格式输出歌词,每行格式为 `[mm:ss.xx]歌词内容`。最后的结果只输出LRC,不需要其他的解释。137 """138 139 response = client.chat.completions.create(140 model="ep-20250304144033-nr9wl",141 messages=[142 {"role": "system", "content": "You are a professional musician who has been invited to make music-related comments."},143 {"role": "user", "content": llm_prompt.format(lyrics_input=lyrics_input, tags_lyrics=tags_lyrics)},144 ],145 stream=False146 )147 148 info = response.choices[0].message.content149 150 return info151 152css = """153/* 固定文本域高度并强制滚动条 */154.lyrics-scroll-box textarea {155 height: 405px !important; /* 固定高度 */156 max-height: 500px !important; /* 最大高度 */157 overflow-y: auto !important; /* 垂直滚动 */158 white-space: pre-wrap; /* 保留换行 */159 line-height: 1.5; /* 行高优化 */160}161 162.gr-examples {163 background: transparent !important;164 border: 1px solid #e0e0e0 !important;165 border-radius: 8px;166 margin: 1rem 0 !important;167 padding: 1rem !important;168}169 170"""171 172 173with gr.Blocks(css=css) as demo:174 gr.HTML(f"""175 <div style="display: flex; align-items: center;">176 <img src='https://raw.githubusercontent.com/ASLP-lab/DiffRhythm/refs/heads/main/src/DiffRhythm_logo.jpg' 177 style='width: 200px; height: 40%; display: block; margin: 0 auto 20px;'>178 </div>179 180 <div style="flex: 1; text-align: center;">181 <div style="font-size: 2em; font-weight: bold; text-align: center; margin-bottom: 5px">182 Di♪♪Rhythm (谛韵)183 </div>184 <div style="display:flex; justify-content: center; column-gap:4px;">185 <a href="https://arxiv.org/abs/2503.01183">186 <img src='https://img.shields.io/badge/Arxiv-Paper-blue'>187 </a> 188 <a href="https://github.com/ASLP-lab/DiffRhythm">189 <img src='https://img.shields.io/badge/GitHub-Repo-green'>190 </a> 191 <a href="https://aslp-lab.github.io/DiffRhythm.github.io/">192 <img src='https://img.shields.io/badge/Project-Page-brown'>193 </a>194 </div>195 </div> 196 """)197 198 with gr.Tabs() as tabs:199 200 # page 1201 with gr.Tab("Music Generate", id=0):202 with gr.Row():203 with gr.Column():204 lrc = gr.Textbox(205 label="Lyrics",206 placeholder="Input the full lyrics",207 lines=12,208 max_lines=50,209 elem_classes="lyrics-scroll-box",210 value="""[00:04.074] Tell me that I'm special\n[00:06.226] Tell me I look pretty\n[00:08.175] Tell me I'm a little angel\n[00:10.175] Sweetheart of your city\n[00:13.307] Say what I'm dying to hear\n[00:17.058] 'Cause I'm dying to hear you\n[00:20.523] Tell me I'm that new thing\n[00:22.571] Tell me that I'm relevant\n[00:24.723] Tell me that I got a big heart\n[00:26.723] Then back it up with evidence\n[00:29.408] I need it and I don't know why\n[00:33.907] This late at night\n[00:36.139] Isn't it lonely\n[00:38.991] I'd do anything to make you want me\n[00:43.222] I'd give it all up if you told me\n[00:47.339] That I'd be\n[00:49.157] The number one girl in your eyes\n[00:52.506] Your one and only\n[00:55.437] So what's it gon' take for you to want me\n[00:59.589] I'd give it all up if you told me\n[01:03.674] That I'd be\n[01:05.823] The number one girl in your eyes\n[01:10.841] Tell me I'm going real big places\n[01:14.055] Down to earth, so friendly\n[01:16.105] And even through all the phases\n[01:18.256] Tell me you accept me\n[01:21.155] Well, that's all I'm dying to hear\n[01:24.937] Yeah, I'm dying to hear you\n[01:28.521] Tell me that you need me\n[01:30.437] Tell me that I'm loved\n[01:32.740] Tell me that I'm worth it\n[01:34.605] And that I'm enough\n[01:37.571] I need it and I don't know why\n[01:41.889] This late at night\n[01:43.805] Isn't it lonely\n[01:46.871] I'd do anything to make you want me\n[01:51.004] I'd give it all up if you told me\n[01:55.237] That I'd be\n[01:57.089] The number one girl in your eyes\n[02:00.325] Your one and only\n[02:03.305] So what's it gon' take for you to want me\n[02:07.355] I'd give it all up if you told me\n[02:11.589] That I'd be\n[02:13.623] The number one girl in your eyes\n[02:16.804] The girl in your eyes\n[02:20.823] The girl in your eyes\n[02:26.055] Tell me I'm the number one girl\n[02:28.355] I'm the number one girl in your eyes\n[02:33.172] The girl in your eyes\n[02:37.321] The girl in your eyes\n[02:42.472] Tell me I'm the number one girl\n[02:44.539] I'm the number one girl in your eyes\n[02:49.605] Well isn't it lonely\n[02:52.488] I'd do anything to make you want me\n[02:56.637] I'd give it all up if you told me\n[03:00.888] That I'd be\n[03:03.172] The number one girl in your eyes\n[03:06.272] Your one and only\n[03:09.160] So what's it gon' take for you to want me\n[03:13.056] I'd give it all up if you told me\n[03:17.305] That I'd be\n[03:19.488] The number one girl in your eyes\n[03:25.420] The number one girl in your eyes\n""" 211 )212 213 current_prompt_type = gr.State(value="audio")214 with gr.Tabs() as inside_tabs:215 with gr.Tab("Audio Prompt"):216 audio_prompt = gr.Audio(label="Audio Prompt", type="filepath", value="./src/prompt/default.wav")217 with gr.Tab("Text Prompt"):218 text_prompt = gr.Textbox(219 label="Text Prompt",220 placeholder="Enter the Text Prompt, eg: emotional piano pop",221 )222 def update_prompt_type(evt: gr.SelectData):223 return "audio" if evt.index == 0 else "text"224 225 inside_tabs.select(226 fn=update_prompt_type,227 outputs=current_prompt_type228 )229 230 with gr.Column():231 with gr.Accordion("Best Practices Guide", open=True):232 gr.Markdown("""233 1. **Lyrics Format Requirements**234 - Each line must follow: `[mm:ss.xx]Lyric content`235 - Example of valid format:236 ``` 237 [00:10.00]Moonlight spills through broken blinds238 [00:13.20]Your shadow dances on the dashboard shrine239 ```240 241 2. **Generation Duration Limits**242 - The generated music must be between **95 seconds (1:35)** and **285 seconds (4:45)** in length 243 - The latest valid lyric timestamp cannot exceed **04:45.00 (285s)**244 245 3. **Audio Prompt Requirements**246 - Reference audio should be ≥ 1 second, Audio >10 seconds will be randomly clipped into 10 seconds247 - For optimal results, the 10-second clips should be carefully selected248 - Shorter clips may lead to incoherent generation249 250 4. **Supported Languages**251 - Chinese and English252 - More languages comming soon253 254 5. **Others** 255 - If loading audio result is slow, you can select Output Format as mp3 in Advanced Settings.256 """)257 # Music_Duration = gr.Radio(["95s", "285s"], label="Music Duration", value="95s")258 Music_Duration = gr.Slider(259 minimum=95,260 maximum=285,261 step=1,262 value=95,263 label="Music Duration (s)",264 interactive=True265 )266 preference_infer = gr.Radio(["quality first", "speed first"], label="Preference", value="quality first")267 lyrics_btn = gr.Button("Generate", variant="primary")268 audio_output = gr.Audio(label="Audio Result", type="filepath", elem_id="audio_output")269 with gr.Accordion("Advanced Settings", open=False):270 seed = gr.Slider(271 label="Seed",272 minimum=0,273 maximum=MAX_SEED,274 step=1,275 value=0,276 )277 randomize_seed = gr.Checkbox(label="Randomize seed", value=True)278 279 steps = gr.Slider(280 minimum=10,281 maximum=100,282 value=32,283 step=1,284 label="Diffusion Steps",285 interactive=True,286 elem_id="step_slider"287 )288 cfg_strength = gr.Slider(289 minimum=1,290 maximum=10,291 value=4.0,292 step=0.5,293 label="CFG Strength",294 interactive=True,295 elem_id="step_slider"296 )297 # edit = gr.Checkbox(label="edit", value=False)298 # edit = False299 # preference_infer = gr.Radio(["quality first", "speed first"], label="Preference", value="quality first")300 # edit_segments = gr.Textbox(301 # label="Edit Segments",302 # placeholder="Time segments to edit (in seconds). Format: `[[start1,end1],...]",303 # )304 305 odeint_method = gr.Radio(["euler", "midpoint", "rk4","implicit_adams"], label="ODE Solver", value="euler") 306 file_type = gr.Dropdown(["wav", "mp3", "ogg"], label="Output Format", value="mp3")307 308 309 gr.Examples(310 examples=[311 ["./src/prompt/pop_cn.wav"], 312 ["./src/prompt/pop_en.wav"], 313 ["./src/prompt/rock_cn.wav"], 314 ["./src/prompt/rock_en.wav"], 315 ["./src/prompt/country_cn.wav"], 316 ["./src/prompt/country_en.wav"],317 ["./src/prompt/classic_cn.wav"],318 ["./src/prompt/classic_en.wav"],319 ["./src/prompt/jazz_cn.wav"],320 ["./src/prompt/jazz_en.wav"],321 ["./src/prompt/rap_cn.wav"],322 ["./src/prompt/rap_en.wav"],323 ["./src/prompt/default.wav"]324 ],325 inputs=[audio_prompt], 326 label="Audio Examples",327 examples_per_page=13,328 elem_id="audio-examples-container" 329 )330 331 gr.Examples(332 examples=[333 ["Pop Emotional Piano"],334 ["流行 情感 钢琴"],335 ["Indie folk ballad, coming-of-age themes, acoustic guitar picking with harmonica interludes"],336 ["独立民谣, 成长主题, 原声吉他弹奏与口琴间奏"]337 ],338 inputs=[text_prompt], 339 label="Text Examples",340 examples_per_page=4,341 elem_id="text-examples-container" 342 )343 344 gr.Examples(345 examples=[346 ["""[00:04.074] Tell me that I'm special\n[00:06.226] Tell me I look pretty\n[00:08.175] Tell me I'm a little angel\n[00:10.175] Sweetheart of your city\n[00:13.307] Say what I'm dying to hear\n[00:17.058] 'Cause I'm dying to hear you\n[00:20.523] Tell me I'm that new thing\n[00:22.571] Tell me that I'm relevant\n[00:24.723] Tell me that I got a big heart\n[00:26.723] Then back it up with evidence\n[00:29.408] I need it and I don't know why\n[00:33.907] This late at night\n[00:36.139] Isn't it lonely\n[00:38.991] I'd do anything to make you want me\n[00:43.222] I'd give it all up if you told me\n[00:47.339] That I'd be\n[00:49.157] The number one girl in your eyes\n[00:52.506] Your one and only\n[00:55.437] So what's it gon' take for you to want me\n[00:59.589] I'd give it all up if you told me\n[01:03.674] That I'd be\n[01:05.823] The number one girl in your eyes\n[01:10.841] Tell me I'm going real big places\n[01:14.055] Down to earth, so friendly\n[01:16.105] And even through all the phases\n[01:18.256] Tell me you accept me\n[01:21.155] Well, that's all I'm dying to hear\n[01:24.937] Yeah, I'm dying to hear you\n[01:28.521] Tell me that you need me\n[01:30.437] Tell me that I'm loved\n[01:32.740] Tell me that I'm worth it\n[01:34.605] And that I'm enough\n[01:37.571] I need it and I don't know why\n[01:41.889] This late at night\n[01:43.805] Isn't it lonely\n[01:46.871] I'd do anything to make you want me\n[01:51.004] I'd give it all up if you told me\n[01:55.237] That I'd be\n[01:57.089] The number one girl in your eyes\n[02:00.325] Your one and only\n[02:03.305] So what's it gon' take for you to want me\n[02:07.355] I'd give it all up if you told me\n[02:11.589] That I'd be\n[02:13.623] The number one girl in your eyes\n[02:16.804] The girl in your eyes\n[02:20.823] The girl in your eyes\n[02:26.055] Tell me I'm the number one girl\n[02:28.355] I'm the number one girl in your eyes\n[02:33.172] The girl in your eyes\n[02:37.321] The girl in your eyes\n[02:42.472] Tell me I'm the number one girl\n[02:44.539] I'm the number one girl in your eyes\n[02:49.605] Well isn't it lonely\n[02:52.488] I'd do anything to make you want me\n[02:56.637] I'd give it all up if you told me\n[03:00.888] That I'd be\n[03:03.172] The number one girl in your eyes\n[03:06.272] Your one and only\n[03:09.160] So what's it gon' take for you to want me\n[03:13.056] I'd give it all up if you told me\n[03:17.305] That I'd be\n[03:19.488] The number one girl in your eyes\n[03:25.420] The number one girl in your eyes\n"""],347 ["""[00:00.133]Abracadabra, abracadabra\n[00:03.985]Abracadabra, abracadabra\n[00:15.358]Pay the toll to the angels\n[00:18.694]Drawin' circles in the clouds\n[00:22.966]Keep your mind on the distance\n[00:26.321]When the devil turns around\n[00:30.540]Hold me in your heart tonight\n[00:33.751]In the magic of the dark moonlight\n[00:38.189]Save me from this empty fight\n[00:43.521]In the game of life\n[00:45.409]Like a poem said by a lady in red\n[00:49.088]You hear the last few words of your life\n[00:53.013]With a haunting dance, now you're both in a trance\n[00:56.687]It's time to cast your spell on the night\n[01:01.131]Abracadabra amor-oo-na-na\n[01:04.394]Abracadabra morta-oo-gaga\n[01:08.778]Abracadabra, abra-ooh-na-na\n[01:12.063]In her tongue, she's sayin'\n[01:14.367]Death or love tonight\n[01:18.249]Abracadabra, abracadabra\n[01:22.136]Abracadabra, abracadabra\n[01:25.859]Feel the beat under your feet\n[01:27.554]The floor's on fire\n[01:29.714]Abracadabra, abracadabra\n[01:33.464]Choose the road on the west side\n[01:36.818]As the dust flies, watch it burn\n[01:41.057]Don't waste time on feeling\n[01:44.419]Use your passion no return\n[01:48.724]Hold me in your heart tonight\n[01:51.886]In the magic of the dark moonlight\n[01:56.270]Save me from this empty fight\n[02:01.599]In the game of life\n[02:03.524]Like a poem said by a lady in red\n[02:07.192]You hear the last few words of your life\n[02:11.055]With a haunting dance, now you're both in a trance\n[02:14.786]It's time to cast your spell on the night\n[02:19.225]Abracadabra amor-oo-na-na\n[02:22.553]Abracadabra morta-oo-gaga\n[02:26.852]Abracadabra, abra-ooh-na-na\n[02:30.110]In her tongue, she's sayin'\n[02:32.494]Death or love tonight\n[02:36.244]Abracadabra, abracadabra\n[02:40.161]Abracadabra, abracadabra\n[02:43.966]Feel the beat under your feet\n[02:45.630]The floor's on fire\n[02:47.812]Abracadabra, abracadabra\n[02:50.537]Phantom of the dancefloor, come to me\n[02:58.169]Sing for me a sinful melody\n[03:05.833]Ah-ah-ah-ah-ah, ah-ah, ah-ah\n[03:13.453]Ah-ah-ah-ah-ah, ah-ah, ah-ah\n[03:22.025]Abracadabra amor-oo-na-na\n[03:25.423]Abracadabra morta-oo-gaga\n[03:29.674]Abracadabra, abra-ooh-na-na\n[03:33.013]In her tongue, she's sayin'\n[03:35.401]Death or love tonight\n"""],348 ["""[00:00.27]只因你太美 baby 只因你太美 baby\n[00:08.95]只因你实在是太美 baby\n[00:13.99]只因你太美 baby\n[00:18.89]迎面走来的你让我如此蠢蠢欲动\n[00:20.88]这种感觉我从未有\n[00:21.79]Cause I got a crush on you who you\n[00:25.74]你是我的我是你的谁\n[00:28.09]再多一眼看一眼就会爆炸\n[00:30.31]再近一点靠近点快被融化\n[00:32.49]想要把你占为己有 baby bae\n[00:34.60]不管走到哪里\n[00:35.44]都会想起的人是你 you you\n[00:38.12]我应该拿你怎样\n[00:39.61]Uh 所有人都在看着你\n[00:42.36]我的心总是不安\n[00:44.18]Oh 我现在已病入膏肓\n[00:46.63]Eh oh\n[00:47.84]难道真的因你而疯狂吗\n[00:51.57]我本来不是这种人\n[00:53.59]因你变成奇怪的人\n[00:55.77]第一次呀变成这样的我\n[01:01.23]不管我怎么去否认\n[01:03.21]只因你太美 baby 只因你太美 baby\n[01:11.46]只因你实在是太美 baby\n[01:16.75]只因你太美 baby\n[01:21.09]Oh eh oh\n[01:22.82]现在确认地告诉我\n[01:25.26]Oh eh oh\n[01:27.31]你到底属于谁\n[01:29.98]Oh eh oh\n[01:31.70]现在确认地告诉我\n[01:34.45]Oh eh oh\n"""],349 ["""[00:19.50]也想不到要怎么问你别来无恙\n[00:25.71]世界乱的一塌糊涂可是能怎样\n[00:31.85]偶尔抬起头来还好有颗月亮可赏\n[00:38.96]太多回忆要我怎么摆进行李箱\n[00:45.22]一直没哭一直走路走灰多少太阳\n[00:51.70]因为往事没有办法悬赏 隐形在那大街小巷\n[01:00.22]剪断了它还嚣张\n[01:03.85]我的嘴在说谎 说的那么漂亮\n[01:10.07]说我早就忘了你像月一样的俏脸庞\n[01:16.51]最怕一边忙呀忙一边回想那旧时光\n[01:22.87]剪不掉的是你 带泪的脸 还真是烦\n[01:43.32]多少原因将我绑在半夜屋顶上\n[01:49.23]一直没再爱一个人如今就是这样\n[01:55.75]因为故事跟你说了一半 于是搁在所谓云端\n[02:04.21]谁忘不了谁孤单\n[02:07.79]我的心在说谎 说下去会疯狂\n[02:14.02]如果没有月亮那些日子都无妨\n[02:20.43]最怕一边忙呀忙一边想那旧时光\n[02:26.91]剪不掉的是你 带笑的苦 还真烦\n[02:33.81]我的嘴又说了谎 说的那么漂亮\n[02:39.68]以为已经忘了你的那些美像月光它剪不断\n[02:47.15]因为爱早就钻进心脏 心一跳泪就会烫\n[02:52.22]那些带泪的脸 带笑的苦 还真烦\n[02:59.28]月亮是个凶手 想你的我 是通缉犯\n[03:08.03]我有时候真的很怕望见那月光中的你\n"""]350 ],351 352 inputs=[lrc],353 label="Lrc Examples",354 examples_per_page=4,355 elem_id="lrc-examples-container",356 )357 358 359 # page 2360 with gr.Tab("Lyrics Generate", id=1):361 with gr.Row():362 with gr.Column():363 with gr.Accordion("Notice", open=False):364 gr.Markdown("**Two Generation Modes:**\n1. Generate from theme & tags\n2. Add timestamps to existing lyrics")365 366 with gr.Group():367 gr.Markdown("### Method 1: Generate from Theme")368 theme = gr.Textbox(label="theme", placeholder="Enter song theme, e.g: Love and Heartbreak")369 tags_gen = gr.Textbox(label="tags", placeholder="Enter song tags, e.g: pop confidence healing")370 language = gr.Radio(["cn", "en"], label="Language", value="en")371 gen_from_theme_btn = gr.Button("Generate LRC (From Theme)", variant="primary")372 373 gr.Examples(374 examples=[375 [376 "Love and Heartbreak", 377 "vocal emotional piano pop",378 "en"379 ],380 [381 "Heroic Epic", 382 "choir orchestral powerful",383 "cn"384 ]385 ],386 inputs=[theme, tags_gen, language],387 label="Examples: Generate from Theme"388 )389 390 with gr.Group(visible=True): 391 gr.Markdown("### Method 2: Add Timestamps to Lyrics")392 tags_lyrics = gr.Textbox(label="tags", placeholder="Enter song tags, e.g: ballad piano slow")393 lyrics_input = gr.Textbox(394 label="Raw Lyrics (without timestamps)",395 placeholder="Enter plain lyrics (without timestamps), e.g:\nYesterday\nAll my troubles...",396 lines=10,397 max_lines=50,398 elem_classes="lyrics-scroll-box"399 )400 401 gen_from_lyrics_btn = gr.Button("Generate LRC (From Lyrics)", variant="primary")402 403 gr.Examples(404 examples=[405 [406 "acoustic folk happy", 407 """I'm sitting here in the boring room\nIt's just another rainy Sunday afternoon"""408 ],409 [410 "electronic dance energetic",411 """We're living in a material world\nAnd I am a material girl"""412 ]413 ],414 inputs=[tags_lyrics, lyrics_input],415 label="Examples: Generate from Lyrics"416 )417 418 419 with gr.Column():420 lrc_output = gr.Textbox(421 label="Generated LRC",422 placeholder="Timed lyrics will appear here",423 lines=57,424 elem_classes="lrc-output",425 show_copy_button=True426 )427 428 # Bind functions429 gen_from_theme_btn.click(430 fn=R1_infer1,431 inputs=[theme, tags_gen, language],432 outputs=lrc_output433 )434 435 gen_from_lyrics_btn.click(436 fn=R1_infer2,437 inputs=[tags_lyrics, lyrics_input],438 outputs=lrc_output439 )440 441 tabs.select(442 lambda s: None, 443 None, 444 None 445 )446 447 lyrics_btn.click(448 fn=infer_music,449 inputs=[lrc, audio_prompt, text_prompt, current_prompt_type, seed, randomize_seed, steps, cfg_strength, file_type, odeint_method, preference_infer, Music_Duration],450 outputs=audio_output451 )452 453 454if __name__ == "__main__":455 demo.launch()