Simonlob commited on
Commit
e864ca3
1 Parent(s): 6660ce2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -6,16 +6,17 @@ import librosa
6
  import numpy as np
7
  import re
8
 
 
9
  processor = Wav2Vec2Processor.from_pretrained("the-cramer-project/Wav2vec-Kyrgyz")
10
  model = Wav2Vec2ForCTC.from_pretrained("the-cramer-project/Wav2vec-Kyrgyz")
11
- model.to("cuda")
12
 
13
  def transcribe(file_):
14
  arr_audio, _ = librosa.load(file_, sr=16000)
15
  inputs = processor(arr_audio, sampling_rate=16_000, return_tensors="pt", padding=True)
16
 
17
  with torch.no_grad():
18
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
19
 
20
  pred_ids = torch.argmax(logits, dim=-1)
21
  text = processor.batch_decode(pred_ids)[0]
 
6
  import numpy as np
7
  import re
8
 
9
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
  processor = Wav2Vec2Processor.from_pretrained("the-cramer-project/Wav2vec-Kyrgyz")
11
  model = Wav2Vec2ForCTC.from_pretrained("the-cramer-project/Wav2vec-Kyrgyz")
12
+ model.to(device = device)
13
 
14
  def transcribe(file_):
15
  arr_audio, _ = librosa.load(file_, sr=16000)
16
  inputs = processor(arr_audio, sampling_rate=16_000, return_tensors="pt", padding=True)
17
 
18
  with torch.no_grad():
19
+ logits = model(inputs.input_values.to(device = device), attention_mask=inputs.attention_mask.to(device = device)).logits
20
 
21
  pred_ids = torch.argmax(logits, dim=-1)
22
  text = processor.batch_decode(pred_ids)[0]