File size: 1,397 Bytes
a943a84
 
 
 
4ebd06e
4da8f76
a943a84
 
 
 
 
 
 
 
 
 
 
286eb75
4da8f76
 
 
a943a84
4da8f76
 
a943a84
 
286eb75
4da8f76
286eb75
 
4da8f76
 
 
 
286eb75
 
4da8f76
 
286eb75
 
4da8f76
286eb75
 
a943a84
10a369e
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
36
37
38
39
40
41
42
43
44
45
46
import torch
import gradio as gr
from transformers import pipeline

MODEL_NAME = "BlueRaccoon/whisper-small-kab"
lang = "kab"  # Language updated to Kabyle

device = 0 if torch.cuda.is_available() else "cpu"
pipe = pipeline(
    task="automatic-speech-recognition",
    model=MODEL_NAME,
    chunk_length_s=30,
    device=device,
)

pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")


def transcribe(microphone):
    if microphone is None:
        return "ERROR: You need to record or upload an audio file."

    text = pipe(microphone)["text"]
    return text


with gr.Blocks() as demo:
    with gr.Tab("Transcribe Kabyle Audio"):
        gr.Markdown(
            f"""
            # Kabyle Whisper Demo: Transcribe Audio
            Transcribe Kabyle audio recorded from the microphone or uploaded as a file. This demo uses the fine-tuned
            checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to transcribe Kabyle audio
            files of arbitrary length.
            """
        )
        # Input for microphone recording only
        microphone_input = gr.Audio(type="filepath", label="Record or Upload Kabyle Audio")
        gr.Interface(
            fn=transcribe,
            inputs=[microphone_input],
            outputs=gr.Textbox(label="Transcription"),
        )

demo.launch()