File size: 1,250 Bytes
d23e0cd
59c621c
6422215
59c621c
5390b32
59c621c
 
 
 
 
 
 
 
 
 
5390b32
59c621c
 
 
 
6422215
59c621c
6422215
59c621c
 
 
6422215
 
59c621c
6422215
59c621c
 
 
6422215
 
59c621c
6422215
 
 
 
 
59c621c
6422215
 
59c621c
6422215
59c621c
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
47
48
import gradio as gr
from transformers import pipeline

# Load the ASR model using the Hugging Face pipeline
model_id = "riteshkr/whisper-large-v3-quantized"
pipe = pipeline("automatic-speech-recognition", model=model_id)

# Define the transcription function
def transcribe_speech(filepath):
    output = pipe(
        filepath,
        max_new_tokens=256,
        generate_kwargs={
            "task": "transcribe",
            "language": "english",
        },
        chunk_length_s=30,
        batch_size=8,
    )
    return output["text"]

# Define the Gradio interface for microphone input
mic_transcribe = gr.Interface(
    fn=transcribe_speech,
    inputs=gr.Audio(sources="microphone", type="filepath"),
    outputs=gr.Textbox(),
)

# Define the Gradio interface for file upload input
file_transcribe = gr.Interface(
    fn=transcribe_speech,
    inputs=gr.Audio(sources="upload", type="filepath"),
    outputs=gr.Textbox(),
)

# Creating the tabbed layout using Blocks
demo = gr.Blocks()

with demo:
    gr.TabbedInterface(
        [mic_transcribe, file_transcribe],
        ["Transcribe Microphone", "Transcribe Audio File"],
    )

# Launch the app with debugging enabled
if __name__ == "__main__":
    demo.launch(debug=True, share=True)