Spaces:
Running
Running
File size: 1,066 Bytes
884123a edbeae5 1f27015 884123a edbeae5 884123a edbeae5 1c12178 884123a 1f27015 4d98a44 |
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 torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
import gradio as gr
device = "cpu" # Free CPU only
torch_dtype = torch.float32
model_id = "KBLab/kb-whisper-large"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype
).to(device)
processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
device=device,
torch_dtype=torch_dtype,
)
def transcribe(audio):
result = pipe(audio, chunk_length_s=30, generate_kwargs={"task": "transcribe", "language": "sv"})
return result["text"]
gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath", label="Upload Swedish Audio"),
outputs=gr.Textbox(label="Transcribed Text"),
title="KB-Whisper Transcriber (Swedish, Free CPU)",
description="Transcribes Swedish audio using KBLab's Whisper Large model. Running on free CPU — may be slow."
).launch(share=True) |