Spaces:
Runtime error
Runtime error
Ahsen Khaliq
commited on
Commit
·
7747139
1
Parent(s):
5a63ac8
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,2 @@
|
|
1 |
-
import soundfile as sf
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
from transformers import Speech2Text2Processor, SpeechEncoderDecoder
|
5 |
-
|
6 |
-
model = SpeechEncoderDecoder.from_pretrained("facebook/s2t-wav2vec2-large-en-de")
|
7 |
-
processor = Speech2Text2Processor.from_pretrained("facebook/s2t-wav2vec2-large-en-de")
|
8 |
-
|
9 |
-
def map_to_array(file):
|
10 |
-
speech, _ = sf.read(file)
|
11 |
-
return speech
|
12 |
-
|
13 |
-
def inference(audio):
|
14 |
-
inputs = processor(map_to_array(audio.name), sampling_rate=16_000, return_tensors="pt")
|
15 |
-
generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"])
|
16 |
-
transcription = processor.batch_decode(generated_ids)
|
17 |
-
return transcription[0]
|
18 |
-
inputs = gr.inputs.Audio(label="Input Audio", type="file")
|
19 |
-
outputs = gr.outputs.Textbox(label="Output Text")
|
20 |
-
title = "Robust wav2vec 2.0"
|
21 |
-
description = "Gradio demo for Robust wav2vec 2.0. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below. Currently supports .wav and .flac files"
|
22 |
-
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2104.01027' target='_blank'>Robust wav2vec 2.0: Analyzing Domain Shift in Self-Supervised Pre-Training</a> | <a href='https://github.com/pytorch/fairseq' target='_blank'>Github Repo</a></p>"
|
23 |
-
examples=[['poem.wav']]
|
24 |
-
gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
gr.Interface.load('huggingface/facebook/s2t-wav2vec2-large-en-de').launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|