root
commited on
Commit
·
ba71a6b
1
Parent(s):
db1df57
ss
Browse files
app.py
CHANGED
@@ -147,18 +147,18 @@ def generate_lyrics(genre, duration):
|
|
147 |
lines_count = calculate_lyrics_length(duration)
|
148 |
|
149 |
# Calculate approximate number of verses and chorus
|
150 |
-
if lines_count <=
|
151 |
-
#
|
152 |
-
verse_lines =
|
153 |
-
chorus_lines =
|
154 |
-
elif lines_count <=
|
155 |
# Medium song - two verses and chorus
|
156 |
-
verse_lines =
|
157 |
-
chorus_lines =
|
158 |
else:
|
159 |
-
# Longer song -
|
160 |
-
verse_lines =
|
161 |
-
chorus_lines =
|
162 |
|
163 |
# Create prompt for the LLM
|
164 |
prompt = f"""
|
@@ -171,9 +171,10 @@ The lyrics should:
|
|
171 |
- Follow this structure:
|
172 |
* Verse: {verse_lines} lines
|
173 |
* Chorus: {chorus_lines} lines
|
174 |
-
* {f'Bridge:
|
175 |
- Be completely original
|
176 |
- Match the song duration of {duration:.1f} seconds
|
|
|
177 |
|
178 |
Your lyrics:
|
179 |
"""
|
@@ -201,7 +202,7 @@ Your lyrics:
|
|
201 |
formatted_lyrics.append("[Verse]")
|
202 |
elif i == verse_lines:
|
203 |
formatted_lyrics.append("\n[Chorus]")
|
204 |
-
elif i == verse_lines + chorus_lines and lines_count >
|
205 |
formatted_lyrics.append("\n[Bridge]")
|
206 |
formatted_lyrics.append(line)
|
207 |
lyrics = '\n'.join(formatted_lyrics)
|
|
|
147 |
lines_count = calculate_lyrics_length(duration)
|
148 |
|
149 |
# Calculate approximate number of verses and chorus
|
150 |
+
if lines_count <= 6:
|
151 |
+
# Very short song - one verse and chorus
|
152 |
+
verse_lines = 2
|
153 |
+
chorus_lines = 2
|
154 |
+
elif lines_count <= 10:
|
155 |
# Medium song - two verses and chorus
|
156 |
+
verse_lines = 3
|
157 |
+
chorus_lines = 2
|
158 |
else:
|
159 |
+
# Longer song - two verses, chorus, and bridge
|
160 |
+
verse_lines = 3
|
161 |
+
chorus_lines = 2
|
162 |
|
163 |
# Create prompt for the LLM
|
164 |
prompt = f"""
|
|
|
171 |
- Follow this structure:
|
172 |
* Verse: {verse_lines} lines
|
173 |
* Chorus: {chorus_lines} lines
|
174 |
+
* {f'Bridge: 2 lines' if lines_count > 10 else ''}
|
175 |
- Be completely original
|
176 |
- Match the song duration of {duration:.1f} seconds
|
177 |
+
- Keep each line concise and impactful
|
178 |
|
179 |
Your lyrics:
|
180 |
"""
|
|
|
202 |
formatted_lyrics.append("[Verse]")
|
203 |
elif i == verse_lines:
|
204 |
formatted_lyrics.append("\n[Chorus]")
|
205 |
+
elif i == verse_lines + chorus_lines and lines_count > 10:
|
206 |
formatted_lyrics.append("\n[Bridge]")
|
207 |
formatted_lyrics.append(line)
|
208 |
lyrics = '\n'.join(formatted_lyrics)
|
utils.py
CHANGED
@@ -40,37 +40,36 @@ def extract_mfcc_features(y, sr, n_mfcc=20):
|
|
40 |
def calculate_lyrics_length(duration):
|
41 |
"""
|
42 |
Calculate appropriate lyrics length based on audio duration.
|
43 |
-
Uses a more
|
44 |
- Average words per line (8-10 words)
|
45 |
-
-
|
46 |
-
-
|
47 |
"""
|
48 |
# Convert duration to minutes
|
49 |
duration_minutes = duration / 60
|
50 |
|
51 |
# Calculate total words based on duration
|
52 |
-
# Using
|
53 |
-
total_words = int(duration_minutes *
|
54 |
|
55 |
# Calculate number of lines
|
56 |
# Assuming 8-10 words per line
|
57 |
words_per_line = 9 # average
|
58 |
total_lines = total_words // words_per_line
|
59 |
|
60 |
-
# Adjust for song structure
|
61 |
-
|
62 |
-
if total_lines < 12:
|
63 |
# Very short song - keep it simple
|
64 |
-
return max(
|
65 |
-
elif total_lines <
|
66 |
# Short song - one verse and chorus
|
67 |
-
return min(
|
68 |
-
elif total_lines <
|
69 |
# Medium song - two verses and chorus
|
70 |
-
return min(
|
71 |
else:
|
72 |
-
# Longer song -
|
73 |
-
return min(
|
74 |
|
75 |
def format_genre_results(top_genres):
|
76 |
"""Format genre classification results for display."""
|
|
|
40 |
def calculate_lyrics_length(duration):
|
41 |
"""
|
42 |
Calculate appropriate lyrics length based on audio duration.
|
43 |
+
Uses a more conservative calculation that generates shorter lyrics:
|
44 |
- Average words per line (8-10 words)
|
45 |
+
- Reduced words per minute (45 words instead of 135)
|
46 |
+
- Simplified song structure
|
47 |
"""
|
48 |
# Convert duration to minutes
|
49 |
duration_minutes = duration / 60
|
50 |
|
51 |
# Calculate total words based on duration
|
52 |
+
# Using 45 words per minute (reduced from 135)
|
53 |
+
total_words = int(duration_minutes * 45)
|
54 |
|
55 |
# Calculate number of lines
|
56 |
# Assuming 8-10 words per line
|
57 |
words_per_line = 9 # average
|
58 |
total_lines = total_words // words_per_line
|
59 |
|
60 |
+
# Adjust for song structure with shorter lengths
|
61 |
+
if total_lines < 6:
|
|
|
62 |
# Very short song - keep it simple
|
63 |
+
return max(2, total_lines)
|
64 |
+
elif total_lines < 10:
|
65 |
# Short song - one verse and chorus
|
66 |
+
return min(6, total_lines)
|
67 |
+
elif total_lines < 15:
|
68 |
# Medium song - two verses and chorus
|
69 |
+
return min(10, total_lines)
|
70 |
else:
|
71 |
+
# Longer song - two verses, chorus, and bridge
|
72 |
+
return min(15, total_lines)
|
73 |
|
74 |
def format_genre_results(top_genres):
|
75 |
"""Format genre classification results for display."""
|