futurespyhi commited on
Commit
ce7990e
Β·
1 Parent(s): 9853042

Fix lyrics format conversion for YuEGP compatibility

Browse files

- Convert **VERSE**, **CHORUS** format to [VERSE], [CHORUS] format
- Remove AI commentary and keep only actual lyrics content
- Add regex processing to clean lyrics for YuE model parsing
- Add debugging output to track conversion process

Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -304,22 +304,44 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
304
  genre_file.write(f"instrumental,{genre},{mood},male vocals")
305
  genre_file_path = genre_file.name
306
 
307
- # Debug: Print lyrics content for debugging
308
- print(f"πŸ› DEBUG - Raw lyrics input: '{lyrics}'")
309
- print(f"πŸ› DEBUG - Formatted lyrics: '{formatted_lyrics}'")
310
- print(f"πŸ› DEBUG - Formatted lyrics length: {len(formatted_lyrics)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
312
  with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as lyrics_file:
313
- lyrics_file.write(formatted_lyrics)
314
  lyrics_file_path = lyrics_file.name
315
-
316
- print(f"πŸ› DEBUG - Lyrics file path: {lyrics_file_path}")
317
-
318
- # Debug: Read back the file to verify what was written
319
- with open(lyrics_file_path, 'r') as verify_file:
320
- written_content = verify_file.read()
321
- print(f"πŸ› DEBUG - Content written to file: '{written_content}'")
322
- print(f"πŸ› DEBUG - Written content length: {len(written_content)}")
323
 
324
  progress(0.2, desc="Setting up generation...")
325
 
 
304
  genre_file.write(f"instrumental,{genre},{mood},male vocals")
305
  genre_file_path = genre_file.name
306
 
307
+ # Convert lyrics format for YuEGP compatibility
308
+ # YuEGP expects [VERSE], [CHORUS] format, but our AI generates **VERSE**, **CHORUS**
309
+ import re
310
+
311
+ # Extract only the actual lyrics content, removing AI commentary
312
+ formatted_lyrics_for_yue = formatted_lyrics
313
+
314
+ # Convert **VERSE 1** to [VERSE], **CHORUS** to [CHORUS], etc.
315
+ formatted_lyrics_for_yue = re.sub(r'\*\*(VERSE\s*\d*)\*\*', r'[\1]', formatted_lyrics_for_yue)
316
+ formatted_lyrics_for_yue = re.sub(r'\*\*(CHORUS)\*\*', r'[\1]', formatted_lyrics_for_yue)
317
+ formatted_lyrics_for_yue = re.sub(r'\*\*(BRIDGE)\*\*', r'[\1]', formatted_lyrics_for_yue)
318
+ formatted_lyrics_for_yue = re.sub(r'\*\*(OUTRO)\*\*', r'[\1]', formatted_lyrics_for_yue)
319
+
320
+ # Remove AI commentary (lines that don't contain actual lyrics)
321
+ lines = formatted_lyrics_for_yue.split('\n')
322
+ clean_lines = []
323
+ in_song = False
324
+
325
+ for line in lines:
326
+ line = line.strip()
327
+ # Start collecting from first section marker
328
+ if re.match(r'\[(VERSE|CHORUS|BRIDGE|OUTRO)', line):
329
+ in_song = True
330
+ # Stop at AI commentary
331
+ 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']):
332
+ break
333
+ if in_song:
334
+ clean_lines.append(line)
335
+
336
+ formatted_lyrics_for_yue = '\n'.join(clean_lines).strip()
337
+
338
+ print(f"πŸ› DEBUG - Original lyrics length: {len(formatted_lyrics)}")
339
+ print(f"πŸ› DEBUG - Converted lyrics for YuE: '{formatted_lyrics_for_yue}'")
340
+ print(f"πŸ› DEBUG - Converted lyrics length: {len(formatted_lyrics_for_yue)}")
341
 
342
  with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as lyrics_file:
343
+ lyrics_file.write(formatted_lyrics_for_yue)
344
  lyrics_file_path = lyrics_file.name
 
 
 
 
 
 
 
 
345
 
346
  progress(0.2, desc="Setting up generation...")
347