salmanmapkar commited on
Commit
61f5a06
1 Parent(s): 8520752

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -32,7 +32,7 @@ from transformers import T5ForConditionalGeneration, T5Tokenizer
32
  __FILES = set()
33
  wispher_models = list(whisper._MODELS.keys())
34
 
35
- def correct_grammar(input_text,num_return_sequences=num_return_sequences):
36
  torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
37
  tokenizer = T5Tokenizer.from_pretrained('deep-learning-analytics/GrammarCorrector')
38
  model = T5ForConditionalGeneration.from_pretrained('deep-learning-analytics/GrammarCorrector').to(torch_device)
@@ -42,7 +42,16 @@ def correct_grammar(input_text,num_return_sequences=num_return_sequences):
42
  for generated_sequence_idx, generated_sequence in enumerate(results):
43
  text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True, skip_special_tokens=True)
44
  generated_sequences.append(text)
45
- return "".join(generated_sequences)
 
 
 
 
 
 
 
 
 
46
 
47
  def CreateFile(filename):
48
  __FILES.add(filename)
@@ -223,6 +232,8 @@ def Transcribe_V2(model, num_speakers, speaker_names, audio="temp_audio.wav"):
223
  # conversation.append([GetSpeaker(segment["speaker"]), segment["text"][1:]]) # segment["speaker"] + ' ' + str(time(segment["start"])) + '\n\n'
224
  # conversation[-1][1] += segment["text"][1:]
225
  # return output
 
 
226
  return ("".join([f"[{start}] - {speaker} \n{text}\n" for start, end, speaker, text in conversation])), ({ "data": [{"start": start, "end":end, "speaker": speaker, "text": text} for start, end, speaker, text in conversation]})
227
 
228
  def get_duration(path):
 
32
  __FILES = set()
33
  wispher_models = list(whisper._MODELS.keys())
34
 
35
+ def correct_grammar(input_text,num_return_sequences="1"):
36
  torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
37
  tokenizer = T5Tokenizer.from_pretrained('deep-learning-analytics/GrammarCorrector')
38
  model = T5ForConditionalGeneration.from_pretrained('deep-learning-analytics/GrammarCorrector').to(torch_device)
 
42
  for generated_sequence_idx, generated_sequence in enumerate(results):
43
  text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True, skip_special_tokens=True)
44
  generated_sequences.append(text)
45
+ generated_text = "".join(generated_sequences)
46
+ _generated_text = ""
47
+ for idx, _sentence in enumerate(generated_text.split('.'), 0):
48
+ if not idx:
49
+ _generated_text+=_sentence+'.'
50
+ elif _sentence[:1]!=' ':
51
+ _generated_text+=' '+_sentence+'.'
52
+ else:
53
+ _generated_text+=_sentence+'.'
54
+ return _generated_text
55
 
56
  def CreateFile(filename):
57
  __FILES.add(filename)
 
232
  # conversation.append([GetSpeaker(segment["speaker"]), segment["text"][1:]]) # segment["speaker"] + ' ' + str(time(segment["start"])) + '\n\n'
233
  # conversation[-1][1] += segment["text"][1:]
234
  # return output
235
+ for idx in range(len(conversation)):
236
+ conversation[idx][3] = correct_grammar(conversation[idx][3])
237
  return ("".join([f"[{start}] - {speaker} \n{text}\n" for start, end, speaker, text in conversation])), ({ "data": [{"start": start, "end":end, "speaker": speaker, "text": text} for start, end, speaker, text in conversation]})
238
 
239
  def get_duration(path):