add model download, double cfg
This commit is contained in:
+31
-20
@@ -65,38 +65,41 @@ def create_text2music_ui(
|
||||
with gr.Column():
|
||||
|
||||
with gr.Row(equal_height=True):
|
||||
audio_duration = gr.Slider(-1, 240.0, step=0.00001, value=180, label="Audio Duration", interactive=True, info="Duration of the audio in seconds. -1 means random duration (30 ~ 240).", scale=9)
|
||||
audio_duration = gr.Slider(-1, 240.0, step=0.00001, value=180, label="Audio Duration", interactive=True, info="-1 means random duration (30 ~ 240).", scale=9)
|
||||
sample_bnt = gr.Button("Sample", variant="primary", scale=1)
|
||||
|
||||
prompt = gr.Textbox(lines=2, label="Tags", max_lines=4, placeholder=TAG_PLACEHOLDER)
|
||||
lyrics = gr.Textbox(lines=9, label="Lyrics", max_lines=13, placeholder=LYRIC_PLACEHOLDER)
|
||||
prompt = gr.Textbox(lines=2, label="Tags", max_lines=4, placeholder=TAG_PLACEHOLDER, info="Support tags, descriptions, and scene. Use commas to separate different tags.")
|
||||
lyrics = gr.Textbox(lines=9, label="Lyrics", max_lines=13, placeholder=LYRIC_PLACEHOLDER, 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.Accordion("Basic Settings", open=True):
|
||||
infer_step = gr.Slider(minimum=1, maximum=1000, step=1, value=60, label="Infer Steps", interactive=True)
|
||||
guidance_scale = gr.Slider(minimum=0.0, maximum=200.0, step=0.1, value=15.0, label="Guidance Scale", interactive=True)
|
||||
manual_seeds = gr.Textbox(label="manual seeds (default None)", placeholder="1,2,3,4", value=None)
|
||||
guidance_scale = gr.Slider(minimum=0.0, maximum=200.0, step=0.1, value=15.0, label="Guidance Scale", interactive=True, info="When guidance_scale_lyric > 1 and guidance_scale_text > 1, the guidance scale will not be applied.")
|
||||
guidance_scale_text = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=5.0, label="Guidance Scale Text", interactive=True, info="Guidance scale for text condition. It can only apply to cfg. set guidance_scale_text=5.0, guidance_scale_lyric=1.5 for start")
|
||||
guidance_scale_lyric = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=1.5, label="Guidance Scale Lyric", interactive=True)
|
||||
|
||||
manual_seeds = gr.Textbox(label="manual seeds (default None)", placeholder="1,2,3,4", value=None, info="Seed for the generation")
|
||||
|
||||
with gr.Accordion("Advanced Settings", open=False):
|
||||
scheduler_type = gr.Radio(["euler", "heun"], value="euler", label="Scheduler Type", elem_id="scheduler_type", )
|
||||
cfg_type = gr.Radio(["cfg", "apg", "cfg_star"], value="apg", label="CFG Type", elem_id="cfg_type", )
|
||||
use_erg_tag = gr.Checkbox(label="use ERG for tag", value=True, )
|
||||
use_erg_lyric = gr.Checkbox(label="use ERG for lyric", value=True, )
|
||||
use_erg_diffusion = gr.Checkbox(label="use ERG for diffusion", value=True, )
|
||||
scheduler_type = gr.Radio(["euler", "heun"], value="euler", label="Scheduler Type", elem_id="scheduler_type", info="Scheduler type for the generation. euler is recommended. heun will take more time.")
|
||||
cfg_type = gr.Radio(["cfg", "apg", "cfg_star"], value="apg", label="CFG Type", elem_id="cfg_type", info="CFG type for the generation. apg is recommended. cfg and cfg_star are almost the same.")
|
||||
use_erg_tag = gr.Checkbox(label="use ERG for tag", value=True, info="Use Entropy Rectifying Guidance for tag. It will multiple a temperature to the attention to make a weaker tag condition and make better diversity.")
|
||||
use_erg_lyric = gr.Checkbox(label="use ERG for lyric", value=True, info="The same but apply to lyric encoder's attention.")
|
||||
use_erg_diffusion = gr.Checkbox(label="use ERG for diffusion", value=True, info="The same but apply to diffusion model's attention.")
|
||||
|
||||
omega_scale = gr.Slider(minimum=-100.0, maximum=100.0, step=0.1, value=10.0, label="Granularity Scale", interactive=True, )
|
||||
omega_scale = gr.Slider(minimum=-100.0, maximum=100.0, step=0.1, value=10.0, label="Granularity Scale", interactive=True, info="Granularity scale for the generation. Higher values can reduce artifacts")
|
||||
|
||||
guidance_interval = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Guidance Interval", interactive=True, )
|
||||
guidance_interval_decay = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.0, label="Guidance Interval Decay", interactive=True, )
|
||||
min_guidance_scale = gr.Slider(minimum=0.0, maximum=200.0, step=0.1, value=3.0, label="Min Guidance Scale", interactive=True, )
|
||||
oss_steps = gr.Textbox(label="OSS Steps", placeholder="16, 29, 52, 96, 129, 158, 172, 183, 189, 200", value=None)
|
||||
guidance_interval = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Guidance Interval", interactive=True, info="Guidance interval for the generation. 0.5 means only apply guidance in the middle steps (0.25 * infer_steps to 0.75 * infer_steps)")
|
||||
guidance_interval_decay = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.0, label="Guidance Interval Decay", interactive=True, info="Guidance interval decay for the generation. Guidance scale will decay from guidance_scale to min_guidance_scale in the interval. 0.0 means no decay.")
|
||||
min_guidance_scale = gr.Slider(minimum=0.0, maximum=200.0, step=0.1, value=3.0, label="Min Guidance Scale", interactive=True, info="Min guidance scale for guidance interval decay's end scale")
|
||||
oss_steps = gr.Textbox(label="OSS Steps", placeholder="16, 29, 52, 96, 129, 158, 172, 183, 189, 200", value=None, info="Optimal Steps for the generation. But not test well")
|
||||
|
||||
text2music_bnt = gr.Button(variant="primary")
|
||||
|
||||
with gr.Column():
|
||||
outputs, input_params_json = create_output_ui()
|
||||
with gr.Tab("retake"):
|
||||
retake_variance = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="variance")
|
||||
retake_seeds = gr.Textbox(label="retake seeds (default None)", placeholder="1,2,3,4", value=None)
|
||||
retake_variance = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="variance", info="Variance for the retake. 0.0 means no variance. 1.0 means full variance.")
|
||||
retake_seeds = gr.Textbox(label="retake seeds (default None)", placeholder="", value=None, info="Seed for the retake.")
|
||||
retake_bnt = gr.Button(variant="primary")
|
||||
retake_outputs, retake_input_params_json = create_output_ui("Retake")
|
||||
|
||||
@@ -118,9 +121,11 @@ def create_text2music_ui(
|
||||
json_data["use_erg_lyric"],
|
||||
json_data["use_erg_diffusion"],
|
||||
", ".join(map(str, json_data["oss_steps"])),
|
||||
retake_seeds,
|
||||
retake_variance,
|
||||
"retake",
|
||||
json_data["guidance_scale_text"] if "guidance_scale_text" in json_data else 0.0,
|
||||
json_data["guidance_scale_lyric"] if "guidance_scale_lyric" in json_data else 0.0,
|
||||
retake_seeds=retake_seeds,
|
||||
retake_variance=retake_variance,
|
||||
task="retake",
|
||||
)
|
||||
|
||||
retake_bnt.click(
|
||||
@@ -156,6 +161,8 @@ def create_text2music_ui(
|
||||
json_data["use_erg_lyric"],
|
||||
json_data["use_erg_diffusion"],
|
||||
", ".join(map(str, json_data["oss_steps"])),
|
||||
json_data["guidance_scale_text"] if "guidance_scale_text" in json_data else 0.0,
|
||||
json_data["guidance_scale_lyric"] if "guidance_scale_lyric" in json_data else 0.0,
|
||||
)
|
||||
|
||||
sample_bnt.click(
|
||||
@@ -177,6 +184,8 @@ def create_text2music_ui(
|
||||
use_erg_lyric,
|
||||
use_erg_diffusion,
|
||||
oss_steps,
|
||||
guidance_scale_text,
|
||||
guidance_scale_lyric,
|
||||
],
|
||||
)
|
||||
|
||||
@@ -199,6 +208,8 @@ def create_text2music_ui(
|
||||
use_erg_lyric,
|
||||
use_erg_diffusion,
|
||||
oss_steps,
|
||||
guidance_scale_text,
|
||||
guidance_scale_lyric,
|
||||
], outputs=outputs + [input_params_json]
|
||||
)
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
from openai import OpenAI
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
random_genre_prompt = """randomly give me a short prompt that describes a music (with genre tag). less than 30 words
|
||||
Here are some examples:
|
||||
fusion jazz with synth, bass, drums, saxophone
|
||||
Electronic, eerie, swing, dreamy, melodic, electro, sad, emotional
|
||||
90s hip-hop, old school rap, turntablism, vinyl samples, instrumental loop
|
||||
"""
|
||||
|
||||
|
||||
def random_genre():
|
||||
client = OpenAI()
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-4o-mini",
|
||||
messages=[{"role": "system", "content": random_genre_prompt}],
|
||||
max_tokens=30,
|
||||
temperature=0.7,
|
||||
)
|
||||
return completion.choices[0].message.content
|
||||
|
||||
|
||||
optimize_genre_prompt = """optimize the following music descirption and make it more genre specific. less than 30 words
|
||||
output examples:
|
||||
fusion jazz with synth, bass, drums, saxophone
|
||||
Electronic, eerie, swing, dreamy, melodic, electro, sad, emotional
|
||||
90s hip-hop, old school rap, turntablism, vinyl samples, instrumental loop
|
||||
|
||||
## input music descirption
|
||||
"""
|
||||
|
||||
|
||||
def optimize_genre(prompt):
|
||||
client = OpenAI()
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-4o-mini",
|
||||
messages=[{"role": "system", "content": optimize_genre_prompt+prompt}],
|
||||
max_tokens=30,
|
||||
temperature=0.7,
|
||||
)
|
||||
return completion.choices[0].message.content
|
||||
Reference in New Issue
Block a user