aitor-medrano commited on
Commit
2ffd512
·
verified ·
1 Parent(s): 0c925a6

Added time to output and default model value

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -2,11 +2,15 @@ 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/lara-base-pushed")
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)
@@ -17,14 +21,17 @@ def greet(modelo, grabacion):
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()
 
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(modelo="Base", grabacion):
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)
 
21
  else:
22
  pipe = pipe_small
23
 
24
+ result = modelo + ":" + pipe({"sampling_rate": sr, "raw": y})["text"]
25
+ fin = time.time()
26
+
27
+ return result, fin - inicio
28
 
29
  demo = gr.Interface(fn=greet,
30
+ inputs=[
31
+ gr.Dropdown(
32
+ ["base", "small"], label="Modelo", info="Modelos de Lara entrenados"
33
+ ),
34
+ gr.Audio()
35
+ ],
36
+ outputs=["text","number"])
37
  demo.launch()