clr commited on
Commit
cb91338
1 Parent(s): c6ead37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -22,8 +22,8 @@ pipe_is = pipeline(model=MODEL_IS)
22
  pipe_fo = pipeline(model=MODEL_FO)
23
 
24
 
25
- whp_is = WhisperProcessor.from_pretrained(MODEL_WHIS)
26
- whm_is = WhisperForConditionalGeneration.from_pretrained(MODEL_WHIS)
27
 
28
 
29
 
@@ -46,13 +46,12 @@ def recc(audio_file,model,processor):
46
  xcp = processor.batch_decode(pred_ids)
47
  return xcp[0]
48
 
49
- def whrecc(audio_file,wmodel,wprocessor):
50
  wav = readwav(audio_file)
51
- input_features = wprocessor(wav, sampling_rate=16000, return_tensors="pt").input_features
52
- predicted_ids = wmodel.generate(input_features)
53
- dec = wprocessor.batch_decode(predicted_ids, skip_special_tokens=True,language_id='is')
54
- xcp = dec[0]
55
- return xcp
56
 
57
 
58
  def recis(audio_file):
@@ -69,7 +68,7 @@ def recfo(audio_file):
69
 
70
 
71
  def recwhis(audio_file):
72
- wh_output = whrecc(audio_file,whm_is,whp_is)
73
  return(wh_output)
74
 
75
  def pick_asrc(au_src):
 
22
  pipe_fo = pipeline(model=MODEL_FO)
23
 
24
 
25
+ wdevice = "cuda" if torch.cuda.is_available() else "cpu"
26
+ whm_is = WhisperModel(model_size_or_path=MODEL_WHIS, device=wdevice)
27
 
28
 
29
 
 
46
  xcp = processor.batch_decode(pred_ids)
47
  return xcp[0]
48
 
49
+ def whrecc(audio_file,lang,wmodel):
50
  wav = readwav(audio_file)
51
+ xcps, info = wmodel.transcribe(audio = audio_file, language = lang, no_repeat_ngram_size = 5)
52
+ txts = [xtp.text for xcp in xcps]
53
+ txt = ' '.join(txts)
54
+ return txt
 
55
 
56
 
57
  def recis(audio_file):
 
68
 
69
 
70
  def recwhis(audio_file):
71
+ wh_output = whrecc(audio_file,"is",whm_is)
72
  return(wh_output)
73
 
74
  def pick_asrc(au_src):