From e1e1f94fa3bbddf803d75c04374f8ce09a30ed5a Mon Sep 17 00:00:00 2001 From: wataru Date: Sun, 16 Apr 2023 00:38:48 +0900 Subject: [PATCH] WIP: multi --- server/restapi/MMVC_Rest_Fileuploader.py | 48 ++++++++++++++++----- server/voice_changer/VoiceChanger.py | 3 +- server/voice_changer/VoiceChangerManager.py | 4 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/server/restapi/MMVC_Rest_Fileuploader.py b/server/restapi/MMVC_Rest_Fileuploader.py index 23acc561..0fce9e68 100644 --- a/server/restapi/MMVC_Rest_Fileuploader.py +++ b/server/restapi/MMVC_Rest_Fileuploader.py @@ -34,7 +34,6 @@ class MMVC_Rest_Fileuploader: json_compatible_item_data = jsonable_encoder(res) return JSONResponse(content=json_compatible_item_data) - # def post_concat_uploaded_file(self, slot: int = Form(...), filename: str = Form(...), filenameChunkNum: int = Form(...)): def post_concat_uploaded_file(self, filename: str = Form(...), filenameChunkNum: int = Form(...)): slot = 0 res = concat_file_chunks(slot, UPLOAD_DIR, filename, filenameChunkNum, UPLOAD_DIR) @@ -54,7 +53,7 @@ class MMVC_Rest_Fileuploader: def post_load_model( self, - # slot: int = Form(...), + slot: int = Form(...), pyTorchModelFilename: str = Form(...), onnxModelFilename: str = Form(...), configFilename: str = Form(...), @@ -63,15 +62,44 @@ class MMVC_Rest_Fileuploader: indexFilename: str = Form(...), isHalf: bool = Form(...), ): - pyTorchModelFilePath = os.path.join(UPLOAD_DIR, pyTorchModelFilename) if pyTorchModelFilename != "-" else None - onnxModelFilePath = os.path.join(UPLOAD_DIR, onnxModelFilename) if onnxModelFilename != "-" else None - configFilePath = os.path.join(UPLOAD_DIR, configFilename) - clusterTorchModelFilePath = os.path.join(UPLOAD_DIR, clusterTorchModelFilename) if clusterTorchModelFilename != "-" else None - featureFilePath = os.path.join(UPLOAD_DIR, featureFilename) if featureFilename != "-" else None - indexFilePath = os.path.join(UPLOAD_DIR, indexFilename) if indexFilename != "-" else None - info = self.voiceChangerManager.loadModel(configFilePath, pyTorchModelFilePath, onnxModelFilePath, - clusterTorchModelFilePath, featureFilePath, indexFilePath, + # # Upload File Path + # pyTorchModelFilePath = os.path.join(UPLOAD_DIR, pyTorchModelFilename) if pyTorchModelFilename != "-" else None + # onnxModelFilePath = os.path.join(UPLOAD_DIR, onnxModelFilename) if onnxModelFilename != "-" else None + # configFilePath = os.path.join(UPLOAD_DIR, configFilename) + # clusterTorchModelFilePath = os.path.join(UPLOAD_DIR, clusterTorchModelFilename) if clusterTorchModelFilename != "-" else None + # featureFilePath = os.path.join(UPLOAD_DIR, featureFilename) if featureFilename != "-" else None + # indexFilePath = os.path.join(UPLOAD_DIR, indexFilename) if indexFilename != "-" else None + + # # Stored File Path by Slot + # pyTorchModelStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", pyTorchModelFilename) if pyTorchModelFilename != "-" else None + # onnxModelStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", onnxModelFilename) if onnxModelFilename != "-" else None + # configStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", configFilename) + # clusterTorchModelStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", clusterTorchModelFilename) if clusterTorchModelFilename != "-" else None + # featureStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", featureFilename) if featureFilename != "-" else None + # indexStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", indexFilename) if indexFilename != "-" else None + + # # Store File + # if pyTorchModelFilename != "-": + # pyTorchModelFilePath = os.path.join(UPLOAD_DIR, pyTorchModelFilename) + # pyTorchModelStoredFilePath = os.path.join(UPLOAD_DIR, f"{slot}", pyTorchModelFilename) + # shutil.move(pyTorchModelFilePath, pyTorchModelStoredFilePath) + + paths = [] + for x in [pyTorchModelFilename, onnxModelFilename, configFilename, clusterTorchModelFilename, featureFilename, indexFilename]: + if x != "-": + uploadPath = os.path.join(UPLOAD_DIR, x) + storeDir = os.path.join(UPLOAD_DIR, f"{slot}") + os.makedirs(storeDir, exist_ok=True) + storePath = os.path.join(storeDir, x) + shutil.move(uploadPath, storePath) + paths.push(storePath) + else: + paths.push(None) + pyTorchModelStoredFilePath, onnxModelStoredFilePath, configStoredFilePath, clusterTorchModelStoredFilePath, featureStoredFilePath, indexStoredFilePath = paths + + info = self.voiceChangerManager.loadModel(slot, configStoredFilePath, pyTorchModelStoredFilePath, onnxModelStoredFilePath, + clusterTorchModelStoredFilePath, featureStoredFilePath, indexStoredFilePath, isHalf) json_compatible_item_data = jsonable_encoder(info) return JSONResponse(content=json_compatible_item_data) diff --git a/server/voice_changer/VoiceChanger.py b/server/voice_changer/VoiceChanger.py index e27e145c..b50fa470 100755 --- a/server/voice_changer/VoiceChanger.py +++ b/server/voice_changer/VoiceChanger.py @@ -108,6 +108,7 @@ class VoiceChanger(): def loadModel( self, + slot: number, config: str, pyTorch_model_file: Optional[str] = None, onnx_model_file: Optional[str] = None, @@ -123,7 +124,7 @@ class VoiceChanger(): elif self.modelType == "so-vits-svc-40" or self.modelType == "so-vits-svc-40_c" or self.modelType == "so-vits-svc-40v2": return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel) elif self.modelType == "RVC": - return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, feature_file, index_file, is_half) + return self.voiceChanger.loadModel(slot, config, pyTorch_model_file, onnx_model_file, feature_file, index_file, is_half) else: return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel) except Exception as e: diff --git a/server/voice_changer/VoiceChangerManager.py b/server/voice_changer/VoiceChangerManager.py index 62ae75fc..9a731139 100644 --- a/server/voice_changer/VoiceChangerManager.py +++ b/server/voice_changer/VoiceChangerManager.py @@ -11,8 +11,8 @@ class VoiceChangerManager(): cls._instance.voiceChanger = VoiceChanger(params) return cls._instance - def loadModel(self, config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half: bool = True): - info = self.voiceChanger.loadModel(config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half) + def loadModel(self, slot, config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half: bool = True): + info = self.voiceChanger.loadModel(slot, config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half) if hasattr(info, "status") and info["status"] == "NG": return info else: