camparchimedes commited on
Commit
1376856
·
verified ·
1 Parent(s): bdf9513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -54,7 +54,7 @@ SIDEBAR_INFO = f"""
54
  <img src="{LOGO}" style="width: 100%; height: auto;"/>
55
  </div>
56
  """
57
- device = 0 if torch.cuda.is_available() else -1
58
 
59
  def convert_to_wav(filepath):
60
  _,file_ending = os.path.splitext(f'{filepath}')
@@ -62,12 +62,12 @@ def convert_to_wav(filepath):
62
  os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
63
  return audio_file
64
 
65
- pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=device)
66
 
67
- def transcribe_audio(audio_file):
68
  start_time = time.time()
69
 
70
- outputs = pipe(audio_file, return_timestamps=False, generate_kwargs={'task': 'transcribe', 'language': 'no'}) # skip_special_tokens=True
71
  text = outputs["text"]
72
 
73
  end_time = time.time()
 
54
  <img src="{LOGO}" style="width: 100%; height: auto;"/>
55
  </div>
56
  """
57
+ device = "cuda" if torch.cuda.is_available() else "cpu"
58
 
59
  def convert_to_wav(filepath):
60
  _,file_ending = os.path.splitext(f'{filepath}')
 
62
  os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
63
  return audio_file
64
 
65
+ pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, device=device)
66
 
67
+ def transcribe_audio(audio_file, batch_size=16):
68
  start_time = time.time()
69
 
70
+ outputs = pipe(audio_file, batch_size=batch_size, return_timestamps=False, generate_kwargs={'task': 'transcribe', 'language': 'no'}) # skip_special_tokens=True
71
  text = outputs["text"]
72
 
73
  end_time = time.time()