Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import torchaudio
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
asr = pipeline("automatic-speech-recognition", model="gigant/romanian-wav2vec2")
|
8 |
+
|
9 |
+
def f(audio):
|
10 |
+
rate, sample = audio
|
11 |
+
resampler = torchaudio.transforms.Resample(rate, 16_000)
|
12 |
+
sample_16 = resampler(torch.Tensor(sample)).numpy()
|
13 |
+
return asr(sample_16)["text"]
|
14 |
+
|
15 |
+
app = gr.Interface(fn=f, inputs=gr.inputs.Audio(source="upload", type="numpy", label="Audio"), outputs=gr.outputs.Textbox(type="str", label="Predicted text"))
|
16 |
+
app.launch()
|