Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,11 +17,12 @@ import nemo.collections.nlp as nemo_nlp
|
|
| 17 |
# ----------------------------------------------------------------------
|
| 18 |
# CONSTANTES DE CONFIGURATION
|
| 19 |
# ----------------------------------------------------------------------
|
|
|
|
| 20 |
ROBOTSMALI_MODELS = [
|
| 21 |
"RobotsMali/soloba-ctc-0.6b-v0",
|
| 22 |
"RobotsMali/soloni-114m-tdt-ctc-v1",
|
| 23 |
"RobotsMali/soloni-114m-tdt-ctc-V0",
|
| 24 |
-
"RobotsMali/stt-bm-quartznet5x5-V0",
|
| 25 |
"RobotsMali/stt-bm-quartznet5x5-v1",
|
| 26 |
"RobotsMali/soloba-ctc-0.6b-v1"
|
| 27 |
]
|
|
@@ -85,8 +86,12 @@ def load_punct_model():
|
|
| 85 |
# ----------------------------------------------------------------------
|
| 86 |
def transcribe_audio(model_name: str, audio_path: str):
|
| 87 |
"""
|
| 88 |
-
Effectue la transcription ASR de l'audio complet avec une barre de progression
|
| 89 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if audio_path is None:
|
| 91 |
yield "⚠️ Veuillez d'abord télécharger ou enregistrer un fichier audio."
|
| 92 |
return
|
|
@@ -104,7 +109,7 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 104 |
full_audio_data, sr = librosa.load(audio_path, sr=SR_TARGET, mono=True)
|
| 105 |
total_duration = len(full_audio_data) / SR_TARGET
|
| 106 |
|
| 107 |
-
# Correction de la forme audio (squeeze)
|
| 108 |
segment_data = full_audio_data.squeeze()
|
| 109 |
sf.write(temp_full_path, segment_data, SR_TARGET)
|
| 110 |
|
|
@@ -121,11 +126,10 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 121 |
yield f"**[3/4] TRANSCRIPTION EN COURS...** Démarrage de l'inférence. ⏳"
|
| 122 |
|
| 123 |
# --- BARRE DE PROGRESSION SIMULÉE ---
|
| 124 |
-
# Affiche une progression visuelle pendant l'attente de l'inférence GPU
|
| 125 |
for progress_percent in range(0, 91, 10):
|
| 126 |
time.sleep(0.3)
|
| 127 |
-
#
|
| 128 |
-
|
| 129 |
|
| 130 |
yield f"**[3/4] FINALISATION...** Inférence en cours sur le GPU. 🚀"
|
| 131 |
# ---------------------------------------------
|
|
@@ -138,7 +142,6 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 138 |
if transcriptions and transcriptions[0]:
|
| 139 |
hyp_object = transcriptions[0]
|
| 140 |
|
| 141 |
-
# Gère les différents formats de sortie de NeMo
|
| 142 |
if hasattr(hyp_object, 'text'):
|
| 143 |
transcription_text_final = hyp_object.text.strip()
|
| 144 |
elif isinstance(hyp_object, str):
|
|
@@ -161,7 +164,8 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 161 |
punct_model = load_punct_model()
|
| 162 |
if punct_model and transcription_text_final != "[Transcription vide ou échec ASR]":
|
| 163 |
yield f"**[4/4] POST-TRAITEMENT...** Correction de la ponctuation et de la casse pour la lisibilité. ✨"
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
try:
|
| 167 |
corrected_list = punct_model.add_punctuation_capitalization([transcription_text_final])
|
|
@@ -179,7 +183,6 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 179 |
|
| 180 |
# 2. PRÉSENTATION LYRICS PROPRE
|
| 181 |
output += "**RÉSULTAT DE LA TRANSCRIPTION (Lyrics) :**\n"
|
| 182 |
-
# Formatage du texte pour l'affichage Markdown
|
| 183 |
formatted_lyrics = processed_text.replace('\n', ' ').strip().replace('. ', '.\n\n>>> ').replace('? ', '?\n\n>>> ')
|
| 184 |
if not formatted_lyrics.startswith('>>> '):
|
| 185 |
formatted_lyrics = '>>> ' + formatted_lyrics
|
|
@@ -195,6 +198,7 @@ def transcribe_audio(model_name: str, audio_path: str):
|
|
| 195 |
yield f"❌ Erreur critique lors du chargement : {str(e)}"
|
| 196 |
|
| 197 |
except Exception as e:
|
|
|
|
| 198 |
yield f"❌ Erreur générale lors de la transcription complète : {e}"
|
| 199 |
|
| 200 |
finally:
|
|
|
|
| 17 |
# ----------------------------------------------------------------------
|
| 18 |
# CONSTANTES DE CONFIGURATION
|
| 19 |
# ----------------------------------------------------------------------
|
| 20 |
+
# Liste de modèles mise à jour et vérifiée (conforme à RobotsMali sur HF)
|
| 21 |
ROBOTSMALI_MODELS = [
|
| 22 |
"RobotsMali/soloba-ctc-0.6b-v0",
|
| 23 |
"RobotsMali/soloni-114m-tdt-ctc-v1",
|
| 24 |
"RobotsMali/soloni-114m-tdt-ctc-V0",
|
| 25 |
+
"RobotsMali/stt-bm-quartznet5x5-V0",
|
| 26 |
"RobotsMali/stt-bm-quartznet5x5-v1",
|
| 27 |
"RobotsMali/soloba-ctc-0.6b-v1"
|
| 28 |
]
|
|
|
|
| 86 |
# ----------------------------------------------------------------------
|
| 87 |
def transcribe_audio(model_name: str, audio_path: str):
|
| 88 |
"""
|
| 89 |
+
Effectue la transcription ASR de l'audio complet avec une barre de progression stylée.
|
| 90 |
"""
|
| 91 |
+
# CORRECTION DE L'ERREUR GRADIO : Initialisation correcte de gr.Progress
|
| 92 |
+
progress = gr.Progress()
|
| 93 |
+
progress(0, desc="Démarrage du traitement")
|
| 94 |
+
|
| 95 |
if audio_path is None:
|
| 96 |
yield "⚠️ Veuillez d'abord télécharger ou enregistrer un fichier audio."
|
| 97 |
return
|
|
|
|
| 109 |
full_audio_data, sr = librosa.load(audio_path, sr=SR_TARGET, mono=True)
|
| 110 |
total_duration = len(full_audio_data) / SR_TARGET
|
| 111 |
|
| 112 |
+
# Correction de la forme audio (squeeze)
|
| 113 |
segment_data = full_audio_data.squeeze()
|
| 114 |
sf.write(temp_full_path, segment_data, SR_TARGET)
|
| 115 |
|
|
|
|
| 126 |
yield f"**[3/4] TRANSCRIPTION EN COURS...** Démarrage de l'inférence. ⏳"
|
| 127 |
|
| 128 |
# --- BARRE DE PROGRESSION SIMULÉE ---
|
|
|
|
| 129 |
for progress_percent in range(0, 91, 10):
|
| 130 |
time.sleep(0.3)
|
| 131 |
+
# Utilisation de la syntaxe correcte : progress(valeur_flottante, description)
|
| 132 |
+
progress(progress_percent / 100, desc=f"Progression ASR ({progress_percent}%)")
|
| 133 |
|
| 134 |
yield f"**[3/4] FINALISATION...** Inférence en cours sur le GPU. 🚀"
|
| 135 |
# ---------------------------------------------
|
|
|
|
| 142 |
if transcriptions and transcriptions[0]:
|
| 143 |
hyp_object = transcriptions[0]
|
| 144 |
|
|
|
|
| 145 |
if hasattr(hyp_object, 'text'):
|
| 146 |
transcription_text_final = hyp_object.text.strip()
|
| 147 |
elif isinstance(hyp_object, str):
|
|
|
|
| 164 |
punct_model = load_punct_model()
|
| 165 |
if punct_model and transcription_text_final != "[Transcription vide ou échec ASR]":
|
| 166 |
yield f"**[4/4] POST-TRAITEMENT...** Correction de la ponctuation et de la casse pour la lisibilité. ✨"
|
| 167 |
+
# Termine la barre de progression
|
| 168 |
+
progress(1.0, desc="Progression ASR (100%)")
|
| 169 |
|
| 170 |
try:
|
| 171 |
corrected_list = punct_model.add_punctuation_capitalization([transcription_text_final])
|
|
|
|
| 183 |
|
| 184 |
# 2. PRÉSENTATION LYRICS PROPRE
|
| 185 |
output += "**RÉSULTAT DE LA TRANSCRIPTION (Lyrics) :**\n"
|
|
|
|
| 186 |
formatted_lyrics = processed_text.replace('\n', ' ').strip().replace('. ', '.\n\n>>> ').replace('? ', '?\n\n>>> ')
|
| 187 |
if not formatted_lyrics.startswith('>>> '):
|
| 188 |
formatted_lyrics = '>>> ' + formatted_lyrics
|
|
|
|
| 198 |
yield f"❌ Erreur critique lors du chargement : {str(e)}"
|
| 199 |
|
| 200 |
except Exception as e:
|
| 201 |
+
# L'erreur de progression étant corrigée, cette ligne gère les autres erreurs
|
| 202 |
yield f"❌ Erreur générale lors de la transcription complète : {e}"
|
| 203 |
|
| 204 |
finally:
|