hugoiabd commited on
Commit
64db4c7
1 Parent(s): 7cdbaf9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+ import numpy as np
5
+ import time
6
+
7
+ pipe_base = pipeline("automatic-speech-recognition", model="aitor-medrano/lara-base-pushed")
8
+ pipe_small = pipeline("automatic-speech-recognition", model="aitor-medrano/whisper-small-lara")
9
+
10
+ def greet(grabacion, modelo="base"):
11
+
12
+ inicio = time.time()
13
+
14
+ sr, y = grabacion
15
+ # Pasamos el array de muestras a tipo NumPy de 32 bits
16
+ y = y.astype(np.float32)
17
+ y /= np.max(np.abs(y))
18
+
19
+ if modelo is not None and modelo == "base":
20
+ pipe = pipe_base
21
+ else:
22
+ modelo = "small"
23
+ pipe = pipe_small
24
+
25
+ result = modelo + ":" + pipe({"sampling_rate": sr, "raw": y})["text"]
26
+ fin = time.time()
27
+
28
+ return result, fin - inicio
29
+
30
+ demo = gr.Interface(fn=greet,
31
+ inputs=[
32
+ gr.Audio(),
33
+ gr.Dropdown(
34
+ ["base", "small"], label="Modelo", info="Modelos de Lara entrenados"
35
+ )
36
+ ],
37
+ outputs=[
38
+ gr.Text(label="Salida"),
39
+ gr.Number(label="Tiempo")
40
+ ])
41
+ demo.launch()