Spaces:
Runtime error
Runtime error
ismaeltorres00
commited on
Commit
•
374f519
1
Parent(s):
7edf4a1
Create app2.py
Browse files
app2.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
import numpy as np
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Definir los modelos
|
8 |
+
modelos = {
|
9 |
+
"base": pipeline("automatic-speech-recognition", model="aitor-medrano/lara-base-pushed"),
|
10 |
+
"small_1": pipeline("automatic-speech-recognition", model="aitor-medrano/whisper-small-lara"),
|
11 |
+
"small_2": pipeline("automatic-speech-recognition", model="aitor-medrano/whisper-small-lara")
|
12 |
+
}
|
13 |
+
|
14 |
+
def greet(grabacion):
|
15 |
+
inicio = time.perf_counter()
|
16 |
+
|
17 |
+
sr, y = grabacion
|
18 |
+
# Normalizar el array de muestras
|
19 |
+
y = (y / np.max(np.abs(y))).astype(np.float32)
|
20 |
+
|
21 |
+
resultados = []
|
22 |
+
tiempos = []
|
23 |
+
|
24 |
+
for nombre_modelo, modelo in modelos.items():
|
25 |
+
inicio_modelo = time.perf_counter()
|
26 |
+
texto_resultado = modelo({"sampling_rate": sr, "raw": y})["text"]
|
27 |
+
fin_modelo = time.perf_counter()
|
28 |
+
resultados.append(f"{nombre_modelo}: {texto_resultado}")
|
29 |
+
tiempos.append(fin_modelo - inicio_modelo)
|
30 |
+
|
31 |
+
tiempo_total = time.perf_counter() - inicio
|
32 |
+
|
33 |
+
return (*resultados, *tiempos, tiempo_total)
|
34 |
+
|
35 |
+
# Crear la interfaz mejorada
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("# Evaluación de Modelos de Reconocimiento Automático de Voz")
|
38 |
+
|
39 |
+
with gr.Tab("Ingreso de Audio"):
|
40 |
+
gr.Audio(label="Graba tu audio", source="microphone", type="numpy", elem_id="audio_input")
|
41 |
+
|
42 |
+
with gr.Tab("Resultados y Tiempos"):
|
43 |
+
with gr.Column():
|
44 |
+
with gr.Row():
|
45 |
+
gr.Textbox(label="Resultado Modelo 1", interactive=False, elem_id="resultado1")
|
46 |
+
gr.Number(label="Tiempo Modelo 1 (s)", interactive=False, elem_id="tiempo1")
|
47 |
+
with gr.Row():
|
48 |
+
gr.Textbox(label="Resultado Modelo 2", interactive=False, elem_id="resultado2")
|
49 |
+
gr.Number(label="Tiempo Modelo 2 (s)", interactive=False, elem_id="tiempo2")
|
50 |
+
with gr.Row():
|
51 |
+
gr.Textbox(label="Resultado Modelo 3", interactive=False, elem_id="resultado3")
|
52 |
+
gr.Number(label="Tiempo Modelo 3 (s)", interactive=False, elem_id="tiempo3")
|
53 |
+
with gr.Row():
|
54 |
+
gr.Number(label="Tiempo Total (s)", interactive=False, elem_id="tiempo_total")
|
55 |
+
|
56 |
+
demo.add_component(gr.Button("Procesar", variant="primary", elem_id="process_button"))
|
57 |
+
|
58 |
+
demo.load(greet, inputs="audio_input", outputs=["resultado1", "resultado2", "resultado3", "tiempo1", "tiempo2", "tiempo3", "tiempo_total"], elem_id="process_button")
|
59 |
+
|
60 |
+
demo.launch()
|