mahimairaja commited on
Commit
7976fae
1 Parent(s): db2137b

Initial Commit

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from transformers import pipeline
4
+ import torch
5
+
6
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
+
8
+ transcriber = pipeline("automatic-speech-recognition", model="mahimairaja/whisper-base-tamil", \
9
+ chunk_length_s=15, device=device)
10
+ transcriber.model.config.forced_decoder_ids = transcriber.tokenizer.get_decoder_prompt_ids(language="ta", task="transcribe")
11
+
12
+ def transcribe(audio):
13
+ return transcriber(audio)["text"]
14
+
15
+ TITLE = "ASR for ALL - Democratizing Tamil"
16
+
17
+ demo = gr.Blocks()
18
+
19
+ mic_transcribe = gr.Interface(
20
+ fn=transcribe,
21
+ inputs=gr.Audio(source="microphone", type="filepath"),
22
+ outputs="text",
23
+ title=TITLE,
24
+ )
25
+
26
+ file_transcribe = gr.Interface(
27
+ fn=transcribe,
28
+ inputs=gr.Audio(source="upload", type="filepath"),
29
+ outputs="text",
30
+ examples=[
31
+ "assets/tamil-audio-01.mp3",
32
+ "assets/tamil-audio-02.mp3",
33
+ "assets/tamil-audio-03.mp3",
34
+ "assets/tamil-audio-04.mp3",
35
+ ],
36
+ title=TITLE,
37
+ )
38
+
39
+
40
+ with demo:
41
+ gr.TabbedInterface(
42
+ [mic_transcribe, file_transcribe],
43
+ ["Real Time Transcription", "Audio File", ]
44
+ )
45
+
46
+ demo.launch(share=True)