Update app.py
Browse files
app.py
CHANGED
@@ -67,8 +67,6 @@ from vocoder import build_codec_model, process_audio
|
|
67 |
from post_process_audio import replace_low_freq_with_energy_matched
|
68 |
import re
|
69 |
|
70 |
-
is_shared_ui = True if "innova-ai/YuE-music-generator-demo" in os.environ['SPACE_ID'] else False
|
71 |
-
|
72 |
def empty_output_folder(output_dir):
|
73 |
# List all files in the output directory
|
74 |
files = os.listdir(output_dir)
|
@@ -114,7 +112,7 @@ model.eval()
|
|
114 |
|
115 |
def generate_music(
|
116 |
# stage1_model="m-a-p/YuE-s1-7B-anneal-en-cot",
|
117 |
-
max_new_tokens=
|
118 |
run_n_segments=2,
|
119 |
genre_txt=None,
|
120 |
lyrics_txt=None,
|
@@ -136,7 +134,7 @@ def generate_music(
|
|
136 |
|
137 |
model = model
|
138 |
cuda_idx = cuda_idx
|
139 |
-
max_new_tokens = max_new_tokens
|
140 |
stage1_output_dir = os.path.join(output_dir, f"stage1")
|
141 |
os.makedirs(stage1_output_dir, exist_ok=True)
|
142 |
|
@@ -398,11 +396,10 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments=2, max_new_tokens=
|
|
398 |
music = generate_music(genre_txt=genre_txt_content, lyrics_txt=lyrics_txt_content, run_n_segments=num_segments, output_dir=output_dir, cuda_idx=0, max_new_tokens=max_new_tokens)
|
399 |
|
400 |
return music
|
401 |
-
except
|
402 |
-
|
403 |
-
return
|
404 |
finally:
|
405 |
-
# Clean up temporary files
|
406 |
print("Temporary files deleted.")
|
407 |
|
408 |
# Gradio
|
@@ -429,12 +426,8 @@ with gr.Blocks() as demo:
|
|
429 |
lyrics_txt = gr.Textbox(label="Lyrics")
|
430 |
|
431 |
with gr.Column():
|
432 |
-
|
433 |
-
|
434 |
-
max_new_tokens = gr.Slider(label="Max New Tokens", info="100 tokens equals 1 second long music", minimum=100, maximum="3000", step=100, value=500, interactive=True) # increase it after testing
|
435 |
-
else:
|
436 |
-
num_segments = gr.Number(label="Number of Song Segments", value=2, interactive=True)
|
437 |
-
max_new_tokens = gr.Slider(label="Max New Tokens", minimum=500, maximum="24000", step=500, value=3000, interactive=True)
|
438 |
submit_btn = gr.Button("Submit")
|
439 |
music_out = gr.Audio(label="Audio Result")
|
440 |
|
@@ -477,8 +470,8 @@ Living out my dreams with this mic and a deal
|
|
477 |
],
|
478 |
inputs = [genre_txt, lyrics_txt],
|
479 |
outputs = [music_out],
|
480 |
-
cache_examples =
|
481 |
-
|
482 |
fn=infer
|
483 |
)
|
484 |
|
@@ -487,4 +480,4 @@ Living out my dreams with this mic and a deal
|
|
487 |
inputs = [genre_txt, lyrics_txt, num_segments, max_new_tokens],
|
488 |
outputs = [music_out]
|
489 |
)
|
490 |
-
demo.queue().launch(
|
|
|
67 |
from post_process_audio import replace_low_freq_with_energy_matched
|
68 |
import re
|
69 |
|
|
|
|
|
70 |
def empty_output_folder(output_dir):
|
71 |
# List all files in the output directory
|
72 |
files = os.listdir(output_dir)
|
|
|
112 |
|
113 |
def generate_music(
|
114 |
# stage1_model="m-a-p/YuE-s1-7B-anneal-en-cot",
|
115 |
+
max_new_tokens=5,
|
116 |
run_n_segments=2,
|
117 |
genre_txt=None,
|
118 |
lyrics_txt=None,
|
|
|
134 |
|
135 |
model = model
|
136 |
cuda_idx = cuda_idx
|
137 |
+
max_new_tokens = max_new_tokens*100
|
138 |
stage1_output_dir = os.path.join(output_dir, f"stage1")
|
139 |
os.makedirs(stage1_output_dir, exist_ok=True)
|
140 |
|
|
|
396 |
music = generate_music(genre_txt=genre_txt_content, lyrics_txt=lyrics_txt_content, run_n_segments=num_segments, output_dir=output_dir, cuda_idx=0, max_new_tokens=max_new_tokens)
|
397 |
|
398 |
return music
|
399 |
+
except Exception as e:
|
400 |
+
gr.warning("An Error Occured: " + e)
|
401 |
+
return none
|
402 |
finally:
|
|
|
403 |
print("Temporary files deleted.")
|
404 |
|
405 |
# Gradio
|
|
|
426 |
lyrics_txt = gr.Textbox(label="Lyrics")
|
427 |
|
428 |
with gr.Column():
|
429 |
+
num_segments = gr.Number(label="Number of Segments", value=2, interactive=True)
|
430 |
+
max_new_tokens = gr.Slider(label="Duration of song", minimum=100, maximum=3000, step=100, value=500, interactive=True)
|
|
|
|
|
|
|
|
|
431 |
submit_btn = gr.Button("Submit")
|
432 |
music_out = gr.Audio(label="Audio Result")
|
433 |
|
|
|
470 |
],
|
471 |
inputs = [genre_txt, lyrics_txt],
|
472 |
outputs = [music_out],
|
473 |
+
cache_examples = True,
|
474 |
+
cache_mode="eager",
|
475 |
fn=infer
|
476 |
)
|
477 |
|
|
|
480 |
inputs = [genre_txt, lyrics_txt, num_segments, max_new_tokens],
|
481 |
outputs = [music_out]
|
482 |
)
|
483 |
+
demo.queue().launch(show_error=True)
|