Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,6 +153,9 @@ def analyze_track(audio_path, lyrics_input):
|
|
| 153 |
if corrected_bpm < 95 and p_rolloff > 2500:
|
| 154 |
corrected_bpm *= 2.0
|
| 155 |
|
|
|
|
|
|
|
|
|
|
| 156 |
# 2. NEURAL NETWORK INFERENCE
|
| 157 |
chunk_len_16k = 16000 * 15
|
| 158 |
chunks_16k = [wav_16k[i:i + chunk_len_16k] for i in range(0, len(wav_16k), chunk_len_16k) if len(wav_16k[i:i+chunk_len_16k]) >= 16000]
|
|
@@ -197,26 +200,27 @@ def analyze_track(audio_path, lyrics_input):
|
|
| 197 |
final_mbti = avg_a_mbti
|
| 198 |
final_emo = avg_a_emo
|
| 199 |
|
| 200 |
-
# 4. ACOUSTIC OVERRIDE
|
| 201 |
def apply_dsp_guardrails(probs, labels, task_type):
|
| 202 |
p = probs.cpu().squeeze().numpy()
|
| 203 |
res = {labels[i]: float(p[i]) for i in range(len(labels))}
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
| 208 |
|
| 209 |
-
is_upbeat_mathrock = is_clean_twinkly and (corrected_bpm >=
|
| 210 |
|
| 211 |
if task_type == "emotion":
|
| 212 |
for outlier in ['disgust', 'annoyance', 'fear', 'confusion']:
|
| 213 |
if outlier in res: res[outlier] *= 0.10
|
| 214 |
|
| 215 |
-
if is_upbeat_mathrock or
|
| 216 |
for neg in ['grief', 'sadness', 'remorse', 'anger']:
|
| 217 |
-
if neg in res: res[neg] *= 0.
|
| 218 |
for pos in ['joy', 'amusement', 'excitement', 'admiration']:
|
| 219 |
-
if pos in res: res[pos] *= 3.
|
| 220 |
elif is_clean_twinkly:
|
| 221 |
if 'anger' in res: res['anger'] *= 0.20
|
| 222 |
if 'grief' in res: res['grief'] *= 0.80
|
|
@@ -227,9 +231,9 @@ def analyze_track(audio_path, lyrics_input):
|
|
| 227 |
if 'anger' in res: res['anger'] *= 1.20
|
| 228 |
|
| 229 |
if task_type == "vibe":
|
| 230 |
-
if is_upbeat_mathrock or
|
| 231 |
-
if 'Aggressive' in res: res['Aggressive'] *= 0.
|
| 232 |
-
if 'Melancholic' in res: res['Melancholic'] *= 0.
|
| 233 |
if 'Technical' in res: res['Technical'] *= 3.50
|
| 234 |
if 'Atmospheric' in res: res['Atmospheric'] *= 1.50
|
| 235 |
elif is_clean_twinkly:
|
|
|
|
| 153 |
if corrected_bpm < 95 and p_rolloff > 2500:
|
| 154 |
corrected_bpm *= 2.0
|
| 155 |
|
| 156 |
+
# Print diagnostic DSP values to terminal for debugging
|
| 157 |
+
print(f"DSP DIAGNOSTIC -> ZCR: {p_zcr:.4f} | Rolloff: {p_rolloff:.1f} | RMS: {p_rms:.4f} | BPM: {corrected_bpm:.1f}")
|
| 158 |
+
|
| 159 |
# 2. NEURAL NETWORK INFERENCE
|
| 160 |
chunk_len_16k = 16000 * 15
|
| 161 |
chunks_16k = [wav_16k[i:i + chunk_len_16k] for i in range(0, len(wav_16k), chunk_len_16k) if len(wav_16k[i:i+chunk_len_16k]) >= 16000]
|
|
|
|
| 200 |
final_mbti = avg_a_mbti
|
| 201 |
final_emo = avg_a_emo
|
| 202 |
|
| 203 |
+
# 4. ACOUSTIC OVERRIDE
|
| 204 |
def apply_dsp_guardrails(probs, labels, task_type):
|
| 205 |
p = probs.cpu().squeeze().numpy()
|
| 206 |
res = {labels[i]: float(p[i]) for i in range(len(labels))}
|
| 207 |
|
| 208 |
+
# Logic Update: Using Spectral Rolloff (Brightness) to detect Pop/Trap elements reliably
|
| 209 |
+
is_bright_pop_trap = p_rolloff > 2800 and p_rms > 0.05
|
| 210 |
+
is_heavy_distorted = p_zcr > 0.115 and p_rolloff <= 2800
|
| 211 |
+
is_clean_twinkly = p_zcr <= 0.115 and p_rolloff > 1500
|
| 212 |
|
| 213 |
+
is_upbeat_mathrock = (is_clean_twinkly or is_bright_pop_trap) and (corrected_bpm >= 115 or p_rms > 0.1)
|
| 214 |
|
| 215 |
if task_type == "emotion":
|
| 216 |
for outlier in ['disgust', 'annoyance', 'fear', 'confusion']:
|
| 217 |
if outlier in res: res[outlier] *= 0.10
|
| 218 |
|
| 219 |
+
if is_upbeat_mathrock or is_bright_pop_trap:
|
| 220 |
for neg in ['grief', 'sadness', 'remorse', 'anger']:
|
| 221 |
+
if neg in res: res[neg] *= 0.10
|
| 222 |
for pos in ['joy', 'amusement', 'excitement', 'admiration']:
|
| 223 |
+
if pos in res: res[pos] *= 3.50
|
| 224 |
elif is_clean_twinkly:
|
| 225 |
if 'anger' in res: res['anger'] *= 0.20
|
| 226 |
if 'grief' in res: res['grief'] *= 0.80
|
|
|
|
| 231 |
if 'anger' in res: res['anger'] *= 1.20
|
| 232 |
|
| 233 |
if task_type == "vibe":
|
| 234 |
+
if is_upbeat_mathrock or is_bright_pop_trap:
|
| 235 |
+
if 'Aggressive' in res: res['Aggressive'] *= 0.10
|
| 236 |
+
if 'Melancholic' in res: res['Melancholic'] *= 0.20
|
| 237 |
if 'Technical' in res: res['Technical'] *= 3.50
|
| 238 |
if 'Atmospheric' in res: res['Atmospheric'] *= 1.50
|
| 239 |
elif is_clean_twinkly:
|