Spaces:
Runtime error
Runtime error
Commit
路
8bc597c
1
Parent(s):
7cd200e
Testing txt output in WHISPERX
Browse files- README.md +11 -0
- app.py +26 -25
- helpers.py +1 -1
README.md
CHANGED
@@ -51,3 +51,14 @@ The user will logging using a password and user specified by me. That user and p
|
|
51 |
|
52 |
Introduce Tab for analysis including POS. Maybe it would be great to have a visualizer with the timestamps and other features in Streamlit. Quizas correcciones.
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
Introduce Tab for analysis including POS. Maybe it would be great to have a visualizer with the timestamps and other features in Streamlit. Quizas correcciones.
|
53 |
|
54 |
+
## Dev
|
55 |
+
|
56 |
+
I used huggingface lfs
|
57 |
+
|
58 |
+
```
|
59 |
+
git install lfs
|
60 |
+
```
|
61 |
+
|
62 |
+
```
|
63 |
+
huggingface-cli lfs-enable-largefiles .
|
64 |
+
```
|
app.py
CHANGED
@@ -7,7 +7,7 @@ from transformers.pipelines.audio_utils import ffmpeg_read
|
|
7 |
from transcription import fast_transcription, speech_to_text, doWhisperX
|
8 |
from whisperx.utils import get_writer
|
9 |
from audio import normalizeAudio, separateVoiceInstrumental, mp3_to_wav, stereo_to_mono, cutaudio, compose_audio
|
10 |
-
from helpers import guardar_en_archivo, guardar_dataframe_en_csv
|
11 |
|
12 |
import json
|
13 |
|
@@ -57,19 +57,8 @@ def transcribeWhisperX(audiofile, model, language, patiente,
|
|
57 |
#nombre_archivo = guardar_en_archivo(out)
|
58 |
|
59 |
##########################################################################
|
60 |
-
import whisperx
|
61 |
from pathlib import Path
|
62 |
-
|
63 |
-
# model_a, metadata = whisperx.load_align_model(
|
64 |
-
# language_code="es", device=device
|
65 |
-
# )
|
66 |
-
# result_aligned = whisperx.align(
|
67 |
-
# result["segments"],
|
68 |
-
# model_a,
|
69 |
-
# metadata,
|
70 |
-
# vocal_path,
|
71 |
-
# device=device,
|
72 |
-
# )
|
73 |
import datetime
|
74 |
fecha_actual = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
75 |
|
@@ -81,17 +70,19 @@ def transcribeWhisperX(audiofile, model, language, patiente,
|
|
81 |
srt_writer = get_writer("srt", Path("."))
|
82 |
result_aligned["language"] = language
|
83 |
srt_writer(result_aligned, file_path, writter_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
# with open(
|
86 |
-
# nombre_archivo,
|
87 |
-
# "w",
|
88 |
-
# encoding="utf-8",
|
89 |
-
# ) as srt:
|
90 |
-
# write_srt(result_aligned["segments"], file=srt)
|
91 |
###########################################################################
|
92 |
|
93 |
-
|
|
|
94 |
|
|
|
95 |
|
96 |
transcribeI = gr.Interface(
|
97 |
fn=transcribe,
|
@@ -135,10 +126,11 @@ transcribeII = gr.Interface(
|
|
135 |
gr.Audio(type="filepath", label="normalized"),
|
136 |
gr.Audio(type="filepath", label="vocal"),
|
137 |
gr.Audio(type="filepath", label="no_vocal"),
|
138 |
-
gr.
|
139 |
-
gr.File(label="Archivo
|
140 |
-
gr.File(label="
|
141 |
-
gr.
|
|
|
142 |
#gr.JSON(label="JSON Output"),
|
143 |
#gr.File(label="Archivo generado")
|
144 |
],
|
@@ -148,7 +140,16 @@ transcribeII = gr.Interface(
|
|
148 |
"Esta p谩gina realiza una transcripci贸n de audio utilizando Whisper. Adem谩s a帽ade varias mejoras y utilidades: a) Preprocesamiento del audio y limpieza de ruido ambiental, b) Conversi贸n de los archivos de audio a un formato compatible con Whisper, c) C谩lculo de la marca temporal palabra por palabra, d) C谩lculo del nivel de seguridad de la transcripci贸n, e) Conversi贸n del resultado a .csv, .srt y ass.\n"
|
149 |
),
|
150 |
allow_flagging="never",
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
)
|
154 |
|
|
|
7 |
from transcription import fast_transcription, speech_to_text, doWhisperX
|
8 |
from whisperx.utils import get_writer
|
9 |
from audio import normalizeAudio, separateVoiceInstrumental, mp3_to_wav, stereo_to_mono, cutaudio, compose_audio
|
10 |
+
from helpers import guardar_en_archivo, guardar_dataframe_en_csv, generar_transcripcion
|
11 |
|
12 |
import json
|
13 |
|
|
|
57 |
#nombre_archivo = guardar_en_archivo(out)
|
58 |
|
59 |
##########################################################################
|
|
|
60 |
from pathlib import Path
|
61 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
import datetime
|
63 |
fecha_actual = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
64 |
|
|
|
70 |
srt_writer = get_writer("srt", Path("."))
|
71 |
result_aligned["language"] = language
|
72 |
srt_writer(result_aligned, file_path, writter_args)
|
73 |
+
###########################################################################
|
74 |
+
|
75 |
+
# Creating the txt
|
76 |
+
|
77 |
+
lineas_txt, nombre_file_txt = generar_transcripcion(diarize_segments)
|
78 |
+
lineas_txt_string = "\n".join(lineas_txt)
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
###########################################################################
|
81 |
|
82 |
+
outputs = (audio_path, audio_normalized_path, vocal_path, novocal_path, lineas_txt_string, nombre_file_txt,
|
83 |
+
str(file_path), guardar_dataframe_en_csv(diarize_segments), json.dumps(result_speakers))
|
84 |
|
85 |
+
return outputs
|
86 |
|
87 |
transcribeI = gr.Interface(
|
88 |
fn=transcribe,
|
|
|
126 |
gr.Audio(type="filepath", label="normalized"),
|
127 |
gr.Audio(type="filepath", label="vocal"),
|
128 |
gr.Audio(type="filepath", label="no_vocal"),
|
129 |
+
gr.TextArea(label="Transcripci贸n"),
|
130 |
+
gr.File(label="Archivo TXT generado"),
|
131 |
+
gr.File(label="Archivo SRT generado con turno de palabra"),
|
132 |
+
gr.File(label="Archivo CSV generado con turno de palabra"),
|
133 |
+
gr.JSON(label="Resultados estructurados en JSON palabra por palabra"),
|
134 |
#gr.JSON(label="JSON Output"),
|
135 |
#gr.File(label="Archivo generado")
|
136 |
],
|
|
|
140 |
"Esta p谩gina realiza una transcripci贸n de audio utilizando Whisper. Adem谩s a帽ade varias mejoras y utilidades: a) Preprocesamiento del audio y limpieza de ruido ambiental, b) Conversi贸n de los archivos de audio a un formato compatible con Whisper, c) C谩lculo de la marca temporal palabra por palabra, d) C谩lculo del nivel de seguridad de la transcripci贸n, e) Conversi贸n del resultado a .csv, .srt y ass.\n"
|
141 |
),
|
142 |
allow_flagging="never",
|
143 |
+
examples=[["Espana 04 - Video 01 - extracto 2 min.wav",
|
144 |
+
"large-v2",
|
145 |
+
"Cualquiera",
|
146 |
+
0.5,
|
147 |
+
"",
|
148 |
+
"",
|
149 |
+
0.5,
|
150 |
+
0.5,
|
151 |
+
0.5,
|
152 |
+
0.5]]
|
153 |
|
154 |
)
|
155 |
|
helpers.py
CHANGED
@@ -77,5 +77,5 @@ def generar_transcripcion(dataframe):
|
|
77 |
# Guardamos la transcripci贸n en un archivo de texto
|
78 |
nombre_archivo = guardar_en_archivo(lineas_transcripcion)
|
79 |
|
80 |
-
return nombre_archivo
|
81 |
|
|
|
77 |
# Guardamos la transcripci贸n en un archivo de texto
|
78 |
nombre_archivo = guardar_en_archivo(lineas_transcripcion)
|
79 |
|
80 |
+
return lineas_transcripcion, nombre_archivo
|
81 |
|