Anujgr8 commited on
Commit
c03b6e7
1 Parent(s): 89f3ad0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import soundfile as sf
2
  import torch
3
- from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor,Wav2Vec2ProcessorWithLM
4
  import gradio as gr
5
  import sox
6
  import subprocess
@@ -24,32 +24,21 @@ def resampler(input_file_path, output_file_path):
24
  )
25
  subprocess.call(command, shell=True)
26
 
27
-
28
- def parse_transcription_with_lm(logits):
29
- result = processor_with_LM.batch_decode(logits.cpu().numpy())
30
- text = result.text
31
- transcription = text[0].replace('<s>','')
32
- return transcription
33
-
34
  def parse_transcription(logits):
35
  predicted_ids = torch.argmax(logits, dim=-1)
36
  transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
37
  return transcription
38
 
39
- def parse(wav_file, applyLM):
40
  input_values = read_file_and_process(wav_file)
41
  with torch.no_grad():
42
  logits = model(**input_values).logits
43
 
44
- if applyLM:
45
- return parse_transcription_with_lm(logits)
46
- else:
47
- return parse_transcription(logits)
48
 
49
  access_token = os.getenv("ACCESS_TOKEN")
50
  model_id = "Anujgr8/wav2vec2-indic-hindi-codeswitch-anuj"
51
  processor = Wav2Vec2Processor.from_pretrained(model_id,token=access_token)
52
- processor_with_LM = Wav2Vec2ProcessorWithLM.from_pretrained(model_id,token=access_token)
53
  model = Wav2Vec2ForCTC.from_pretrained(model_id,token=access_token)
54
 
55
 
@@ -58,9 +47,8 @@ txtbox = gr.Textbox(
58
  label="Output from model will appear here:",
59
  lines=5
60
  )
61
- chkbox = gr.Checkbox(label="Apply LM", value=False)
62
 
63
 
64
- gr.Interface(parse, inputs = [input_, chkbox], outputs=txtbox,
65
  streaming=True, interactive=True,
66
  analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);
 
1
  import soundfile as sf
2
  import torch
3
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
4
  import gradio as gr
5
  import sox
6
  import subprocess
 
24
  )
25
  subprocess.call(command, shell=True)
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
+ def parse(wav_file):
33
  input_values = read_file_and_process(wav_file)
34
  with torch.no_grad():
35
  logits = model(**input_values).logits
36
 
37
+ return parse_transcription_with_lm(logits)
 
 
 
38
 
39
  access_token = os.getenv("ACCESS_TOKEN")
40
  model_id = "Anujgr8/wav2vec2-indic-hindi-codeswitch-anuj"
41
  processor = Wav2Vec2Processor.from_pretrained(model_id,token=access_token)
 
42
  model = Wav2Vec2ForCTC.from_pretrained(model_id,token=access_token)
43
 
44
 
 
47
  label="Output from model will appear here:",
48
  lines=5
49
  )
 
50
 
51
 
52
+ gr.Interface(parse, inputs = [input_], outputs=txtbox,
53
  streaming=True, interactive=True,
54
  analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);