cdactvm commited on
Commit
6899aff
1 Parent(s): 8e28212

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -15,21 +15,59 @@ from isNumber import is_number
15
  from processDoubles import process_doubles
16
  from replaceWords import replace_words
17
 
18
- transcriber = pipeline(task="automatic-speech-recognition", model="cdactvm/w2v-bert-2.0-hindi_v1")
 
19
 
20
 
21
- def transcribe(audio):
22
  # # Process the audio file
23
- transcript = transcriber(audio)
24
  text_value = transcript['text']
25
  processd_doubles=process_doubles(text_value)
26
  replaced_words = replace_words(processd_doubles)
27
  converted_text=text_to_int(replaced_words)
28
  return converted_text
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  demo=gr.Interface(
31
- transcribe,
 
32
  inputs=[
 
 
33
  gr.Audio(sources=["microphone","upload"], type="filepath"),
34
  ],
35
  outputs=[
@@ -38,3 +76,4 @@ demo=gr.Interface(
38
  title="Automatic Speech Recognition",
39
  description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
40
  ).launch()
 
 
15
  from processDoubles import process_doubles
16
  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):
23
  # # Process the audio file
24
+ transcript = transcriber_hindi_new(audio)
25
  text_value = transcript['text']
26
  processd_doubles=process_doubles(text_value)
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
33
+ transcript = transcriber_hindi_old(audio)
34
+ text_value = transcript['text']
35
+ processd_doubles=process_doubles(text_value)
36
+ replaced_words = replace_words(processd_doubles)
37
+ converted_text=text_to_int(replaced_words)
38
+ return converted_text
39
+
40
+ def sel_lng(lng, mic=None, file=None):
41
+ if mic is not None:
42
+ audio = mic
43
+ elif file is not None:
44
+ audio = file
45
+ else:
46
+ return "You must either provide a mic recording or a file"
47
+
48
+ if lng == "hindi_old":
49
+ return transcribe_hindi_old(audio)
50
+ elif lng == "hindi_new":
51
+ return transcribe_hindi_new(audio)
52
+
53
+ # demo=gr.Interface(
54
+ # transcribe,
55
+ # inputs=[
56
+ # gr.Audio(sources=["microphone","upload"], type="filepath"),
57
+ # ],
58
+ # outputs=[
59
+ # "textbox"
60
+ # ],
61
+ # title="Automatic Speech Recognition",
62
+ # description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
63
+ # ).launch()
64
+
65
  demo=gr.Interface(
66
+ fn=sel_lng,
67
+
68
  inputs=[
69
+ gr.Dropdown([
70
+ "hindi_new","hindi_old"],label="Select Language"),
71
  gr.Audio(sources=["microphone","upload"], type="filepath"),
72
  ],
73
  outputs=[
 
76
  title="Automatic Speech Recognition",
77
  description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
78
  ).launch()
79
+