update ui and add examples

This commit is contained in:
chuxij
2025-05-13 07:00:35 +00:00
parent 6db26bae5d
commit 6ca5bd880e
10 changed files with 258 additions and 119 deletions
+105 -19
View File
@@ -8,6 +8,7 @@ Apache 2.0 License
import gradio as gr
import librosa
import os
TAG_DEFAULT = "funk, pop, soul, rock, melodic, guitar, drums, bass, keyboard, percussion, 105 BPM, energetic, upbeat, groovy, vibrant, dynamic"
@@ -48,6 +49,26 @@ Catch the tune and hold it tight
In this moment we take flight
"""
# First, let's define the presets at the top of the file, after the imports
GENRE_PRESETS = {
"Modern Pop": "pop, synth, drums, guitar, 120 bpm, upbeat, catchy, vibrant, female vocals, polished vocals",
"Rock": "rock, electric guitar, drums, bass, 130 bpm, energetic, rebellious, gritty, male vocals, raw vocals",
"Hip Hop": "hip hop, 808 bass, hi-hats, synth, 90 bpm, bold, urban, intense, male vocals, rhythmic vocals",
"Country": "country, acoustic guitar, steel guitar, fiddle, 100 bpm, heartfelt, rustic, warm, male vocals, twangy vocals",
"EDM": "edm, synth, bass, kick drum, 128 bpm, euphoric, pulsating, energetic, instrumental",
"Reggae": "reggae, guitar, bass, drums, 80 bpm, chill, soulful, positive, male vocals, smooth vocals",
"Classical": "classical, orchestral, strings, piano, 60 bpm, elegant, emotive, timeless, instrumental",
"Jazz": "jazz, saxophone, piano, double bass, 110 bpm, smooth, improvisational, soulful, male vocals, crooning vocals",
"Metal": "metal, electric guitar, double kick drum, bass, 160 bpm, aggressive, intense, heavy, male vocals, screamed vocals",
"R&B": "r&b, synth, bass, drums, 85 bpm, sultry, groovy, romantic, female vocals, silky vocals"
}
# Add this function to handle preset selection
def update_tags_from_preset(preset_name):
if preset_name == "Custom":
return ""
return GENRE_PRESETS.get(preset_name, "")
def create_output_ui(task_name="Text2Music"):
# For many consumer-grade GPU devices, only one batch can be run
@@ -69,7 +90,17 @@ def create_text2music_ui(
gr,
text2music_process_func,
sample_data_func=None,
load_data_func=None,
):
with gr.Row(equal_height=True):
curr_file_dir = os.path.dirname(__file__)
output_file_dir = os.path.join(curr_file_dir, "..", "..", "outputs")
json_files = [f for f in os.listdir(output_file_dir) if f.endswith('.json')]
json_files.sort(reverse=True, key=lambda x: int(x.split('_')[1]))
output_files = gr.Dropdown(choices=json_files, label="Select previous generated input params", scale=9, interactive=True)
load_bnt = gr.Button("Load", variant="primary", scale=1)
with gr.Row():
with gr.Column():
with gr.Row(equal_height=True):
@@ -84,7 +115,7 @@ def create_text2music_ui(
info="-1 means random duration (30 ~ 240).",
scale=9,
)
sample_bnt = gr.Button("Sample", variant="primary", scale=1)
sample_bnt = gr.Button("Sample", variant="secondary", scale=1)
# audio2audio
with gr.Row(equal_height=True):
@@ -120,25 +151,43 @@ def create_text2music_ui(
outputs=[ref_audio_input, ref_audio_strength],
)
prompt = gr.Textbox(
lines=2,
label="Tags",
max_lines=4,
value=TAG_DEFAULT,
info="Support tags, descriptions, and scene. Use commas to separate different tags.\ntags and lyrics examples are from ai music generation community",
)
lyrics = gr.Textbox(
lines=9,
label="Lyrics",
max_lines=13,
value=LYRIC_DEFAULT,
info="Support lyric structure tags like [verse], [chorus], and [bridge] to separate different parts of the lyrics.\nUse [instrumental] or [inst] to generate instrumental music. Not support genre structure tag in lyrics",
with gr.Column(scale=2):
with gr.Group():
gr.Markdown("""<center>Support tags, descriptions, and scene. Use commas to separate different tags.<br>Tags and lyrics examples are from AI music generation community.</center>""")
with gr.Row():
genre_preset = gr.Dropdown(
choices=["Custom"] + list(GENRE_PRESETS.keys()),
value="Custom",
label="Preset",
scale=1,
)
prompt = gr.Textbox(
lines=1,
label="Tags",
max_lines=4,
value=TAG_DEFAULT,
scale=9,
)
# Add the change event for the preset dropdown
genre_preset.change(
fn=update_tags_from_preset,
inputs=[genre_preset],
outputs=[prompt]
)
with gr.Group():
gr.Markdown("""<center>Support lyric structure tags like [verse], [chorus], and [bridge] to separate different parts of the lyrics.<br>Use [instrumental] or [inst] to generate instrumental music. Not support genre structure tag in lyrics</center>""")
lyrics = gr.Textbox(
lines=9,
label="Lyrics",
max_lines=13,
value=LYRIC_DEFAULT,
)
with gr.Accordion("Basic Settings", open=False):
infer_step = gr.Slider(
minimum=1,
maximum=1000,
maximum=200,
step=1,
value=60,
label="Infer Steps",
@@ -146,7 +195,7 @@ def create_text2music_ui(
)
guidance_scale = gr.Slider(
minimum=0.0,
maximum=200.0,
maximum=30.0,
step=0.1,
value=15.0,
label="Guidance Scale",
@@ -774,8 +823,7 @@ def create_text2music_ui(
outputs=extend_outputs + [extend_input_params_json],
)
def sample_data(lora_name_or_path_):
json_data = sample_data_func(lora_name_or_path_)
def json2output(json_data):
return (
json_data["audio_duration"],
json_data["prompt"],
@@ -820,6 +868,10 @@ def create_text2music_ui(
),
)
def sample_data(lora_name_or_path_):
json_data = sample_data_func(lora_name_or_path_)
return json2output(json_data)
sample_bnt.click(
sample_data,
inputs=[lora_name_or_path],
@@ -848,6 +900,39 @@ def create_text2music_ui(
],
)
def load_data(json_file):
json_file = os.path.join(output_file_dir, json_file)
json_data = load_data_func(json_file)
return json2output(json_data)
load_bnt.click(
fn=load_data,
inputs=[output_files],
outputs=[
audio_duration,
prompt,
lyrics,
infer_step,
guidance_scale,
scheduler_type,
cfg_type,
omega_scale,
manual_seeds,
guidance_interval,
guidance_interval_decay,
min_guidance_scale,
use_erg_tag,
use_erg_lyric,
use_erg_diffusion,
oss_steps,
guidance_scale_text,
guidance_scale_lyric,
audio2audio_enable,
ref_audio_strength,
ref_audio_input,
],
)
text2music_bnt.click(
fn=text2music_process_func,
inputs=[
@@ -881,6 +966,7 @@ def create_text2music_ui(
def create_main_demo_ui(
text2music_process_func=dump_func,
sample_data_func=dump_func,
load_data_func=dump_func,
):
with gr.Blocks(
title="ACE-Step Model 1.0 DEMO",
@@ -890,12 +976,12 @@ def create_main_demo_ui(
<h1 style="text-align: center;">ACE-Step: A Step Towards Music Generation Foundation Model</h1>
"""
)
with gr.Tab("text2music"):
create_text2music_ui(
gr=gr,
text2music_process_func=text2music_process_func,
sample_data_func=sample_data_func,
load_data_func=load_data_func,
)
return demo