Bishan commited on
Commit
0c5f390
·
1 Parent(s): 4ba2ace

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -64
app.py CHANGED
@@ -24,37 +24,18 @@ def resampler(input_file_path, output_file_path):
24
  subprocess.call(command, shell=True)
25
 
26
 
27
- # def parse_transcription_with_lm(logits):
28
- # result = processor_with_LM.batch_decode(logits.cpu().numpy())
29
- # text = result.text
30
- # transcription = text[0].replace('<s>','')
31
- # return transcription
32
-
33
  def parse_transcription(logits):
34
  predicted_ids = torch.argmax(logits, dim=-1)
35
  transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
36
  return transcription
37
 
38
- # def parse(wav_file, applyLM):
39
- # input_values = read_file_and_process(wav_file)
40
- # with torch.no_grad():
41
- # logits = model(**input_values).logits
42
-
43
- # if applyLM:
44
- # # return parse_transcription_with_lm(logits)
45
- # return "done"
46
- # else:
47
- # return parse_transcription(logits)
48
-
49
- def parse(wav_file, applyLM):
50
  input_values = read_file_and_process(wav_file)
51
  with torch.no_grad():
52
  logits = model(**input_values).logits
53
 
54
- if applyLM:
55
- # return parse_transcription_with_lm(logits)
56
- return "done"
57
- else:
58
  return parse_transcription(logits)
59
 
60
 
@@ -76,57 +57,19 @@ def parse(wav_file, applyLM):
76
  # This is hindi
77
  model_id = "Harveenchadha/vakyansh-wav2vec2-hindi-him-4200"
78
 
79
-
80
-
81
- # processor = Wav2Vec2Processor.from_pretrained(model_id)
82
- # # processor_with_LM = Wav2Vec2ProcessorWithLM.from_pretrained(model_id)
83
- # model = Wav2Vec2ForCTC.from_pretrained(model_id)
84
-
85
-
86
- # input_ = gr.Audio(source="microphone", type="filepath")
87
- # txtbox = gr.Textbox(
88
- # label="Output from model will appear here:",
89
- # lines=5
90
- # )
91
- # chkbox = gr.Checkbox(label="Apply LM", value=False)
92
-
93
-
94
- # gr.Interface(parse, inputs = [input_, chkbox], outputs=txtbox,
95
- # streaming=True, interactive=True,
96
- # analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);
97
-
98
-
99
-
100
-
101
-
102
  processor = Wav2Vec2Processor.from_pretrained(model_id)
103
  model = Wav2Vec2ForCTC.from_pretrained(model_id)
104
 
 
105
  # input_ = gr.inputs.File(source="upload", type="filepath") # Change input source to "upload" and type to "audio"
106
  input_ = gr.Audio(source="upload", type="filepath")
107
  txtbox = gr.Textbox(
108
  label="Output from the model will appear here:",
109
  lines=5
110
  )
111
- chkbox = gr.Checkbox(label="Apply LM", value=False)
112
 
113
- gr.Interface(parse, inputs=[input_, chkbox], outputs=txtbox,
 
114
  streaming=True, interactive=True,
115
  analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
 
24
  subprocess.call(command, shell=True)
25
 
26
 
 
 
 
 
 
 
27
  def parse_transcription(logits):
28
  predicted_ids = torch.argmax(logits, dim=-1)
29
  transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
30
  return transcription
31
 
32
+
33
+ def parse(wav_file):
 
 
 
 
 
 
 
 
 
 
34
  input_values = read_file_and_process(wav_file)
35
  with torch.no_grad():
36
  logits = model(**input_values).logits
37
 
38
+ if wav_file:
 
 
 
39
  return parse_transcription(logits)
40
 
41
 
 
57
  # This is hindi
58
  model_id = "Harveenchadha/vakyansh-wav2vec2-hindi-him-4200"
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  processor = Wav2Vec2Processor.from_pretrained(model_id)
61
  model = Wav2Vec2ForCTC.from_pretrained(model_id)
62
 
63
+ # input_ = gr.Audio(source="microphone", type="filepath")
64
  # input_ = gr.inputs.File(source="upload", type="filepath") # Change input source to "upload" and type to "audio"
65
  input_ = gr.Audio(source="upload", type="filepath")
66
  txtbox = gr.Textbox(
67
  label="Output from the model will appear here:",
68
  lines=5
69
  )
70
+ # chkbox = gr.Checkbox(label="Apply LM", value=False)
71
 
72
+ # gr.Interface(parse, inputs=[input_, chkbox], outputs=txtbox,
73
+ gr.Interface(parse, inputs=[input_], outputs=txtbox,
74
  streaming=True, interactive=True,
75
  analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);