Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import nbimporter
|
|
9 |
from transformers import pipeline
|
10 |
from transformers import AutoProcessor
|
11 |
from pyctcdecode import build_ctcdecoder
|
12 |
-
|
13 |
from text2int import text_to_int
|
14 |
from isNumber import is_number
|
15 |
from processDoubles import process_doubles
|
@@ -17,6 +17,20 @@ from replaceWords import replace_words
|
|
17 |
|
18 |
transcriber_hindi_new = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
|
19 |
transcriber_hindi_old = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_old")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
def transcribe_hindi_new(audio):
|
@@ -27,6 +41,15 @@ def transcribe_hindi_new(audio):
|
|
27 |
replaced_words = replace_words(processd_doubles)
|
28 |
converted_text=text_to_int(replaced_words)
|
29 |
return converted_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def transcribe_hindi_old(audio):
|
32 |
# # Process the audio file
|
@@ -50,6 +73,8 @@ def sel_lng(lng, mic=None, file=None):
|
|
50 |
return transcribe_hindi_old(audio)
|
51 |
elif lng == "model_2":
|
52 |
return transcribe_hindi_new(audio)
|
|
|
|
|
53 |
|
54 |
# demo=gr.Interface(
|
55 |
# transcribe,
|
@@ -68,7 +93,7 @@ demo=gr.Interface(
|
|
68 |
|
69 |
inputs=[
|
70 |
gr.Dropdown([
|
71 |
-
"model_1","model_2"],label="Select
|
72 |
gr.Audio(sources=["microphone","upload"], type="filepath"),
|
73 |
],
|
74 |
outputs=[
|
|
|
9 |
from transformers import pipeline
|
10 |
from transformers import AutoProcessor
|
11 |
from pyctcdecode import build_ctcdecoder
|
12 |
+
from transformers import Wav2Vec2ProcessorWithLM
|
13 |
from text2int import text_to_int
|
14 |
from isNumber import is_number
|
15 |
from processDoubles import process_doubles
|
|
|
17 |
|
18 |
transcriber_hindi_new = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
|
19 |
transcriber_hindi_old = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_old")
|
20 |
+
processor = AutoProcessor.from_pretrained("cdactvm/w2v-bert-2.0-hindi_v1")
|
21 |
+
vocab_dict = processor.tokenizer.get_vocab()
|
22 |
+
sorted_vocab_dict = {k.lower(): v for k, v in sorted(vocab_dict.items(), key=lambda item: item[1])}
|
23 |
+
decoder = build_ctcdecoder(
|
24 |
+
labels=list(sorted_vocab_dict.keys()),
|
25 |
+
kenlm_model_path="lm.binary",
|
26 |
+
)
|
27 |
+
processor_with_lm = Wav2Vec2ProcessorWithLM(
|
28 |
+
feature_extractor=processor.feature_extractor,
|
29 |
+
tokenizer=processor.tokenizer,
|
30 |
+
decoder=decoder
|
31 |
+
)
|
32 |
+
processor.feature_extractor._processor_class = "Wav2Vec2ProcessorWithLM"
|
33 |
+
transcriber_hindi_lm = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1", tokenizer=processor_with_lm, feature_extractor=processor_with_lm.feature_extractor, decoder=processor_with_lm.decoder)
|
34 |
|
35 |
|
36 |
def transcribe_hindi_new(audio):
|
|
|
41 |
replaced_words = replace_words(processd_doubles)
|
42 |
converted_text=text_to_int(replaced_words)
|
43 |
return converted_text
|
44 |
+
|
45 |
+
def transcribe_hindi_lm(audio):
|
46 |
+
# # Process the audio file
|
47 |
+
transcript = transcriber_hindi_lm(audio)
|
48 |
+
text_value = transcript['text']
|
49 |
+
processd_doubles=process_doubles(text_value)
|
50 |
+
replaced_words = replace_words(processd_doubles)
|
51 |
+
converted_text=text_to_int(replaced_words)
|
52 |
+
return converted_text
|
53 |
|
54 |
def transcribe_hindi_old(audio):
|
55 |
# # Process the audio file
|
|
|
73 |
return transcribe_hindi_old(audio)
|
74 |
elif lng == "model_2":
|
75 |
return transcribe_hindi_new(audio)
|
76 |
+
elif lng== "model_3":
|
77 |
+
return transcribe_hindi_lm(audio)
|
78 |
|
79 |
# demo=gr.Interface(
|
80 |
# transcribe,
|
|
|
93 |
|
94 |
inputs=[
|
95 |
gr.Dropdown([
|
96 |
+
"model_1","model_2","model_3"],label="Select Model"),
|
97 |
gr.Audio(sources=["microphone","upload"], type="filepath"),
|
98 |
],
|
99 |
outputs=[
|