Spaces:
Build error
Build error
Delete model_utils.py
Browse files- model_utils.py +0 -45
model_utils.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
3 |
-
import whisper
|
4 |
-
from config import WHISPER_MODEL_SIZE
|
5 |
-
import spaces
|
6 |
-
|
7 |
-
# Global variables to store models
|
8 |
-
whisper_processor = None
|
9 |
-
whisper_model = None
|
10 |
-
whisper_model_small = None
|
11 |
-
|
12 |
-
@spaces.GPU
|
13 |
-
def load_models():
|
14 |
-
global whisper_processor, whisper_model, whisper_model_small
|
15 |
-
if whisper_processor is None:
|
16 |
-
whisper_processor = WhisperProcessor.from_pretrained(f"openai/whisper-{WHISPER_MODEL_SIZE}")
|
17 |
-
if whisper_model is None:
|
18 |
-
whisper_model = WhisperForConditionalGeneration.from_pretrained(f"openai/whisper-{WHISPER_MODEL_SIZE}")
|
19 |
-
if whisper_model_small is None:
|
20 |
-
whisper_model_small = whisper.load_model(WHISPER_MODEL_SIZE)
|
21 |
-
|
22 |
-
@spaces.GPU
|
23 |
-
def get_device():
|
24 |
-
return "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
-
|
26 |
-
@spaces.GPU
|
27 |
-
def get_processor():
|
28 |
-
global whisper_processor
|
29 |
-
if whisper_processor is None:
|
30 |
-
load_models()
|
31 |
-
return whisper_processor
|
32 |
-
|
33 |
-
@spaces.GPU
|
34 |
-
def get_model():
|
35 |
-
global whisper_model
|
36 |
-
if whisper_model is None:
|
37 |
-
load_models()
|
38 |
-
return whisper_model.to(get_device())
|
39 |
-
|
40 |
-
@spaces.GPU
|
41 |
-
def get_whisper_model_small():
|
42 |
-
global whisper_model_small
|
43 |
-
if whisper_model_small is None:
|
44 |
-
load_models()
|
45 |
-
return whisper_model_small
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|