litagin commited on
Commit
84dabd4
·
verified ·
1 Parent(s): 7b13fc0

Make device selection CPU-safe

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -15,9 +15,14 @@ MODEL_ID = "sbintuitions/kana-whisper"
15
 
16
  # ZeroGPU exposes CUDA at startup, so we can load straight onto the GPU. The
17
  # @spaces.GPU decorator on transcribe() is what actually reserves the slice at
18
- # call time; on non-ZeroGPU hardware the decorator is a no-op.
19
- device = "cuda"
20
- torch_dtype = torch.float16
 
 
 
 
 
21
 
22
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
23
  MODEL_ID,
 
15
 
16
  # ZeroGPU exposes CUDA at startup, so we can load straight onto the GPU. The
17
  # @spaces.GPU decorator on transcribe() is what actually reserves the slice at
18
+ # call time; on non-ZeroGPU hardware the decorator is a no-op. We detect the
19
+ # device so the Space still builds/runs on plain CPU hardware (just slower).
20
+ if torch.cuda.is_available():
21
+ device = "cuda"
22
+ torch_dtype = torch.float16
23
+ else:
24
+ device = "cpu"
25
+ torch_dtype = torch.float32
26
 
27
  model = AutoModelForSpeechSeq2Seq.from_pretrained(
28
  MODEL_ID,