aitor-medrano commited on
Commit
a0414ee
1 Parent(s): 4921f0d

Create app_dropdown.py

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