Spaces:
Running
on
T4
Running
on
T4
Update UI
Browse filessegment length and max overlap
app.py
CHANGED
@@ -137,8 +137,9 @@ def load_melody_filepath(melody_filepath, title, assigned_model,topp, temperatur
|
|
137 |
# get melody filename
|
138 |
#$Union[str, os.PathLike]
|
139 |
symbols = ['_', '.', '-']
|
|
|
140 |
if (melody_filepath is None) or (melody_filepath == ""):
|
141 |
-
return title, gr.update(maximum=0, value=0) , gr.update(value="medium", interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef)
|
142 |
|
143 |
if (title is None) or ("MusicGen" in title) or (title == ""):
|
144 |
melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
|
@@ -163,9 +164,9 @@ def load_melody_filepath(melody_filepath, title, assigned_model,topp, temperatur
|
|
163 |
segment_samples = sr * segment_length
|
164 |
total_melodys = max(min((len(melody_data) // segment_samples), 25), 0)
|
165 |
print(f"Melody length: {len(melody_data)}, Melody segments: {total_melodys}\n")
|
166 |
-
MAX_PROMPT_INDEX = total_melodys
|
167 |
-
|
168 |
-
return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=0), gr.update(value=assigned_model, interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef)
|
169 |
|
170 |
def predict(model, text, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap=1, prompt_index = 0, include_title = True, include_settings = True, harmony_only = False, profile = gr.OAuthProfile, segment_length = 30, progress=gr.Progress(track_tqdm=True)):
|
171 |
global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
|
@@ -474,7 +475,7 @@ def ui(**kwargs):
|
|
474 |
with gr.Accordion("Expert", open=False):
|
475 |
with gr.Row():
|
476 |
segment_length = gr.Slider(minimum=10, maximum=30, value=30, step=1,label="Music Generation Segment Length (s)", interactive=True,key="segment_length")
|
477 |
-
overlap = gr.Slider(minimum=0, maximum=
|
478 |
dimension = gr.Slider(minimum=-2, maximum=2, value=2, step=1, label="Dimension", info="determines which direction to add new segements of audio. (1 = stack tracks, 2 = lengthen, -2..0 = ?)", interactive=True)
|
479 |
with gr.Row():
|
480 |
topk = gr.Number(label="Top-k", value=280, precision=0, interactive=True, info="more structured", key="topk")
|
@@ -491,10 +492,10 @@ def ui(**kwargs):
|
|
491 |
seed_used = gr.Number(label='Seed used', value=-1, interactive=False)
|
492 |
|
493 |
radio.change(toggle_audio_src, radio, [melody_filepath], queue=False, show_progress=False)
|
494 |
-
melody_filepath.change(load_melody_filepath, inputs=[melody_filepath, title, model,topp, temperature, cfg_coef, segment_length], outputs=[title, prompt_index , model, topp, temperature, cfg_coef], api_name="melody_filepath_change", queue=False)
|
495 |
reuse_seed.click(fn=lambda x: x, inputs=[seed_used], outputs=[seed], queue=False, api_name="reuse_seed_click")
|
496 |
autoplay_cb.change(fn=lambda x: gr.update(autoplay=x), inputs=[autoplay_cb], outputs=[output], queue=False, api_name="autoplay_cb_change")
|
497 |
-
segment_length.release(fn=load_melody_filepath, queue=False, api_name="segment_length_change", trigger_mode="once", inputs=[melody_filepath, title, model,topp, temperature, cfg_coef, segment_length], outputs=[title, prompt_index , model, topp, temperature, cfg_coef], show_progress="minimal")
|
498 |
|
499 |
gr.Examples(
|
500 |
examples=[
|
|
|
137 |
# get melody filename
|
138 |
#$Union[str, os.PathLike]
|
139 |
symbols = ['_', '.', '-']
|
140 |
+
MAX_OVERLAP = int(segment_length // 2) - 1
|
141 |
if (melody_filepath is None) or (melody_filepath == ""):
|
142 |
+
return title, gr.update(maximum=0, value=0) , gr.update(value="medium", interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef), gr.update(maximum=MAX_OVERLAP)
|
143 |
|
144 |
if (title is None) or ("MusicGen" in title) or (title == ""):
|
145 |
melody_name, melody_extension = get_filename_from_filepath(melody_filepath)
|
|
|
164 |
segment_samples = sr * segment_length
|
165 |
total_melodys = max(min((len(melody_data) // segment_samples), 25), 0)
|
166 |
print(f"Melody length: {len(melody_data)}, Melody segments: {total_melodys}\n")
|
167 |
+
MAX_PROMPT_INDEX = total_melodys
|
168 |
+
|
169 |
+
return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=0), gr.update(value=assigned_model, interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef), gr.update(maximum=MAX_OVERLAP)
|
170 |
|
171 |
def predict(model, text, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap=1, prompt_index = 0, include_title = True, include_settings = True, harmony_only = False, profile = gr.OAuthProfile, segment_length = 30, progress=gr.Progress(track_tqdm=True)):
|
172 |
global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
|
|
|
475 |
with gr.Accordion("Expert", open=False):
|
476 |
with gr.Row():
|
477 |
segment_length = gr.Slider(minimum=10, maximum=30, value=30, step=1,label="Music Generation Segment Length (s)", interactive=True,key="segment_length")
|
478 |
+
overlap = gr.Slider(minimum=0, maximum=14, value=1, step=1, label="Segment Overlap", interactive=True)
|
479 |
dimension = gr.Slider(minimum=-2, maximum=2, value=2, step=1, label="Dimension", info="determines which direction to add new segements of audio. (1 = stack tracks, 2 = lengthen, -2..0 = ?)", interactive=True)
|
480 |
with gr.Row():
|
481 |
topk = gr.Number(label="Top-k", value=280, precision=0, interactive=True, info="more structured", key="topk")
|
|
|
492 |
seed_used = gr.Number(label='Seed used', value=-1, interactive=False)
|
493 |
|
494 |
radio.change(toggle_audio_src, radio, [melody_filepath], queue=False, show_progress=False)
|
495 |
+
melody_filepath.change(load_melody_filepath, inputs=[melody_filepath, title, model,topp, temperature, cfg_coef, segment_length], outputs=[title, prompt_index , model, topp, temperature, cfg_coef, overlap], api_name="melody_filepath_change", queue=False)
|
496 |
reuse_seed.click(fn=lambda x: x, inputs=[seed_used], outputs=[seed], queue=False, api_name="reuse_seed_click")
|
497 |
autoplay_cb.change(fn=lambda x: gr.update(autoplay=x), inputs=[autoplay_cb], outputs=[output], queue=False, api_name="autoplay_cb_change")
|
498 |
+
segment_length.release(fn=load_melody_filepath, queue=False, api_name="segment_length_change", trigger_mode="once", inputs=[melody_filepath, title, model,topp, temperature, cfg_coef, segment_length], outputs=[title, prompt_index , model, topp, temperature, cfg_coef, overlap], show_progress="minimal")
|
499 |
|
500 |
gr.Examples(
|
501 |
examples=[
|