Spaces:
Sleeping
Sleeping
File size: 2,427 Bytes
e48211d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
from argparse import Namespace
import os
from modules.whisper.faster_whisper_inference import FasterWhisperInference
from modules.whisper.whisper_Inference import WhisperInference
from modules.whisper.insanely_fast_whisper_inference import InsanelyFastWhisperInference
from modules.whisper.whisper_base import WhisperBase
class WhisperFactory:
@staticmethod
def create_whisper_inference(
whisper_type: str,
model_dir: str,
output_dir: str,
args: Namespace
) -> "WhisperBase":
"""
Create a whisper inference class based on the provided whisper_type.
Parameters
----------
whisper_type: str
The repository name of whisper inference to use. Supported values are:
- "faster-whisper" from
- "whisper"
- insanely-fast-whisper", "insanely_fast_whisper", "insanelyfastwhisper",
"insanely-faster-whisper", "insanely_faster_whisper", "insanelyfasterwhisper"
model_dir: str
The directory path where the whisper model is located.
output_dir: str
The directory path where the output files will be saved.
args: Any
Additional arguments to be passed to the whisper inference object.
Returns
-------
WhisperBase
An instance of the appropriate whisper inference class based on the whisper_type.
"""
# Temporal fix of the bug : https://github.com/jhj0517/Whisper-WebUI/issues/144
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
whisper_type = whisper_type.lower().strip()
faster_whisper_typos = ["faster_whisper", "faster-whisper", "fasterwhisper"]
whisper_typos = ["whisper"]
insanely_fast_whisper_typos = [
"insanely_fast_whisper", "insanely-fast-whisper", "insanelyfastwhisper",
"insanely_faster_whisper", "insanely-faster-whisper", "insanelyfasterwhisper"
]
if whisper_type in faster_whisper_typos:
return FasterWhisperInference(model_dir, output_dir, args)
elif whisper_type in whisper_typos:
return WhisperInference(model_dir, output_dir, args)
elif whisper_type in insanely_fast_whisper_typos:
return InsanelyFastWhisperInference(model_dir, output_dir, args)
else:
return FasterWhisperInference(model_dir, output_dir, args)
|