File size: 949 Bytes
bc3643e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration

# load mode
model_name = "openai/whisper-medium"
processor = WhisperProcessor.from_pretrained(model_name,language="lo")
model = WhisperForConditionalGeneration.from_pretrained(model_dir)

asr = pipeline(
    "automatic-speech-recognition",
    model= "LuoYiSULIXAY/whisper-lao-finetuned_laonlp",
    tokenizer=processor.tokenizer,
    feature_extractor=processor.feature_extractor,
    device=-1  
)

def transcribe(audio):
    result = asr(audio, generate_kwargs={"language": "lao", "task": "transcribe"})
    return result["text"]

demo = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(type="filepath",streaming=False),  # ✅ 正确写法
    outputs="text",
    title="Whisper Lao",
    description="Realtime demo for Lao speech recognition using a fine-tuned Whisper model.",
)

demo.launch(share=True)