Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
import torchaudio
|
4 |
+
import gradio as gr
|
5 |
+
import nemo.collections.asr as nemo_asr
|
6 |
+
|
7 |
+
# Select device
|
8 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
9 |
+
|
10 |
+
# Load CTC and RNNT models from AI4Bharat
|
11 |
+
asr_ctc = nemo_asr.models.EncDecCTCModelBPE.from_pretrained("ai4bharat/indicwhisper-ctc-indic").to(device)
|
12 |
+
asr_rnnt = nemo_asr.models.EncDecRNNTBPEModel.from_pretrained("ai4bharat/indicwhisper-rnnt-indic").to(device)
|
13 |
+
|
14 |
+
# All 22 scheduled Indian languages
|
15 |
+
language_options = [
|
16 |
+
"Assamese", "Bengali", "Bodo", "Dogri", "Gujarati", "Hindi",
|
17 |
+
"Kannada", "Kashmiri", "Konkani", "Maithili", "Malayalam",
|
18 |
+
"Manipuri", "Marathi", "Nepali", "Odia", "Punjabi", "Sanskrit",
|
19 |
+
"Santali", "Sindhi", "Tamil", "Telugu", "Urdu"
|
20 |
+
]
|
21 |
+
|
22 |
+
# CTC ASR function
|
23 |
+
def run_asr_ctc(audio_path, source_lang):
|
24 |
+
asr_ctc.change_vocabulary(language=source_lang)
|
25 |
+
return asr_ctc.transcribe(paths2audio_files=[audio_path])[0]
|
26 |
+
|
27 |
+
# RNNT ASR function
|
28 |
+
def run_asr_rnnt(audio_path, source_lang):
|
29 |
+
asr_rnnt.change_vocabulary(language=source_lang)
|
30 |
+
return asr_rnnt.transcribe(paths2audio_files=[audio_path])[0]
|
31 |
+
|
32 |
+
# Gradio UI
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("## AI4Bharat Indic ASR (CTC & RNNT)")
|
35 |
+
|
36 |
+
with gr.Tab("CTC Transcription"):
|
37 |
+
with gr.Row():
|
38 |
+
input_audio = gr.Audio(type="filepath", label="Upload Audio")
|
39 |
+
source_lang = gr.Dropdown(choices=language_options, label="Language", value="Hindi")
|
40 |
+
output_text_ctc = gr.Textbox(label="CTC Transcription Output")
|
41 |
+
ctc_button = gr.Button("Transcribe (CTC)")
|
42 |
+
ctc_button.click(run_asr_ctc, inputs=[input_audio, source_lang], outputs=output_text_ctc)
|
43 |
+
|
44 |
+
with gr.Tab("RNNT Transcription"):
|
45 |
+
with gr.Row():
|
46 |
+
input_audio_rnnt = gr.Audio(type="filepath", label="Upload Audio")
|
47 |
+
source_lang_rnnt = gr.Dropdown(choices=language_options, label="Language", value="Hindi")
|
48 |
+
output_text_rnnt = gr.Textbox(label="RNNT Transcription Output")
|
49 |
+
rnnt_button = gr.Button("Transcribe (RNNT)")
|
50 |
+
rnnt_button.click(run_asr_rnnt, inputs=[input_audio_rnnt, source_lang_rnnt], outputs=output_text_rnnt)
|
51 |
+
|
52 |
+
demo.launch()
|