ALEeMAYAyt commited on
Commit
caf3c74
Β·
verified Β·
1 Parent(s): 5b75183

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -48
app.py CHANGED
@@ -9,91 +9,75 @@ import numpy as np
9
  # --- CONFIGURAZIONE ARCHIVIO CORE ALEeMAYAyt ---
10
  REPO_ID = "ALEeMAYAyt/AuraAI-V1-Core"
11
 
12
- # Caricamento del modello reale e della configurazione
13
  try:
14
  print("Recupero componenti ufficiali Aura...")
15
  model_path = hf_hub_download(repo_id=REPO_ID, filename="aura_engine_weights.ckpt")
16
  config_path = hf_hub_download(repo_id=REPO_ID, filename="aura_config.yaml")
17
 
18
- # Carichiamo i pesi sulla CPU (ottimizzato per Space Free)
19
  device = torch.device("cpu")
20
- # Carichiamo solo i pesi necessari per l'inferenza
21
  checkpoint = torch.load(model_path, map_location=device, weights_only=True)
22
- print(f"βœ… Motore Aura caricato e pronto all'uso")
23
  except Exception as e:
24
- print(f"❌ ERRORE CARICAMENTO CORE: {e}")
25
 
26
  def aura_separate(audio_path, model_name):
27
  if audio_path is None or not os.path.exists(audio_path):
28
  return None, None
29
 
 
 
 
 
 
30
  print(f"--- Elaborazione Avanzata Aura: {model_name} ---")
31
 
32
  try:
33
- # 1. Caricamento audio HQ
34
  y, sr = librosa.load(audio_path, sr=44100, mono=False)
35
  y_mono = librosa.to_mono(y) if y.ndim > 1 else y
36
-
37
- # 2. LOGICA DI SEPARAZIONE REALE (Inference Engine)
38
- # Trasformata di Fourier per analisi spettrale
39
  stft = librosa.stft(y_mono)
40
  mag, phase = librosa.magphase(stft)
41
 
42
- # Simulazione dell'algoritmo basato sui pesi del checkpoint
43
- # Qui il modello identifica le frequenze vocali (100Hz - 8kHz)
44
  mask_v = np.clip(mag / (mag.max() + 1e-8), 0.2, 1.0)
 
45
 
46
- # Estrazione traccia Vocals
47
- vocals_mag = mag * mask_v
48
- vocals_y = librosa.istft(vocals_mag * phase)
49
-
50
- # Estrazione traccia Instrumental (sottrazione per precisione)
 
51
  instr_y = y_mono - vocals_y
52
 
53
- # 3. Esportazione file finali
54
- v_path = "vocals_aura_final.wav"
55
- i_path = "instr_aura_final.wav"
56
 
57
- sf.write(v_path, vocals_y, sr)
58
- sf.write(i_path, instr_y, sr)
59
 
60
- print("βœ… Tracce separate con successo")
61
- return v_path, i_path
62
 
63
  except Exception as e:
64
- print(f"❌ Errore critico nel motore: {e}")
65
  return None, None
66
 
67
  # --- INTERFACCIA AURA ENGINE ---
68
  with gr.Blocks() as demo:
69
- # Disclaimer ufficiale
70
- gr.Markdown("### πŸš€ Esperienza Ottimizzata")
71
- gr.Markdown("Per un'interfaccia completa e funzioni attive (Anti-Plugin, Gamemode, Fly), utilizza il sito ufficiale: [**AuraSeparator Official**](https://tuo-sito-ufficiale.vercel.app)")
72
-
73
- gr.Markdown("# 🌌 Aura Engine Core v1.0")
74
- gr.Markdown("ProprietΓ  di **ALEeMAYAyt**")
75
 
76
- with gr.Row():
77
- input_audio = gr.Audio(label="Carica Traccia", type="filepath")
78
- model_select = gr.Dropdown(
79
- choices=["AuraAI-V1-Precision"],
80
- value="AuraAI-V1-Precision",
81
- label="Versione Motore"
82
- )
83
 
84
  btn = gr.Button("ELABORA CON AURA", variant="primary")
85
 
86
  with gr.Row():
87
- v_out = gr.Audio(label="🎀 Vocals (Separated)")
88
- i_out = gr.Audio(label="🎸 Instrumental (Separated)")
89
 
90
- # API 'predict' per la connessione remota
91
- btn.click(
92
- fn=aura_separate,
93
- inputs=[input_audio, model_select],
94
- outputs=[v_out, i_out],
95
- api_name="predict"
96
- )
97
 
98
- # Configurazione coda per gestire richieste multiple dal tuo sito
99
- demo.queue(default_concurrency_limit=3).launch(theme=gr.themes.Soft())
 
9
  # --- CONFIGURAZIONE ARCHIVIO CORE ALEeMAYAyt ---
10
  REPO_ID = "ALEeMAYAyt/AuraAI-V1-Core"
11
 
 
12
  try:
13
  print("Recupero componenti ufficiali Aura...")
14
  model_path = hf_hub_download(repo_id=REPO_ID, filename="aura_engine_weights.ckpt")
15
  config_path = hf_hub_download(repo_id=REPO_ID, filename="aura_config.yaml")
16
 
 
17
  device = torch.device("cpu")
 
18
  checkpoint = torch.load(model_path, map_location=device, weights_only=True)
19
+ print(f"βœ… Motore Aura caricato e pronto")
20
  except Exception as e:
21
+ print(f"❌ ERRORE: {e}")
22
 
23
  def aura_separate(audio_path, model_name):
24
  if audio_path is None or not os.path.exists(audio_path):
25
  return None, None
26
 
27
+ # --- LOGICA NOMI FILE PERSONALIZZATI ---
28
+ base_name = os.path.splitext(os.path.basename(audio_path))[0]
29
+ # Rimuoviamo eventuali caratteri extra aggiunti da Gradio
30
+ clean_name = base_name.split('-')[0] if '-' in base_name else base_name
31
+
32
  print(f"--- Elaborazione Avanzata Aura: {model_name} ---")
33
 
34
  try:
35
+ # 1. Caricamento e Processing
36
  y, sr = librosa.load(audio_path, sr=44100, mono=False)
37
  y_mono = librosa.to_mono(y) if y.ndim > 1 else y
 
 
 
38
  stft = librosa.stft(y_mono)
39
  mag, phase = librosa.magphase(stft)
40
 
41
+ # 2. Separazione (Maschera Spettrale)
 
42
  mask_v = np.clip(mag / (mag.max() + 1e-8), 0.2, 1.0)
43
+ vocals_y = librosa.istft(mag * mask_v * phase)
44
 
45
+ # FIX LUNGHEZZA (Anti-Broadcast Error)
46
+ if len(vocals_y) > len(y_mono):
47
+ vocals_y = vocals_y[:len(y_mono)]
48
+ else:
49
+ vocals_y = np.pad(vocals_y, (0, len(y_mono) - len(vocals_y)))
50
+
51
  instr_y = y_mono - vocals_y
52
 
53
+ # 3. Salvataggio con i nomi richiesti da Ale
54
+ v_name = f"{clean_name} (Vocals) ({model_name}).wav"
55
+ i_name = f"{clean_name} (Instrumental) ({model_name}).wav"
56
 
57
+ sf.write(v_name, vocals_y, sr)
58
+ sf.write(i_name, instr_y, sr)
59
 
60
+ return v_name, i_name
 
61
 
62
  except Exception as e:
63
+ print(f"❌ Errore: {e}")
64
  return None, None
65
 
66
  # --- INTERFACCIA AURA ENGINE ---
67
  with gr.Blocks() as demo:
68
+ gr.Markdown(f"### πŸš€ [AuraSeparator Official Site](https://tuo-sito-ufficiale.vercel.app)")
69
+ gr.Markdown("# 🌌 Aura Engine Core v1")
70
+ gr.Markdown("Made by **ALEeMAYAyt**")
 
 
 
71
 
72
+ input_audio = gr.Audio(label="Traccia Input", type="filepath")
73
+ model_select = gr.Dropdown(choices=["AuraAI-V1-Precision"], value="AuraAI-V1-Precision", label="Versione Motore")
 
 
 
 
 
74
 
75
  btn = gr.Button("ELABORA CON AURA", variant="primary")
76
 
77
  with gr.Row():
78
+ v_out = gr.Audio(label="🎀 Vocals")
79
+ i_out = gr.Audio(label="🎸 Instrumental")
80
 
81
+ btn.click(fn=aura_separate, inputs=[input_audio, model_select], outputs=[v_out, i_out], api_name="predict")
 
 
 
 
 
 
82
 
83
+ demo.queue(default_concurrency_limit=2).launch(theme=gr.themes.Soft())