root
commited on
Commit
·
c6a60af
1
Parent(s):
8ab14fe
funtool
Browse files
app.py
CHANGED
|
@@ -1950,6 +1950,10 @@ The lyrics should:
|
|
| 1950 |
- Be completely original
|
| 1951 |
- Match the song duration of {duration:.1f} seconds
|
| 1952 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1953 |
Your lyrics:
|
| 1954 |
"""
|
| 1955 |
else:
|
|
@@ -1996,6 +2000,10 @@ The lyrics should:
|
|
| 1996 |
DON'T include any section labels like [Verse] or [Chorus] unless specifically instructed.
|
| 1997 |
Instead, write lyrics that flow naturally and match the music's rhythm precisely.
|
| 1998 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1999 |
Your lyrics:
|
| 2000 |
"""
|
| 2001 |
|
|
@@ -2061,7 +2069,7 @@ Your lyrics:
|
|
| 2061 |
for model_name, token_id in think_end_tokens.items():
|
| 2062 |
if token_id in output_ids:
|
| 2063 |
found_token = token_id
|
| 2064 |
-
token_position =
|
| 2065 |
break
|
| 2066 |
|
| 2067 |
# Use the position of the thinking token if found
|
|
@@ -2179,15 +2187,23 @@ Improved lyrics with fixed rhythm:
|
|
| 2179 |
|
| 2180 |
lyrics = '\n'.join(formatted_lyrics)
|
| 2181 |
|
| 2182 |
-
#
|
| 2183 |
-
if "[
|
| 2184 |
-
#
|
| 2185 |
-
|
| 2186 |
-
|
|
|
|
| 2187 |
|
| 2188 |
-
#
|
| 2189 |
-
|
| 2190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2191 |
|
| 2192 |
return lyrics
|
| 2193 |
|
|
@@ -2262,7 +2278,13 @@ def process_audio(audio_file):
|
|
| 2262 |
}
|
| 2263 |
|
| 2264 |
# Extract rhythm analysis if present in the lyrics
|
| 2265 |
-
if isinstance(lyrics, str) and "[Note:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2266 |
clean_lyrics = lyrics.split("[Note:")[0].strip()
|
| 2267 |
rhythm_analysis = "[Note:" + lyrics.split("[Note:")[1]
|
| 2268 |
results["clean_lyrics"] = clean_lyrics
|
|
@@ -2349,9 +2371,15 @@ with gr.Blocks(title="Music Genre Classifier & Lyrics Generator") as demo:
|
|
| 2349 |
|
| 2350 |
# Extract rhythm analysis if present
|
| 2351 |
rhythm_analysis = "No detailed rhythm analysis available"
|
| 2352 |
-
if isinstance(lyrics, str)
|
| 2353 |
-
|
| 2354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2355 |
|
| 2356 |
# Format emotion analysis results
|
| 2357 |
try:
|
|
@@ -2376,17 +2404,17 @@ with gr.Blocks(title="Music Genre Classifier & Lyrics Generator") as demo:
|
|
| 2376 |
else:
|
| 2377 |
emotion_text += f"~{section['syllable_count']} syllables)\n"
|
| 2378 |
|
| 2379 |
-
|
| 2380 |
-
|
| 2381 |
-
|
| 2382 |
-
|
| 2383 |
-
|
| 2384 |
-
|
| 2385 |
-
|
| 2386 |
-
|
| 2387 |
-
|
| 2388 |
-
|
| 2389 |
-
|
| 2390 |
|
| 2391 |
except Exception as e:
|
| 2392 |
print(f"Error displaying song structure: {str(e)}")
|
|
|
|
| 1950 |
- Be completely original
|
| 1951 |
- Match the song duration of {duration:.1f} seconds
|
| 1952 |
|
| 1953 |
+
IMPORTANT: Your generated lyrics must be followed by a section titled "[RHYTHM_ANALYSIS_SECTION]"
|
| 1954 |
+
where you analyze how well the lyrics align with the musical rhythm. This section MUST appear
|
| 1955 |
+
even if there are no rhythm issues.
|
| 1956 |
+
|
| 1957 |
Your lyrics:
|
| 1958 |
"""
|
| 1959 |
else:
|
|
|
|
| 2000 |
DON'T include any section labels like [Verse] or [Chorus] unless specifically instructed.
|
| 2001 |
Instead, write lyrics that flow naturally and match the music's rhythm precisely.
|
| 2002 |
|
| 2003 |
+
IMPORTANT: Your generated lyrics must be followed by a section titled "[RHYTHM_ANALYSIS_SECTION]"
|
| 2004 |
+
where you analyze how well the lyrics align with the musical rhythm. This section MUST appear
|
| 2005 |
+
even if there are no rhythm issues.
|
| 2006 |
+
|
| 2007 |
Your lyrics:
|
| 2008 |
"""
|
| 2009 |
|
|
|
|
| 2069 |
for model_name, token_id in think_end_tokens.items():
|
| 2070 |
if token_id in output_ids:
|
| 2071 |
found_token = token_id
|
| 2072 |
+
token_position = output_ids.index(token_id) + 1
|
| 2073 |
break
|
| 2074 |
|
| 2075 |
# Use the position of the thinking token if found
|
|
|
|
| 2187 |
|
| 2188 |
lyrics = '\n'.join(formatted_lyrics)
|
| 2189 |
|
| 2190 |
+
# Check if we have the [RHYTHM_ANALYSIS_SECTION] tag
|
| 2191 |
+
if "[RHYTHM_ANALYSIS_SECTION]" in lyrics:
|
| 2192 |
+
# Split at our custom marker
|
| 2193 |
+
parts = lyrics.split("[RHYTHM_ANALYSIS_SECTION]")
|
| 2194 |
+
clean_lyrics = parts[0].strip()
|
| 2195 |
+
rhythm_analysis = parts[1].strip()
|
| 2196 |
|
| 2197 |
+
# Add our standard marker for compatibility with existing code
|
| 2198 |
+
lyrics = clean_lyrics + "\n\n[Note: Rhythm Analysis]\n" + rhythm_analysis
|
| 2199 |
+
|
| 2200 |
+
# For backwards compatibility - if we have the old format, still handle it
|
| 2201 |
+
elif "[Note: Potential rhythm mismatches" in lyrics:
|
| 2202 |
+
# Keep it as is, the existing parsing code can handle this format
|
| 2203 |
+
pass
|
| 2204 |
+
else:
|
| 2205 |
+
# No analysis found, add a minimal one
|
| 2206 |
+
lyrics = lyrics + "\n\n[Note: Rhythm Analysis]\nNo rhythm issues detected. All syllables align well with the beat pattern."
|
| 2207 |
|
| 2208 |
return lyrics
|
| 2209 |
|
|
|
|
| 2278 |
}
|
| 2279 |
|
| 2280 |
# Extract rhythm analysis if present in the lyrics
|
| 2281 |
+
if isinstance(lyrics, str) and "[Note: Rhythm Analysis]" in lyrics:
|
| 2282 |
+
clean_lyrics = lyrics.split("[Note: Rhythm Analysis]")[0].strip()
|
| 2283 |
+
rhythm_analysis = "[Note: Rhythm Analysis]" + lyrics.split("[Note: Rhythm Analysis]")[1]
|
| 2284 |
+
results["clean_lyrics"] = clean_lyrics
|
| 2285 |
+
results["rhythm_analysis"] = rhythm_analysis
|
| 2286 |
+
# Backwards compatibility with old format
|
| 2287 |
+
elif isinstance(lyrics, str) and "[Note: Potential rhythm mismatches" in lyrics:
|
| 2288 |
clean_lyrics = lyrics.split("[Note:")[0].strip()
|
| 2289 |
rhythm_analysis = "[Note:" + lyrics.split("[Note:")[1]
|
| 2290 |
results["clean_lyrics"] = clean_lyrics
|
|
|
|
| 2371 |
|
| 2372 |
# Extract rhythm analysis if present
|
| 2373 |
rhythm_analysis = "No detailed rhythm analysis available"
|
| 2374 |
+
if isinstance(lyrics, str):
|
| 2375 |
+
# First check for new format
|
| 2376 |
+
if "[Note: Rhythm Analysis]" in lyrics:
|
| 2377 |
+
clean_lyrics = lyrics.split("[Note: Rhythm Analysis]")[0].strip()
|
| 2378 |
+
rhythm_analysis = lyrics.split("[Note: Rhythm Analysis]")[1]
|
| 2379 |
+
# Check for old format
|
| 2380 |
+
elif "[Note: Potential rhythm mismatches" in lyrics:
|
| 2381 |
+
clean_lyrics = lyrics.split("[Note:")[0].strip()
|
| 2382 |
+
rhythm_analysis = "[Note:" + lyrics.split("[Note:")[1]
|
| 2383 |
|
| 2384 |
# Format emotion analysis results
|
| 2385 |
try:
|
|
|
|
| 2404 |
else:
|
| 2405 |
emotion_text += f"~{section['syllable_count']} syllables)\n"
|
| 2406 |
|
| 2407 |
+
# Add flexible structure info if available
|
| 2408 |
+
if "flexible_structure" in song_structure and song_structure["flexible_structure"]:
|
| 2409 |
+
flexible = song_structure["flexible_structure"]
|
| 2410 |
+
if "segments" in flexible and flexible["segments"]:
|
| 2411 |
+
emotion_text += "\nDetailed Rhythm Analysis:\n"
|
| 2412 |
+
for i, segment in enumerate(flexible["segments"][:5]): # Show first 5 segments
|
| 2413 |
+
emotion_text += f"- Segment {i+1}: {segment['start']:.1f}s to {segment['end']:.1f}s, "
|
| 2414 |
+
emotion_text += f"pattern: {segment.get('syllable_template', 'N/A')}\n"
|
| 2415 |
+
|
| 2416 |
+
if len(flexible["segments"]) > 5:
|
| 2417 |
+
emotion_text += f" (+ {len(flexible['segments']) - 5} more segments)\n"
|
| 2418 |
|
| 2419 |
except Exception as e:
|
| 2420 |
print(f"Error displaying song structure: {str(e)}")
|