rashid101b commited on
Commit
154da93
1 Parent(s): 8b3ca86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -5,12 +5,12 @@ import torch
5
  import gradio as gr
6
  from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC
7
  nltk.download("punkt")
 
8
  #Loading the pre-trained model and the tokenizer
9
  model_name = "facebook/wav2vec2-base-960h"
10
  tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
11
  model = Wav2Vec2ForCTC.from_pretrained(model_name)
12
  def load_data(input_file):
13
-
14
  #reading the file
15
  speech, sample_rate = librosa.load(input_file)
16
  #make it 1-D
@@ -23,7 +23,8 @@ def load_data(input_file):
23
  def correct_casing(input_sentence):
24
  sentences = nltk.sent_tokenize(input_sentence)
25
  return (' '.join([s.replace(s[0],s[0].capitalize(),1) for s in sentences]))
26
- def asr_transcript(input_file):
 
27
  speech = load_data(input_file)
28
  #Tokenize
29
  input_values = tokenizer(speech, return_tensors="pt").input_values
@@ -37,9 +38,9 @@ def load_data(input_file):
37
  transcription = correct_casing(transcription.lower())
38
  return transcription
39
 
40
- gr.Interface(asr_transcript,
41
- inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Speaker"),
42
- outputs = gr.outputs.Textbox(label="Output Text"),
43
- title="ASR using Wav2Vec 2.0",
44
- description = "This application displays transcribed text for given audio input",
45
- examples = [["Test_File1.wav"], ["Test_File2.wav"], ["Test_File3.wav"]], theme="grass").launch()
 
5
  import gradio as gr
6
  from transformers import Wav2Vec2Tokenizer, Wav2Vec2ForCTC
7
  nltk.download("punkt")
8
+
9
  #Loading the pre-trained model and the tokenizer
10
  model_name = "facebook/wav2vec2-base-960h"
11
  tokenizer = Wav2Vec2Tokenizer.from_pretrained(model_name)
12
  model = Wav2Vec2ForCTC.from_pretrained(model_name)
13
  def load_data(input_file):
 
14
  #reading the file
15
  speech, sample_rate = librosa.load(input_file)
16
  #make it 1-D
 
23
  def correct_casing(input_sentence):
24
  sentences = nltk.sent_tokenize(input_sentence)
25
  return (' '.join([s.replace(s[0],s[0].capitalize(),1) for s in sentences]))
26
+
27
+ def asr_transcript(input_file):
28
  speech = load_data(input_file)
29
  #Tokenize
30
  input_values = tokenizer(speech, return_tensors="pt").input_values
 
38
  transcription = correct_casing(transcription.lower())
39
  return transcription
40
 
41
+ gr.Interface(asr_transcript,
42
+ inputs = gr.inputs.Audio(source="microphone", type="filepath", optional=True, label="Speaker"),
43
+ outputs = gr.outputs.Textbox(label="Output Text"),
44
+ title="ASR using Wav2Vec 2.0",
45
+ description = "This application displays transcribed text for given audio input",
46
+ examples = [["Test_File1.wav"], ["Test_File2.wav"], ["Test_File3.wav"]], theme="grass").launch()