root
commited on
Commit
·
370bf23
1
Parent(s):
5b33796
ss
Browse files
app.py
CHANGED
|
@@ -149,7 +149,7 @@ def generate_lyrics(music_analysis, genre, duration):
|
|
| 149 |
text_generator = load_llm_pipeline()
|
| 150 |
|
| 151 |
# Construct prompt for the LLM
|
| 152 |
-
prompt = f"""
|
| 153 |
- Key: {key} {mode}
|
| 154 |
- Tempo: {tempo} BPM
|
| 155 |
- Emotion: {emotion}
|
|
@@ -157,9 +157,16 @@ def generate_lyrics(music_analysis, genre, duration):
|
|
| 157 |
- Duration: {duration:.1f} seconds
|
| 158 |
- Time signature: {music_analysis["rhythm_analysis"]["estimated_time_signature"]}
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
"""
|
| 164 |
|
| 165 |
# Generate lyrics using the LLM pipeline
|
|
@@ -174,14 +181,25 @@ The output should ONLY contain the actual song lyrics, formatted as they would a
|
|
| 174 |
|
| 175 |
lyrics = generation_result[0]["generated_text"]
|
| 176 |
|
| 177 |
-
#
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
lyrics = re.sub(r'^Title:.*?$', '', lyrics, flags=re.MULTILINE).strip()
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
lyrics = re.sub(r'
|
| 183 |
-
lyrics = re.sub(r'
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
return lyrics
|
| 187 |
|
|
|
|
| 149 |
text_generator = load_llm_pipeline()
|
| 150 |
|
| 151 |
# Construct prompt for the LLM
|
| 152 |
+
prompt = f"""Write lyrics for a {genre} song with these specifications:
|
| 153 |
- Key: {key} {mode}
|
| 154 |
- Tempo: {tempo} BPM
|
| 155 |
- Emotion: {emotion}
|
|
|
|
| 157 |
- Duration: {duration:.1f} seconds
|
| 158 |
- Time signature: {music_analysis["rhythm_analysis"]["estimated_time_signature"]}
|
| 159 |
|
| 160 |
+
IMPORTANT INSTRUCTIONS:
|
| 161 |
+
- The lyrics should be in English
|
| 162 |
+
- Write ONLY the raw lyrics with no structural labels
|
| 163 |
+
- DO NOT include [verse], [chorus], [bridge], or any other section markers
|
| 164 |
+
- DO NOT include any explanations or thinking about the lyrics
|
| 165 |
+
- DO NOT number the verses or lines
|
| 166 |
+
- DO NOT use bullet points
|
| 167 |
+
- Format as simple line-by-line lyrics only
|
| 168 |
+
- Make sure the lyrics match the specified duration and tempo
|
| 169 |
+
- Keep lyrics concise enough to fit the duration when sung at the given tempo
|
| 170 |
"""
|
| 171 |
|
| 172 |
# Generate lyrics using the LLM pipeline
|
|
|
|
| 181 |
|
| 182 |
lyrics = generation_result[0]["generated_text"]
|
| 183 |
|
| 184 |
+
# Enhanced post-processing to remove ALL structural elements and thinking
|
| 185 |
+
# Remove any lines with section labels using a more comprehensive pattern
|
| 186 |
+
lyrics = re.sub(r'^\[.*?\].*$', '', lyrics, flags=re.MULTILINE)
|
| 187 |
+
|
| 188 |
+
# Remove common prefixes and thinking text
|
| 189 |
+
lyrics = re.sub(r'^(Here are|Here is|These are|This is|Let me|I will|I'll).*?:\s*', '', lyrics, flags=re.IGNORECASE)
|
| 190 |
lyrics = re.sub(r'^Title:.*?$', '', lyrics, flags=re.MULTILINE).strip()
|
| 191 |
+
|
| 192 |
+
# Remove all section markers in any format
|
| 193 |
+
lyrics = re.sub(r'^\s*(Verse|Chorus|Bridge|Pre.?Chorus|Intro|Outro|Refrain|Hook|Breakdown)(\s*\d*|\s*[A-Z])?:?\s*$', '', lyrics, flags=re.MULTILINE|re.IGNORECASE)
|
| 194 |
+
lyrics = re.sub(r'\[(Verse|Chorus|Bridge|Pre.?Chorus|Intro|Outro|Refrain|Hook|Breakdown)(\s*\d*|\s*[A-Z])?\]', '', lyrics, flags=re.IGNORECASE)
|
| 195 |
+
|
| 196 |
+
# Remove any "thinking" or explanatory parts that might be at the beginning
|
| 197 |
+
lyrics = re.sub(r'^.*?(Let\'s|Here\'s|I need|I want|I\'ll|First|The|This).*?:\s*', '', lyrics, flags=re.IGNORECASE)
|
| 198 |
+
|
| 199 |
+
# Remove any empty lines at beginning, collapse multiple blank lines, and trim
|
| 200 |
+
lyrics = re.sub(r'^\s*\n', '', lyrics)
|
| 201 |
+
lyrics = re.sub(r'\n\s*\n\s*\n+', '\n\n', lyrics)
|
| 202 |
+
lyrics = lyrics.strip()
|
| 203 |
|
| 204 |
return lyrics
|
| 205 |
|