bugfix: same slot select

This commit is contained in:
wataru 2023-04-25 15:01:19 +09:00
parent ca5eff8b35
commit 87e4ab0cb7
3 changed files with 16 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@ -12,11 +12,13 @@ export const ModelSwitchRow = (_props: ModelSwitchRowProps) => {
const modelSwitchRow = useMemo(() => { const modelSwitchRow = useMemo(() => {
const slot = appState.serverSetting.serverSetting.modelSlotIndex const slot = appState.serverSetting.serverSetting.modelSlotIndex
const onSwitchModelClicked = (index: number, filename: string) => { const onSwitchModelClicked = async (index: number, filename: string) => {
const framework: Framework = filename.endsWith(".onnx") ? "ONNX" : "PyTorch" const framework: Framework = filename.endsWith(".onnx") ? "ONNX" : "PyTorch"
console.log("Framework:::", filename, framework) console.log("Framework:::", filename, framework)
appState.serverSetting.updateServerSettings({ ...appState.serverSetting.serverSetting, modelSlotIndex: index, framework: framework }) // Quick hack for same slot is selected. 下桁が実際のSlotID
const dummyModelSlotIndex = (Math.floor(Date.now() / 1000)) * 1000 + index
await appState.serverSetting.updateServerSettings({ ...appState.serverSetting.serverSetting, modelSlotIndex: dummyModelSlotIndex, framework: framework })
} }
const modelOptions = appState.serverSetting.serverSetting.modelSlots.map((x, index) => { const modelOptions = appState.serverSetting.serverSetting.modelSlots.map((x, index) => {
const className = index == slot ? "body-button-active left-margin-1" : "body-button left-margin-1" const className = index == slot ? "body-button-active left-margin-1" : "body-button left-margin-1"

View File

@ -114,19 +114,11 @@ class RVC:
def loadModel(self, props): def loadModel(self, props):
self.is_half = props["isHalf"] self.is_half = props["isHalf"]
self.tmp_slot = props["slot"] tmp_slot = props["slot"]
params_str = props["params"] params_str = props["params"]
params = json.loads(params_str) params = json.loads(params_str)
# self.settings.modelSlots[self.tmp_slot] = ModelSlot( newSlot = asdict(self.settings.modelSlots[tmp_slot])
# pyTorchModelFile=props["files"]["pyTorchModelFilename"],
# onnxModelFile=props["files"]["onnxModelFilename"],
# featureFile=props["files"]["featureFilename"],
# indexFile=props["files"]["indexFilename"],
# defaultTrans=params["trans"]
# )
newSlot = asdict(self.settings.modelSlots[self.tmp_slot])
newSlot.update({ newSlot.update({
"pyTorchModelFile": props["files"]["pyTorchModelFilename"], "pyTorchModelFile": props["files"]["pyTorchModelFilename"],
"onnxModelFile": props["files"]["onnxModelFilename"], "onnxModelFile": props["files"]["onnxModelFilename"],
@ -134,16 +126,9 @@ class RVC:
"indexFile": props["files"]["indexFilename"], "indexFile": props["files"]["indexFilename"],
"defaultTrans": params["trans"] "defaultTrans": params["trans"]
}) })
# .update({ self.settings.modelSlots[tmp_slot] = ModelSlot(**newSlot)
# pyTorchModelFile: props["files"]["pyTorchModelFilename"],
# onnxModelFile: props["files"]["onnxModelFilename"],
# featureFile: props["files"]["featureFilename"],
# indexFile: props["files"]["indexFilename"],
# defaultTrans: params["trans"]
# })
self.settings.modelSlots[self.tmp_slot] = ModelSlot(**newSlot)
print("[Voice Changer] RVC loading... slot:", self.tmp_slot) print("[Voice Changer] RVC loading... slot:", tmp_slot)
try: try:
hubert_path = self.params["hubert_base"] hubert_path = self.params["hubert_base"]
@ -158,8 +143,8 @@ class RVC:
print("EXCEPTION during loading hubert/contentvec model", e) print("EXCEPTION during loading hubert/contentvec model", e)
if self.initialLoad: if self.initialLoad:
self.prepareModel(self.tmp_slot) self.prepareModel(tmp_slot)
self.settings.modelSlotIndex = self.tmp_slot self.settings.modelSlotIndex = tmp_slot
self.currentSlot = self.settings.modelSlotIndex self.currentSlot = self.settings.modelSlotIndex
self.switchModel() self.switchModel()
self.initialLoad = False self.initialLoad = False
@ -290,8 +275,9 @@ class RVC:
self.onnx_session.set_providers(providers=["CUDAExecutionProvider"], provider_options=provider_options) self.onnx_session.set_providers(providers=["CUDAExecutionProvider"], provider_options=provider_options)
if key == "modelSlotIndex": if key == "modelSlotIndex":
# self.switchModel(int(val)) # self.switchModel(int(val))
self.tmp_slot = int(val) val = int(val) % 1000 # Quick hack for same slot is selected
self.prepareModel(self.tmp_slot) self.prepareModel(val)
self.currentSlot = -1
setattr(self.settings, key, int(val)) setattr(self.settings, key, int(val))
elif key in self.settings.floatData: elif key in self.settings.floatData:
setattr(self.settings, key, float(val)) setattr(self.settings, key, float(val))
@ -431,8 +417,8 @@ class RVC:
return result return result
def inference(self, data): def inference(self, data):
if self.settings.modelSlotIndex < -1: if self.settings.modelSlotIndex < 0:
print("[Voice Changer] No model uploaded.") print("[Voice Changer] wait for loading model...", self.settings.modelSlotIndex, self.currentSlot)
raise NoModeLoadedException("model_common") raise NoModeLoadedException("model_common")
if self.currentSlot != self.settings.modelSlotIndex: if self.currentSlot != self.settings.modelSlotIndex: