patrickvonplaten commited on
Commit
89b20be
1 Parent(s): 411f418

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -10,12 +10,18 @@ feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
10
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
11
  model = SpeechEncoderDecoderModel.from_pretrained(model_name).to(device)
12
 
 
 
 
13
  def process_audio_file(file):
14
  data, sr = librosa.load(file)
15
  if sr != 16000:
16
  data = librosa.resample(data, sr, 16000)
17
  print(data.shape)
18
  input_values = feature_extractor(data, return_tensors="pt").input_values.to(device)
 
 
 
19
  return input_values
20
 
21
  def transcribe(file_mic, file_upload, target_language):
 
10
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
11
  model = SpeechEncoderDecoderModel.from_pretrained(model_name).to(device)
12
 
13
+ if torch.cuda.is_available():
14
+ model.half()
15
+
16
  def process_audio_file(file):
17
  data, sr = librosa.load(file)
18
  if sr != 16000:
19
  data = librosa.resample(data, sr, 16000)
20
  print(data.shape)
21
  input_values = feature_extractor(data, return_tensors="pt").input_values.to(device)
22
+
23
+ if torch.cuda.is_available():
24
+ input_values.to(torch.float16)
25
  return input_values
26
 
27
  def transcribe(file_mic, file_upload, target_language):