Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,15 +60,40 @@ def transcribe_audio(audio_path):
|
|
| 60 |
return raw_transcription, word_timestamps, transcription_with_timestamps
|
| 61 |
|
| 62 |
# -------------------------------------------------
|
| 63 |
-
# 3. Gestion du tableau éditable
|
| 64 |
# -------------------------------------------------
|
| 65 |
-
def add_row(metadata_state):
|
| 66 |
-
"""Ajoute
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
def save_segments(metadata_table):
|
| 74 |
"""Sauvegarde les modifications apportées par l'utilisateur."""
|
|
@@ -159,24 +184,16 @@ with gr.Blocks() as demo:
|
|
| 159 |
gr.Markdown("# Application de Découpe Audio")
|
| 160 |
|
| 161 |
metadata_state = gr.State(init_metadata_state())
|
| 162 |
-
|
| 163 |
audio_input = gr.Audio(type="filepath", label="Fichier audio")
|
| 164 |
-
raw_transcription = gr.Textbox(label="Transcription", interactive=False)
|
| 165 |
-
transcription_timestamps = gr.Textbox(label="Transcription avec Timestamps", interactive=False)
|
| 166 |
table = gr.Dataframe(label="Segments", headers=["Texte", "Début (s)", "Fin (s)", "ID"], datatype=["str", "number", "number", "str"], interactive=True)
|
| 167 |
|
| 168 |
-
add_row_button = gr.Button("Ajouter
|
| 169 |
save_button = gr.Button("Enregistrer")
|
| 170 |
validate_button = gr.Button("Valider")
|
| 171 |
generate_button = gr.Button("Générer ZIP")
|
| 172 |
-
zip_file = gr.File(label="Télécharger le ZIP")
|
| 173 |
-
|
| 174 |
-
word_timestamps = gr.State()
|
| 175 |
|
| 176 |
-
|
| 177 |
-
add_row_button.click(add_row, inputs=metadata_state, outputs=metadata_state)
|
| 178 |
save_button.click(save_segments, inputs=table, outputs=metadata_state)
|
| 179 |
-
validate_button.click(validate_segments, inputs=[audio_input, metadata_state], outputs=metadata_state)
|
| 180 |
-
generate_button.click(generate_zip, inputs=metadata_state, outputs=zip_file)
|
| 181 |
|
| 182 |
demo.queue().launch()
|
|
|
|
| 60 |
return raw_transcription, word_timestamps, transcription_with_timestamps
|
| 61 |
|
| 62 |
# -------------------------------------------------
|
| 63 |
+
# 3. Gestion du tableau éditable (Ajout dynamique)
|
| 64 |
# -------------------------------------------------
|
| 65 |
+
def add_row(metadata_state, new_rows):
|
| 66 |
+
"""Ajoute dynamiquement des lignes au tableau en suivant le format structuré."""
|
| 67 |
+
if new_rows is None:
|
| 68 |
+
new_rows = []
|
| 69 |
|
| 70 |
+
formatted_rows = []
|
| 71 |
+
|
| 72 |
+
# Gestion flexible des entrées (dictionnaires, listes, tuples, DataFrame)
|
| 73 |
+
if isinstance(new_rows, list):
|
| 74 |
+
for row in new_rows:
|
| 75 |
+
if isinstance(row, dict):
|
| 76 |
+
texte = row.get("Texte", "")
|
| 77 |
+
debut = row.get("Début (s)", None)
|
| 78 |
+
fin = row.get("Fin (s)", None)
|
| 79 |
+
elif isinstance(row, (list, tuple)) and len(row) >= 3:
|
| 80 |
+
texte, debut, fin = row[:3]
|
| 81 |
+
else:
|
| 82 |
+
continue
|
| 83 |
+
formatted_rows.append([texte, debut, fin, ""])
|
| 84 |
+
|
| 85 |
+
elif isinstance(new_rows, pd.DataFrame):
|
| 86 |
+
for _, row in new_rows.iterrows():
|
| 87 |
+
formatted_rows.append([row.get("Texte", ""), row.get("Début (s)", None), row.get("Fin (s)", None), ""])
|
| 88 |
+
|
| 89 |
+
# Conversion en DataFrame et fusion avec l'état actuel
|
| 90 |
+
if formatted_rows:
|
| 91 |
+
new_data = pd.DataFrame(formatted_rows, columns=["Texte", "Début (s)", "Fin (s)", "ID"])
|
| 92 |
+
metadata_state = pd.concat([metadata_state, new_data], ignore_index=True)
|
| 93 |
+
|
| 94 |
+
print(f"[LOG] {len(new_rows)} nouvelles lignes ajoutées.")
|
| 95 |
+
|
| 96 |
+
return metadata_state
|
| 97 |
|
| 98 |
def save_segments(metadata_table):
|
| 99 |
"""Sauvegarde les modifications apportées par l'utilisateur."""
|
|
|
|
| 184 |
gr.Markdown("# Application de Découpe Audio")
|
| 185 |
|
| 186 |
metadata_state = gr.State(init_metadata_state())
|
| 187 |
+
|
| 188 |
audio_input = gr.Audio(type="filepath", label="Fichier audio")
|
|
|
|
|
|
|
| 189 |
table = gr.Dataframe(label="Segments", headers=["Texte", "Début (s)", "Fin (s)", "ID"], datatype=["str", "number", "number", "str"], interactive=True)
|
| 190 |
|
| 191 |
+
add_row_button = gr.Button("Ajouter des lignes")
|
| 192 |
save_button = gr.Button("Enregistrer")
|
| 193 |
validate_button = gr.Button("Valider")
|
| 194 |
generate_button = gr.Button("Générer ZIP")
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
add_row_button.click(add_row, inputs=[metadata_state, table], outputs=metadata_state)
|
|
|
|
| 197 |
save_button.click(save_segments, inputs=table, outputs=metadata_state)
|
|
|
|
|
|
|
| 198 |
|
| 199 |
demo.queue().launch()
|