Spaces:
Running
Running
File size: 921 Bytes
6beb61d de11171 477d5da 6beb61d 477d5da 6beb61d 477d5da 6beb61d de11171 477d5da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
from pathlib import Path
from transformers import pipeline
model_id = "Sandiago21/whisper-large-v2-spanish"
cache_path = Path("~/.cache/huggingface/transformers") / model_id
if not cache_path.is_dir():
pipe = pipeline("automatic-speech-recognition", model=model_id)
else:
pipe = pipeline("automatic-speech-recognition", model=cache_path)
def transcribe_speech(filepath):
output = pipe(
filepath,
max_new_tokens=256,
generate_kwargs={
"task": "transcribe",
"language": "spanish",
},
chunk_length_s=30,
batch_size=8,
)
return output["text"]
demo = gr.Blocks()
mic_transcribe = gr.Interface(
fn=transcribe_speech,
inputs=gr.Audio(source="microphone", type="filepath"),
outputs=gr.outputs.Textbox(),
)
if __name__ == "__main__":
mic_transcribe.launch(share=True, host="0.0.0.0", port=7860) |