david174 commited on
Commit
d3636cf
·
verified ·
1 Parent(s): fdaf97e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -38
app.py CHANGED
@@ -3,50 +3,47 @@ import librosa
3
  import numpy as np
4
  from pydub import AudioSegment
5
 
6
- def ghost_fix(tu_track, track_ref, intensidad):
7
  if tu_track is None:
8
- return None, "Sube un audio.", "...", "https://images.unsplash.com/photo-1614613535308-eb5fbd3d2c17?q=80&w=500", "..."
 
9
  try:
10
- # 1. ANALISIS RAPIDO
11
- y, sr = librosa.load(tu_track, duration=20)
 
12
  chroma = librosa.feature.chroma_cqt(y=y, sr=sr)
13
  notas = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
14
  key_det = notas[np.argmax(np.mean(chroma, axis=1))]
15
- rms_tu = np.mean(librosa.feature.rms(y=y))
16
 
17
- # 2. COMPARADOR
18
- info = "TONALIDAD: " + key_det + "\n"
19
- if track_ref is not None:
20
- y_r, _ = librosa.load(track_ref, duration=20)
21
- diff = 20 * np.log10(np.mean(librosa.feature.rms(y=y_r)) / rms_tu)
22
- info += "DIF. VOLUMEN: " + str(round(diff, 1)) + " dB\n"
23
-
24
- # 3. MASTER
25
- audio = AudioSegment.from_file(tu_track)
26
- audio = audio.apply_gain((intensidad / 10) - 5)
27
- audio.export("final.wav", format="wav")
28
 
29
- prompt = "Cyberpunk Art, Neon, DnB style, Key: " + key_det
30
- return "final.wav", info + "\nCONSEJO: Ajusta tu Kick a " + key_det, key_det, "https://images.unsplash.com/photo-1550684848-fac1c5b4e853?q=80&w=500", prompt
31
- except Exception as e:
32
- return None, "Error: " + str(e), "!", None, "..."
33
-
34
- with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="orange")) as demo:
35
- gr.Markdown("# 💀 DNB GHOST v7.2")
36
- with gr.Row():
37
- with gr.Column():
38
- in_t = gr.Audio(label="TU TRACK", type="filepath")
39
- in_r = gr.Audio(label="REFERENCIA", type="filepath")
40
- in_s = gr.Slider(0, 100, label="MASTER", value=80)
41
- btn = gr.Button("🚀 PROCESAR", variant="primary")
42
- with gr.Column():
43
- out_a = gr.Audio(label="MASTER")
44
- out_i = gr.Textbox(label="INFORME")
45
- out_k = gr.Label(label="KEY")
46
- with gr.Column():
47
- out_m = gr.Image(label="VIBE")
48
- out_p = gr.Textbox(label="PROMPT ARTE")
49
 
50
- btn.click(ghost_fix, [in_t, in_r, in_s], [out_a, out_i, out_k, out_m, out_p])
 
 
 
 
51
 
52
- demo.launch()
 
 
 
3
  import numpy as np
4
  from pydub import AudioSegment
5
 
6
+ def ghost_critic_v9(tu_track, track_ref, intensidad):
7
  if tu_track is None:
8
+ return None, "Sube tu audio.", "...", "https://images.unsplash.com/photo-1614613535308-eb5fbd3d2c17?q=80&w=500", "..."
9
+
10
  try:
11
+ # 1. CARGA Y ANÁLISIS ESPECTRAL
12
+ y, sr = librosa.load(tu_track, duration=30)
13
+ # Análisis de Key
14
  chroma = librosa.feature.chroma_cqt(y=y, sr=sr)
15
  notas = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
16
  key_det = notas[np.argmax(np.mean(chroma, axis=1))]
 
17
 
18
+ # 2. COMPARATIVA DE MEZCLA Y COMPOSICIÓN
19
+ critica_comp = "⚠️ Composición: Sube una referencia para analizar la estructura."
20
+ critica_mix = "⚠️ Mezcla: Falta análisis comparativo."
 
 
 
 
 
 
 
 
21
 
22
+ if track_ref is not None:
23
+ y_r, _ = librosa.load(track_ref, duration=30)
24
+
25
+ # Comparar Brillo (Spectral Centroid)
26
+ sc_tu = np.mean(librosa.feature.spectral_centroid(y=y, sr=sr))
27
+ sc_ref = np.mean(librosa.feature.spectral_centroid(y=y_r, sr=sr))
28
+
29
+ # Comparar Densidad (RMS)
30
+ rms_tu = np.sqrt(np.mean(y**2))
31
+ rms_ref = np.sqrt(np.mean(y_r**2))
32
+
33
+ # Lógica de Crítica de Mezcla
34
+ if sc_tu < sc_ref * 0.8:
35
+ critica_mix = "❌ MEZCLA: Tu track suena 'oscuro'. Falta brillo en los hi-hats y sintes (zona 8k-12kHz)."
36
+ elif sc_tu > sc_ref * 1.2:
37
+ critica_mix = "❌ MEZCLA: Demasiados agudos. Tu mezcla va a fatigar el oído. Baja los platos."
38
+ else:
39
+ critica_mix = "✅ MEZCLA: El balance de brillo está en el punto profesional."
 
 
40
 
41
+ # Lógica de Crítica de Composición/Arreglo
42
+ if rms_tu < rms_ref * 0.7:
43
+ critica_comp = "❌ COMPOSICIÓN: El drop se siente vacío. Añade capas (layers) de sintes o percusión extra (shakers/rides)."
44
+ else:
45
+ critica_comp = "✅ COMPOSICIÓN: La densidad de elementos es sólida y potente."
46
 
47
+ # 3. MASTERING
48
+ audio = AudioSegment.from_file(tu_track)
49
+ audio = audio.apply_gain((intensidad / 10) - 5)