Spaces:
Runtime error
Runtime error
Commit
路
9dba6bb
1
Parent(s):
2cce248
method for creating the final text
Browse files- app.py +3 -2
- helpers.py +41 -0
app.py
CHANGED
@@ -88,7 +88,7 @@ def transcribeWhisperX(audiofile, model, language, patiente,
|
|
88 |
# write_srt(result_aligned["segments"], file=srt)
|
89 |
###########################################################################
|
90 |
|
91 |
-
return audio_path, audio_normalized_path, vocal_path, novocal_path, vocal_path, guardar_dataframe_en_csv(diarize_segments), json.dumps(result_speakers)
|
92 |
|
93 |
|
94 |
transcribeI = gr.Interface(
|
@@ -133,7 +133,8 @@ transcribeII = gr.Interface(
|
|
133 |
gr.Audio(type="filepath", label="normalized"),
|
134 |
gr.Audio(type="filepath", label="vocal"),
|
135 |
gr.Audio(type="filepath", label="no_vocal"),
|
136 |
-
|
|
|
137 |
gr.File(label="Tabla con diarizaci贸n generada"),
|
138 |
gr.JSON(label="JSON Output"),
|
139 |
#gr.JSON(label="JSON Output"),
|
|
|
88 |
# write_srt(result_aligned["segments"], file=srt)
|
89 |
###########################################################################
|
90 |
|
91 |
+
return audio_path, audio_normalized_path, vocal_path, novocal_path, vocal_path, str(file_path.stem), guardar_dataframe_en_csv(diarize_segments), json.dumps(result_speakers)
|
92 |
|
93 |
|
94 |
transcribeI = gr.Interface(
|
|
|
133 |
gr.Audio(type="filepath", label="normalized"),
|
134 |
gr.Audio(type="filepath", label="vocal"),
|
135 |
gr.Audio(type="filepath", label="no_vocal"),
|
136 |
+
gr.File(label="Archivo SRT generado"),
|
137 |
+
gr.File(label="Archivo CSV generado"),
|
138 |
gr.File(label="Tabla con diarizaci贸n generada"),
|
139 |
gr.JSON(label="JSON Output"),
|
140 |
#gr.JSON(label="JSON Output"),
|
helpers.py
CHANGED
@@ -38,3 +38,44 @@ def dataframe_a_lista(df):
|
|
38 |
lista_strings = df_str.apply(lambda row: ' '.join(row), axis=1).tolist()
|
39 |
|
40 |
return lista_strings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
lista_strings = df_str.apply(lambda row: ' '.join(row), axis=1).tolist()
|
39 |
|
40 |
return lista_strings
|
41 |
+
|
42 |
+
def generar_transcripcion(dataframe):
|
43 |
+
# Ordenamos el DataFrame por Timestamp
|
44 |
+
dataframe = dataframe.sort_values(by='Timestamp')
|
45 |
+
|
46 |
+
# Creamos un diccionario para almacenar los textos de cada speaker
|
47 |
+
textos_por_speaker = {}
|
48 |
+
|
49 |
+
# Iteramos sobre las filas del DataFrame
|
50 |
+
for index, row in dataframe.iterrows():
|
51 |
+
# Obtenemos los valores de la fila
|
52 |
+
timestamp = row['Timestamp']
|
53 |
+
speaker = row['speaker']
|
54 |
+
texto = row['text']
|
55 |
+
|
56 |
+
# Si el speaker no est谩 en el diccionario, lo agregamos
|
57 |
+
if speaker not in textos_por_speaker:
|
58 |
+
textos_por_speaker[speaker] = []
|
59 |
+
|
60 |
+
# Agregamos el texto al diccionario
|
61 |
+
textos_por_speaker[speaker].append(texto)
|
62 |
+
|
63 |
+
# Creamos una lista para almacenar las l铆neas de la transcripci贸n
|
64 |
+
lineas_transcripcion = []
|
65 |
+
|
66 |
+
# Iteramos sobre los speakers y sus textos
|
67 |
+
for speaker, textos in textos_por_speaker.items():
|
68 |
+
# Creamos un p谩rrafo con todos los textos del speaker
|
69 |
+
parrafo = ' '.join(textos)
|
70 |
+
|
71 |
+
# Agregamos la l铆nea de la transcripci贸n con el timestamp y el speaker
|
72 |
+
linea = f"{timestamp} - {speaker}: {parrafo}"
|
73 |
+
|
74 |
+
# Agregamos la l铆nea a la lista de la transcripci贸n
|
75 |
+
lineas_transcripcion.append(linea)
|
76 |
+
|
77 |
+
# Guardamos la transcripci贸n en un archivo de texto
|
78 |
+
nombre_archivo = guardar_en_archivo(lineas_transcripcion)
|
79 |
+
|
80 |
+
return nombre_archivo
|
81 |
+
|