Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
import gradio as gr | |
import re | |
import torch | |
from pyctcdecode import BeamSearchDecoderCTC | |
import torch | |
import librosa | |
import time | |
lmID = "aware-ai/german-lowercase-4gram-kenlm" | |
decoder = BeamSearchDecoderCTC.load_from_hf_hub(lmID) | |
p = pipeline("automatic-speech-recognition", model="aware-ai/robust-wav2vec2-base-german-lowercase", decoder=decoder) | |
ttp = pipeline("text2text-generation", model="aware-ai/marian-german-grammar") | |
def transcribe(audio): | |
transcribed = p(audio[1], chunk_length_s=20, stride_length_s=(0, 0))["text"] | |
return transcribed | |
def punctuate(text): | |
punctuated = ttp(text, max_length = 512)[0]["generated_text"] | |
return punctuated | |
def get_asr_interface(): | |
return gr.Interface( | |
fn=transcribe, | |
inputs=[ | |
gr.inputs.Audio(source="microphone") | |
], | |
outputs=[ | |
"textbox", | |
]) | |
def get_punctuate_interface(): | |
return gr.Interface( | |
fn=punctuate, | |
inputs=[ | |
"textbox" | |
], | |
outputs=[ | |
"textbox", | |
]) | |
interfaces = [ | |
get_asr_interface(), | |
get_punctuate_interface(), | |
] | |
gradio.Series(interfaces).launch(server_name = "0.0.0.0") |