root commited on
Commit
5524ef7
·
1 Parent(s): 48a9e55
Files changed (2) hide show
  1. app.py +0 -0
  2. utils.py +0 -48
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
utils.py CHANGED
@@ -37,40 +37,6 @@ def extract_mfcc_features(y, sr, n_mfcc=20):
37
  # Return a fallback feature vector if extraction fails
38
  return np.zeros(n_mfcc)
39
 
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 * 90)
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."""
76
  result = "Top Detected Genres:\n"
@@ -89,17 +55,3 @@ def ensure_cuda_availability():
89
  print("CUDA is not available. Using CPU for inference.")
90
  return cuda_available
91
 
92
- def preprocess_audio_for_model(waveform, sample_rate, target_sample_rate=16000, max_length=16000):
93
- """Preprocess audio for model input (resample, pad/trim)."""
94
- # Resample if needed
95
- if sample_rate != target_sample_rate:
96
- waveform = librosa.resample(waveform, orig_sr=sample_rate, target_sr=target_sample_rate)
97
-
98
- # Trim or pad to expected length
99
- if len(waveform) > max_length:
100
- waveform = waveform[:max_length]
101
- elif len(waveform) < max_length:
102
- padding = max_length - len(waveform)
103
- waveform = np.pad(waveform, (0, padding), 'constant')
104
-
105
- return waveform
 
37
  # Return a fallback feature vector if extraction fails
38
  return np.zeros(n_mfcc)
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def format_genre_results(top_genres):
41
  """Format genre classification results for display."""
42
  result = "Top Detected Genres:\n"
 
55
  print("CUDA is not available. Using CPU for inference.")
56
  return cuda_available
57