YNB23 commited on
Commit
d2204e0
·
verified ·
1 Parent(s): 83491f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import librosa
3
  import numpy as np
4
  from pydub import AudioSegment
 
5
  import os
6
 
7
  # Titan Intelligence Core
@@ -25,9 +26,15 @@ def engine_v28_titan(input_audio, ref_audio, pressure, active_fix, active_master
25
  # 1. SONIC DNA SCAN (120 sec limit)
26
  y, sr = librosa.load(input_audio, duration=120)
27
 
28
- # BPM Detection - FIXED TYPO HERE
29
  onset_env = librosa.onset.onset_strength(y=y, sr=sr)
30
- tempo = librosa.feature.rhythm.tempo(onset_envelope=onset_env, sr=sr)
 
 
 
 
 
 
31
  bpm = int(np.atleast_1d(tempo)[0])
32
  if bpm < 115:
33
  bpm *= 2 # DnB/Techno optimizer
@@ -78,13 +85,13 @@ def engine_v28_titan(input_audio, ref_audio, pressure, active_fix, active_master
78
  target_lufs = -14 + ((pressure / 100) * 8)
79
  gain_db = target_lufs - (-20)
80
 
81
- # Use compress_dynamic_range (one argument version if newer pydub)
82
- audio = audio.compress_dynamic_range(
 
83
  threshold=-20.0,
84
  ratio=4.0,
85
  attack=12.0,
86
- release=100.0,
87
- window=5.0
88
  )
89
 
90
  optimal_gain = min(gain_db, pressure / 10)
@@ -104,12 +111,12 @@ def engine_v28_titan(input_audio, ref_audio, pressure, active_fix, active_master
104
  if active_master:
105
  log += "\n\n✅ MASTERING COMPLETE - Download below!"
106
 
107
- # FIXED: Return exactly 4 values to match Gradio outputs
108
  return output_path, log, detected_key, str(bpm)
109
 
110
  except Exception as e:
111
  return None, f"ERROR: {str(e)}", "!", "0"
112
 
 
113
  def titan_mentor_ai(question):
114
  if not ghost_titan["analyzed"]:
115
  return "Upload a track first."
@@ -133,6 +140,7 @@ def titan_mentor_ai(question):
133
  return f"BPM: {b} (DnB range 160-180)"
134
  return f"Status: {k} @ {b} BPM | Crest: {round(ghost_titan['crest'], 1)}dB"
135
 
 
136
  css = """
137
  body, .gradio-container {
138
  background: #020202 !important;
@@ -157,6 +165,10 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
157
  out_key = gr.Label(label="KEY")
158
  out_bpm = gr.Label(label="BPM")
159
  in_audio = gr.Audio(label="🎵 UPLOAD TRACK", type="filepath")
 
 
 
 
160
  fix_btn = gr.Checkbox(label="🔧 MIX REPAIR", value=False)
161
  mst_btn = gr.Checkbox(label="🔥 AUTO MASTER", value=False)
162
  in_pwr = gr.Slider(0, 100, label="GAIN PRESSURE", value=85)
@@ -173,10 +185,16 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
173
 
174
  exec_btn.click(
175
  fn=engine_v28_titan,
176
- inputs=[in_audio, in_audio, in_pwr, fix_btn, mst_btn],
 
177
  outputs=[out_audio, out_diag, out_key, out_bpm]
178
  )
179
- chat_btn.click(fn=titan_mentor_ai, inputs=[user_msg], outputs=[chat_out])
 
 
 
 
 
180
 
181
  if __name__ == "__main__":
182
  demo.launch()
 
2
  import librosa
3
  import numpy as np
4
  from pydub import AudioSegment
5
+ from pydub.effects import compress_dynamic_range
6
  import os
7
 
8
  # Titan Intelligence Core
 
26
  # 1. SONIC DNA SCAN (120 sec limit)
27
  y, sr = librosa.load(input_audio, duration=120)
28
 
29
+ # BPM Detection - FIX: Removed non-existent .rhythm attribute
30
  onset_env = librosa.onset.onset_strength(y=y, sr=sr)
31
+
32
+ # Version-agnostic Librosa tempo extraction
33
+ if hasattr(librosa.feature, 'tempo'):
34
+ tempo = librosa.feature.tempo(onset_envelope=onset_env, sr=sr)
35
+ else:
36
+ tempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sr)
37
+
38
  bpm = int(np.atleast_1d(tempo)[0])
39
  if bpm < 115:
40
  bpm *= 2 # DnB/Techno optimizer
 
85
  target_lufs = -14 + ((pressure / 100) * 8)
86
  gain_db = target_lufs - (-20)
87
 
88
+ # FIX: Explicitly call compress_dynamic_range and remove invalid 'window' argument
89
+ audio = compress_dynamic_range(
90
+ audio,
91
  threshold=-20.0,
92
  ratio=4.0,
93
  attack=12.0,
94
+ release=100.0
 
95
  )
96
 
97
  optimal_gain = min(gain_db, pressure / 10)
 
111
  if active_master:
112
  log += "\n\n✅ MASTERING COMPLETE - Download below!"
113
 
 
114
  return output_path, log, detected_key, str(bpm)
115
 
116
  except Exception as e:
117
  return None, f"ERROR: {str(e)}", "!", "0"
118
 
119
+
120
  def titan_mentor_ai(question):
121
  if not ghost_titan["analyzed"]:
122
  return "Upload a track first."
 
140
  return f"BPM: {b} (DnB range 160-180)"
141
  return f"Status: {k} @ {b} BPM | Crest: {round(ghost_titan['crest'], 1)}dB"
142
 
143
+
144
  css = """
145
  body, .gradio-container {
146
  background: #020202 !important;
 
165
  out_key = gr.Label(label="KEY")
166
  out_bpm = gr.Label(label="BPM")
167
  in_audio = gr.Audio(label="🎵 UPLOAD TRACK", type="filepath")
168
+
169
+ # FIX: Restored reference audio block mapping to 'ref_audio' in engine_v28_titan
170
+ in_ref = gr.Audio(label="MASTER REFERENCE (Optional)", type="filepath")
171
+
172
  fix_btn = gr.Checkbox(label="🔧 MIX REPAIR", value=False)
173
  mst_btn = gr.Checkbox(label="🔥 AUTO MASTER", value=False)
174
  in_pwr = gr.Slider(0, 100, label="GAIN PRESSURE", value=85)
 
185
 
186
  exec_btn.click(
187
  fn=engine_v28_titan,
188
+ # FIX: Replaced duplicate 'in_audio' with 'in_ref'
189
+ inputs=[in_audio, in_ref, in_pwr, fix_btn, mst_btn],
190
  outputs=[out_audio, out_diag, out_key, out_bpm]
191
  )
192
+
193
+ chat_btn.click(
194
+ fn=titan_mentor_ai,
195
+ inputs=[user_msg],
196
+ outputs=[chat_out]
197
+ )
198
 
199
  if __name__ == "__main__":
200
  demo.launch()