root commited on
Commit
ba71a6b
·
1 Parent(s): db1df57
Files changed (2) hide show
  1. app.py +13 -12
  2. utils.py +14 -15
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 <= 12:
151
- # Short song - one verse and chorus
152
- verse_lines = 4
153
- chorus_lines = 4
154
- elif lines_count <= 20:
155
  # Medium song - two verses and chorus
156
- verse_lines = 6
157
- chorus_lines = 4
158
  else:
159
- # Longer song - three verses, chorus, and bridge
160
- verse_lines = 6
161
- chorus_lines = 4
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: 4 lines' if lines_count > 20 else ''}
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 > 20:
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 sophisticated calculation that considers:
44
  - Average words per line (8-10 words)
45
- - Average words per minute (120-150 words)
46
- - Typical song structure (verses, chorus, bridge)
47
  """
48
  # Convert duration to minutes
49
  duration_minutes = duration / 60
50
 
51
  # Calculate total words based on duration
52
- # Using 135 words per minute as average
53
- total_words = int(duration_minutes * 135)
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
- # Typical song has 2-3 verses, 1-2 choruses, and possibly a bridge
62
- if total_lines < 12:
63
  # Very short song - keep it simple
64
- return max(4, total_lines)
65
- elif total_lines < 20:
66
  # Short song - one verse and chorus
67
- return min(12, total_lines)
68
- elif total_lines < 30:
69
  # Medium song - two verses and chorus
70
- return min(20, total_lines)
71
  else:
72
- # Longer song - three verses, chorus, and possibly bridge
73
- return min(30, total_lines)
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."""