nimool commited on
Commit
0180e45
1 Parent(s): a6b64e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -15,7 +15,7 @@ def read_file_and_process(wav_file):
15
  resampler(wav_file, filename_16k)
16
  speech, _ = sf.read(filename_16k)
17
  inputs = processor(speech, sampling_rate=16_000, return_tensors="pt", padding=True)
18
-
19
  return inputs
20
 
21
 
@@ -33,18 +33,29 @@ def parse_transcription(logits):
33
  return transcription
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  def parse(wav_file):
37
  input_values = read_file_and_process(wav_file)
38
  with torch.no_grad():
39
  logits = model(**input_values).logits
40
- sentence = parse_transcription(logits)
41
- check_spell = spell_checker.check(sentence)
42
- if check_spell[0] is False:
43
- corrected = check_spell[1]
44
- else:
45
- corrected = sentence
46
- return corrected
47
-
48
 
49
  model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
50
  processor = Wav2Vec2Processor.from_pretrained(model_id)
 
15
  resampler(wav_file, filename_16k)
16
  speech, _ = sf.read(filename_16k)
17
  inputs = processor(speech, sampling_rate=16_000, return_tensors="pt", padding=True)
18
+
19
  return inputs
20
 
21
 
 
33
  return transcription
34
 
35
 
36
+ # def parse(wav_file):
37
+ # input_values = read_file_and_process(wav_file)
38
+ # with torch.no_grad():
39
+ # logits = model(**input_values).logits
40
+ # sentence = parse_transcription(logits)
41
+ # check_spell = spell_checker.check(sentence)
42
+ # if check_spell[0] is False:
43
+ # corrected = check_spell[1]
44
+ # else:
45
+ # corrected = sentence
46
+ # return corrected
47
+
48
  def parse(wav_file):
49
  input_values = read_file_and_process(wav_file)
50
  with torch.no_grad():
51
  logits = model(**input_values).logits
52
+ # sentence = parse_transcription(logits)
53
+ check_spell = spell_checker.check(parse_transcription(logits))
54
+ # if check_spell[0] is False:
55
+ # corrected = check_spell[1]
56
+ # else:
57
+ # corrected = sentence
58
+ return spell_checker.check(parse_transcription(logits))[1] if spell_checker.check(parse_transcription(logits))[0] is False else parse_transcription(logits)
 
59
 
60
  model_id = "jonatasgrosman/wav2vec2-large-xlsr-53-persian"
61
  processor = Wav2Vec2Processor.from_pretrained(model_id)