Spaces:
Running
Running
futurespyhi
commited on
Commit
Β·
a402939
1
Parent(s):
71096e3
modify lyric and genre according to YuE's README
Browse files- .gitignore +3 -0
- app.py +15 -12
.gitignore
CHANGED
|
@@ -114,3 +114,6 @@ backup/
|
|
| 114 |
|
| 115 |
# test files
|
| 116 |
tests/
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# test files
|
| 116 |
tests/
|
| 117 |
+
|
| 118 |
+
# log
|
| 119 |
+
logs.txt
|
app.py
CHANGED
|
@@ -175,7 +175,7 @@ def validate_file_structure():
|
|
| 175 |
return True
|
| 176 |
|
| 177 |
@spaces.GPU(duration=1200) # H200 on ZeroGPU is free for 25mins, for compatibility on A10G large and L40s
|
| 178 |
-
def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progress()) -> str:
|
| 179 |
"""
|
| 180 |
Generate music using YuE model with high-performance Spaces configuration
|
| 181 |
"""
|
|
@@ -191,7 +191,7 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 191 |
# Create temporary files
|
| 192 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as genre_file:
|
| 193 |
# genre_file.write(f"instrumental,{genre},{mood},male vocals")
|
| 194 |
-
genre_file.write(f"
|
| 195 |
genre_file_path = genre_file.name
|
| 196 |
|
| 197 |
# Convert lyrics format for YuE compatibility
|
|
@@ -201,11 +201,11 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 201 |
# Extract only the actual lyrics content, removing AI commentary
|
| 202 |
formatted_lyrics_for_yue = formatted_lyrics
|
| 203 |
|
| 204 |
-
# Convert **VERSE 1** to [
|
| 205 |
-
formatted_lyrics_for_yue = re.sub(r'\*\*(VERSE\s*\d*)\*\*', r'[
|
| 206 |
-
formatted_lyrics_for_yue = re.sub(r'\*\*(CHORUS)\*\*', r'[
|
| 207 |
-
formatted_lyrics_for_yue = re.sub(r'\*\*(BRIDGE)\*\*', r'[
|
| 208 |
-
formatted_lyrics_for_yue = re.sub(r'\*\*(OUTRO)\*\*', r'[
|
| 209 |
|
| 210 |
# Remove AI commentary (lines that don't contain actual lyrics)
|
| 211 |
lines = formatted_lyrics_for_yue.split('\n')
|
|
@@ -214,16 +214,19 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 214 |
|
| 215 |
for line in lines:
|
| 216 |
line = line.strip()
|
| 217 |
-
# Start collecting from first section marker
|
| 218 |
-
if re.match(r'\[(
|
| 219 |
in_song = True
|
| 220 |
# Stop at AI commentary
|
| 221 |
if in_song and line and not line.startswith('[') and any(phrase in line.lower() for phrase in ['how do you like', 'would you like', 'let me know', 'take a look']):
|
| 222 |
break
|
| 223 |
if in_song:
|
| 224 |
clean_lines.append(line)
|
| 225 |
-
|
|
|
|
| 226 |
formatted_lyrics_for_yue = '\n'.join(clean_lines).strip()
|
|
|
|
|
|
|
| 227 |
|
| 228 |
print(f"π DEBUG - Original lyrics length: {len(formatted_lyrics)}")
|
| 229 |
print(f"π DEBUG - Converted lyrics for YuE: '{formatted_lyrics_for_yue}'")
|
|
@@ -516,7 +519,7 @@ def build_interface():
|
|
| 516 |
gr.Markdown("### ποΈ Music Settings")
|
| 517 |
with gr.Row():
|
| 518 |
genre = gr.Dropdown(
|
| 519 |
-
choices=["pop", "rock", "jazz", "classical", "
|
| 520 |
value="pop", label="Genre"
|
| 521 |
)
|
| 522 |
mood = gr.Dropdown(
|
|
@@ -637,7 +640,7 @@ def build_interface():
|
|
| 637 |
# Music generation with progress
|
| 638 |
generate_btn.click(
|
| 639 |
fn=generate_music_spaces,
|
| 640 |
-
inputs=[lyrics_display, genre, mood],
|
| 641 |
outputs=[music_output],
|
| 642 |
queue=True,
|
| 643 |
show_progress=True
|
|
|
|
| 175 |
return True
|
| 176 |
|
| 177 |
@spaces.GPU(duration=1200) # H200 on ZeroGPU is free for 25mins, for compatibility on A10G large and L40s
|
| 178 |
+
def generate_music_spaces(lyrics: str, genre: str, mood: str, theme: str, progress=gr.Progress()) -> str:
|
| 179 |
"""
|
| 180 |
Generate music using YuE model with high-performance Spaces configuration
|
| 181 |
"""
|
|
|
|
| 191 |
# Create temporary files
|
| 192 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as genre_file:
|
| 193 |
# genre_file.write(f"instrumental,{genre},{mood},male vocals")
|
| 194 |
+
genre_file.write(f"{genre} electronic {mood} {theme} female airy vocal bright")
|
| 195 |
genre_file_path = genre_file.name
|
| 196 |
|
| 197 |
# Convert lyrics format for YuE compatibility
|
|
|
|
| 201 |
# Extract only the actual lyrics content, removing AI commentary
|
| 202 |
formatted_lyrics_for_yue = formatted_lyrics
|
| 203 |
|
| 204 |
+
# Convert **VERSE 1** to [verse], **CHORUS** to [chorus], etc. (lowercase as expected by YuE)
|
| 205 |
+
formatted_lyrics_for_yue = re.sub(r'\*\*(VERSE\s*\d*)\*\*', r'[verse]', formatted_lyrics_for_yue)
|
| 206 |
+
formatted_lyrics_for_yue = re.sub(r'\*\*(CHORUS)\*\*', r'[chorus]', formatted_lyrics_for_yue)
|
| 207 |
+
formatted_lyrics_for_yue = re.sub(r'\*\*(BRIDGE)\*\*', r'[bridge]', formatted_lyrics_for_yue)
|
| 208 |
+
formatted_lyrics_for_yue = re.sub(r'\*\*(OUTRO)\*\*', r'[outro]', formatted_lyrics_for_yue)
|
| 209 |
|
| 210 |
# Remove AI commentary (lines that don't contain actual lyrics)
|
| 211 |
lines = formatted_lyrics_for_yue.split('\n')
|
|
|
|
| 214 |
|
| 215 |
for line in lines:
|
| 216 |
line = line.strip()
|
| 217 |
+
# Start collecting from first section marker (lowercase as expected by YuE)
|
| 218 |
+
if re.match(r'\[(verse|chorus|bridge|outro)', line, re.IGNORECASE):
|
| 219 |
in_song = True
|
| 220 |
# Stop at AI commentary
|
| 221 |
if in_song and line and not line.startswith('[') and any(phrase in line.lower() for phrase in ['how do you like', 'would you like', 'let me know', 'take a look']):
|
| 222 |
break
|
| 223 |
if in_song:
|
| 224 |
clean_lines.append(line)
|
| 225 |
+
|
| 226 |
+
# Join with proper section separators as required by YuE (double newlines between sections)
|
| 227 |
formatted_lyrics_for_yue = '\n'.join(clean_lines).strip()
|
| 228 |
+
# Add double newlines between sections for YuE format
|
| 229 |
+
formatted_lyrics_for_yue = re.sub(r'\n(\[(?:verse|chorus|bridge|outro)\])', r'\n\n\1', formatted_lyrics_for_yue)
|
| 230 |
|
| 231 |
print(f"π DEBUG - Original lyrics length: {len(formatted_lyrics)}")
|
| 232 |
print(f"π DEBUG - Converted lyrics for YuE: '{formatted_lyrics_for_yue}'")
|
|
|
|
| 519 |
gr.Markdown("### ποΈ Music Settings")
|
| 520 |
with gr.Row():
|
| 521 |
genre = gr.Dropdown(
|
| 522 |
+
choices=["pop", "rock", "jazz", "classical", "folk", "r&b", "country", "hip-hop"],
|
| 523 |
value="pop", label="Genre"
|
| 524 |
)
|
| 525 |
mood = gr.Dropdown(
|
|
|
|
| 640 |
# Music generation with progress
|
| 641 |
generate_btn.click(
|
| 642 |
fn=generate_music_spaces,
|
| 643 |
+
inputs=[lyrics_display, genre, mood, theme],
|
| 644 |
outputs=[music_output],
|
| 645 |
queue=True,
|
| 646 |
show_progress=True
|