Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,8 @@ pipe = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0
|
|
16 |
|
17 |
p1 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-odia_v1")
|
18 |
p2 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
|
|
|
|
|
19 |
os.system('git clone https://github.com/irshadbhat/indic-trans.git')
|
20 |
os.system('pip install ./indic-trans/.')
|
21 |
|
@@ -35,7 +37,16 @@ def transcribe_hindi(speech):
|
|
35 |
if text is None:
|
36 |
return "Error: ASR returned None"
|
37 |
return text
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def transcribe_odiya_eng(speech):
|
40 |
trn = Transliterator(source='ori', target='eng', build_lookup=True)
|
41 |
text = p1(speech)["text"]
|
@@ -60,6 +71,31 @@ def transcribe_hin_eng(speech):
|
|
60 |
processed_sentence = process_doubles(replaced_words)
|
61 |
return process_transcription(processed_sentence)
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def process_transcription(input_sentence):
|
64 |
word_to_code_map = {}
|
65 |
code_to_word_map = {}
|
@@ -92,6 +128,14 @@ def sel_lng(lng, mic=None, file=None):
|
|
92 |
return transcribe_hin_eng(audio)
|
93 |
elif lng == "Hindi":
|
94 |
return transcribe_hindi(audio)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Function to replace incorrectly spelled words
|
97 |
def replace_words(sentence):
|
@@ -316,7 +360,7 @@ demo=gr.Interface(
|
|
316 |
|
317 |
inputs=[
|
318 |
|
319 |
-
gr.Dropdown(["Hindi","Hindi-trans","Odiya","Odiya-trans"],value="Hindi",label="Select Language"),
|
320 |
gr.Audio(sources=["microphone","upload"], type="filepath"),
|
321 |
#gr.Audio(sources="upload", type="filepath"),
|
322 |
#"state"
|
|
|
16 |
|
17 |
p1 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-odia_v1")
|
18 |
p2 = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
|
19 |
+
p3 = pipeline(task="automatic-speech-recognition", model="cdactvm/kannada_w2v-bert_model")
|
20 |
+
p4 = pipeline(task="automatic-speech-recognition", model="cdactvm/telugu_w2v-bert_model")
|
21 |
os.system('git clone https://github.com/irshadbhat/indic-trans.git')
|
22 |
os.system('pip install ./indic-trans/.')
|
23 |
|
|
|
37 |
if text is None:
|
38 |
return "Error: ASR returned None"
|
39 |
return text
|
40 |
+
def transcribe_kannada(speech):
|
41 |
+
text = p3(speech)["text"]
|
42 |
+
if text is None:
|
43 |
+
return "Error: ASR returned None"
|
44 |
+
return text
|
45 |
+
def transcribe_telugu(speech):
|
46 |
+
text = p4(speech)["text"]
|
47 |
+
if text is None:
|
48 |
+
return "Error: ASR returned None"
|
49 |
+
return text
|
50 |
def transcribe_odiya_eng(speech):
|
51 |
trn = Transliterator(source='ori', target='eng', build_lookup=True)
|
52 |
text = p1(speech)["text"]
|
|
|
71 |
processed_sentence = process_doubles(replaced_words)
|
72 |
return process_transcription(processed_sentence)
|
73 |
|
74 |
+
def transcribe_kan_eng(speech):
|
75 |
+
trn = Transliterator(source='kan', target='eng', build_lookup=True)
|
76 |
+
text = p3(speech)["text"]
|
77 |
+
if text is None:
|
78 |
+
return "Error: ASR returned None"
|
79 |
+
sentence = trn.transform(text)
|
80 |
+
if sentence is None:
|
81 |
+
return "Error: Transliteration returned None"
|
82 |
+
replaced_words = replace_words(sentence)
|
83 |
+
processed_sentence = process_doubles(replaced_words)
|
84 |
+
return process_transcription(processed_sentence)
|
85 |
+
|
86 |
+
def transcribe_tel_eng(speech):
|
87 |
+
trn = Transliterator(source='tel', target='eng', build_lookup=True)
|
88 |
+
text = p4(speech)["text"]
|
89 |
+
if text is None:
|
90 |
+
return "Error: ASR returned None"
|
91 |
+
sentence = trn.transform(text)
|
92 |
+
if sentence is None:
|
93 |
+
return "Error: Transliteration returned None"
|
94 |
+
replaced_words = replace_words(sentence)
|
95 |
+
processed_sentence = process_doubles(replaced_words)
|
96 |
+
return process_transcription(processed_sentence)
|
97 |
+
|
98 |
+
|
99 |
def process_transcription(input_sentence):
|
100 |
word_to_code_map = {}
|
101 |
code_to_word_map = {}
|
|
|
128 |
return transcribe_hin_eng(audio)
|
129 |
elif lng == "Hindi":
|
130 |
return transcribe_hindi(audio)
|
131 |
+
elif lng == "Kannada-trans":
|
132 |
+
return transcribe_kan_eng(audio)
|
133 |
+
elif lng == "Kannada":
|
134 |
+
return transcribe_kannada(audio)
|
135 |
+
elif lng == "Telugu-trans":
|
136 |
+
return transcribe_tel_eng(audio)
|
137 |
+
elif lng == "Telugu":
|
138 |
+
return transcribe_telugu(audio)
|
139 |
|
140 |
# Function to replace incorrectly spelled words
|
141 |
def replace_words(sentence):
|
|
|
360 |
|
361 |
inputs=[
|
362 |
|
363 |
+
gr.Dropdown(["Hindi","Hindi-trans","Odiya","Odiya-trans","Kannada","Kannada-trans","Telugu","Telugu-trans"],value="Hindi",label="Select Language"),
|
364 |
gr.Audio(sources=["microphone","upload"], type="filepath"),
|
365 |
#gr.Audio(sources="upload", type="filepath"),
|
366 |
#"state"
|