Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
|
4 |
+
transcribe = pipeline("automatic-speech-recognition")
|
5 |
+
def speech_to_text(audio):
|
6 |
+
text = transcribe(audio)["text"]
|
7 |
+
|
8 |
+
model_inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
9 |
+
generated_tokens = model.generate(
|
10 |
+
**model_inputs,
|
11 |
+
forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]
|
12 |
+
)
|
13 |
+
|
14 |
+
translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
15 |
+
|
16 |
+
return translation
|
17 |
+
|
18 |
+
gr.Interface(
|
19 |
+
fn=speech_to_text,
|
20 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
21 |
+
outputs="text").launch()
|