camparchimedes commited on
Commit
9769005
·
verified ·
1 Parent(s): 01ca89f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -24,26 +24,33 @@ import torch
24
  from transformers import pipeline, AutoProcessor # AutoModelForSpeechSeq2Seq
25
 
26
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
27
 
28
- pipe = pipeline("automatic-speech-recognition", model="NbAiLabBeta/nb-whisper-large", device=device, torch_dtype=torch.float32)
29
 
30
  # @spaces.GPU(queue=True)
31
 
32
- # Initialize processor before using it in the function
33
  processor = AutoProcessor.from_pretrained("NbAiLabBeta/nb-whisper-large")
 
 
34
 
35
  language = "no"
36
  task = "transcribe"
37
 
38
- def transcribe_audio(audio_file, forced_decoder_ids):
39
  if audio_file.endswith(".m4a"):
40
  audio_file = convert_to_wav(audio_file)
41
 
42
  start_time = time.time()
43
- forced_decoder_ids = processor.get_decoder_prompt_ids(language="no", task="transcribe")
 
 
44
 
45
  with torch.no_grad():
46
- output = pipe(audio_file, chunk_length_s=30, generate_kwargs={"forced_decoder_ids": forced_decoder_ids})
 
 
47
 
48
  text = output["text"]
49
  end_time = time.time()
@@ -204,7 +211,7 @@ def save_to_pdf(text, summary):
204
 
205
  banner_html = """
206
  <div style="text-align: center;">
207
- <img src="https://huggingface.co/spaces/camparchimedes/transcription_app/blob/main/Olas%20AudioSwitch%20Shop.png" alt="Banner" width="100%" height="auto">
208
  </div>
209
  """
210
 
 
24
  from transformers import pipeline, AutoProcessor # AutoModelForSpeechSeq2Seq
25
 
26
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
27
+ torch_dtype = torch.float32
28
 
29
+ pipe = pipeline("automatic-speech-recognition", model="NbAiLabBeta/nb-whisper-large", device=device, torch_dtype=torch_dtype)
30
 
31
  # @spaces.GPU(queue=True)
32
 
33
+ # Initialize processor and pipeline
34
  processor = AutoProcessor.from_pretrained("NbAiLabBeta/nb-whisper-large")
35
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
36
+ torch_dtype = torch.float32
37
 
38
  language = "no"
39
  task = "transcribe"
40
 
41
+ def transcribe_audio(audio_file):
42
  if audio_file.endswith(".m4a"):
43
  audio_file = convert_to_wav(audio_file)
44
 
45
  start_time = time.time()
46
+
47
+ # forced_decoder_ids@the correct context
48
+ forced_decoder_ids = processor.get_decoder_prompt_ids(language=language, task=task)
49
 
50
  with torch.no_grad():
51
+ # CUDA@function -->
52
+ with torch.cuda.device(device) if torch.cuda.is_available() else contextlib.nullcontext():
53
+ output = pipe(audio_file, chunk_length_s=30, generate_kwargs={"forced_decoder_ids": forced_decoder_ids})
54
 
55
  text = output["text"]
56
  end_time = time.time()
 
211
 
212
  banner_html = """
213
  <div style="text-align: center;">
214
+ <img src="https://huggingface.co/spaces/camparchimedes/transcription_app/blob/main/Olas%20AudioSwitch%20Shop.png" width="100%" height="auto">
215
  </div>
216
  """
217