2023-05-02 14:57:12 +03:00
|
|
|
from torch import device
|
|
|
|
|
|
|
|
from const import EnumInferenceTypes
|
|
|
|
from voice_changer.RVC.inferencer.Inferencer import Inferencer
|
2023-05-03 07:14:00 +03:00
|
|
|
from voice_changer.RVC.inferencer.OnnxRVCInferencer import OnnxRVCInferencer
|
|
|
|
from voice_changer.RVC.inferencer.OnnxRVCInferencerNono import OnnxRVCInferencerNono
|
2023-05-02 14:57:12 +03:00
|
|
|
from voice_changer.RVC.inferencer.RVCInferencer import RVCInferencer
|
|
|
|
from voice_changer.RVC.inferencer.RVCInferencerNono import RVCInferencerNono
|
|
|
|
from voice_changer.RVC.inferencer.WebUIInferencer import WebUIInferencer
|
|
|
|
from voice_changer.RVC.inferencer.WebUIInferencerNono import WebUIInferencerNono
|
|
|
|
|
|
|
|
|
|
|
|
class InferencerManager:
|
|
|
|
currentInferencer: Inferencer | None = None
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getInferencer(
|
|
|
|
cls, inferencerType: EnumInferenceTypes, file: str, isHalf: bool, dev: device
|
|
|
|
) -> Inferencer:
|
|
|
|
cls.currentInferencer = cls.loadInferencer(inferencerType, file, isHalf, dev)
|
|
|
|
return cls.currentInferencer
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def loadInferencer(
|
|
|
|
cls, inferencerType: EnumInferenceTypes, file: str, isHalf: bool, dev: device
|
2023-05-02 16:29:28 +03:00
|
|
|
) -> Inferencer:
|
|
|
|
if (
|
|
|
|
inferencerType == EnumInferenceTypes.pyTorchRVC
|
|
|
|
or inferencerType == EnumInferenceTypes.pyTorchRVC.value
|
|
|
|
):
|
2023-05-02 14:57:12 +03:00
|
|
|
return RVCInferencer().loadModel(file, dev, isHalf)
|
2023-05-02 16:29:28 +03:00
|
|
|
elif (
|
|
|
|
inferencerType == EnumInferenceTypes.pyTorchRVCNono
|
|
|
|
or inferencerType == EnumInferenceTypes.pyTorchRVCNono.value
|
|
|
|
):
|
2023-05-02 14:57:12 +03:00
|
|
|
return RVCInferencerNono().loadModel(file, dev, isHalf)
|
2023-05-02 16:29:28 +03:00
|
|
|
elif (
|
|
|
|
inferencerType == EnumInferenceTypes.pyTorchWebUI
|
|
|
|
or inferencerType == EnumInferenceTypes.pyTorchWebUI.value
|
|
|
|
):
|
2023-05-02 14:57:12 +03:00
|
|
|
return WebUIInferencer().loadModel(file, dev, isHalf)
|
2023-05-02 16:29:28 +03:00
|
|
|
elif (
|
|
|
|
inferencerType == EnumInferenceTypes.pyTorchWebUINono
|
|
|
|
or inferencerType == EnumInferenceTypes.pyTorchWebUINono.value
|
|
|
|
):
|
2023-05-02 14:57:12 +03:00
|
|
|
return WebUIInferencerNono().loadModel(file, dev, isHalf)
|
2023-05-02 16:29:28 +03:00
|
|
|
elif (
|
|
|
|
inferencerType == EnumInferenceTypes.onnxRVC
|
|
|
|
or inferencerType == EnumInferenceTypes.onnxRVC.value
|
|
|
|
):
|
2023-05-03 07:14:00 +03:00
|
|
|
return OnnxRVCInferencer().loadModel(file, dev, isHalf)
|
2023-05-02 16:29:28 +03:00
|
|
|
elif (
|
|
|
|
inferencerType == EnumInferenceTypes.onnxRVCNono
|
|
|
|
or inferencerType == EnumInferenceTypes.onnxRVCNono.value
|
|
|
|
):
|
2023-05-03 07:14:00 +03:00
|
|
|
return OnnxRVCInferencerNono().loadModel(file, dev, isHalf)
|
2023-05-02 14:57:12 +03:00
|
|
|
else:
|
|
|
|
raise RuntimeError("[Voice Changer] Inferencer not found", inferencerType)
|