WIP: multi

This commit is contained in:
wataru 2023-04-16 00:38:48 +09:00
parent 707096b48c
commit e1e1f94fa3
3 changed files with 42 additions and 13 deletions

View File

@ -34,7 +34,6 @@ class MMVC_Rest_Fileuploader:
json_compatible_item_data = jsonable_encoder(res) json_compatible_item_data = jsonable_encoder(res)
return JSONResponse(content=json_compatible_item_data) 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(...)): def post_concat_uploaded_file(self, filename: str = Form(...), filenameChunkNum: int = Form(...)):
slot = 0 slot = 0
res = concat_file_chunks(slot, UPLOAD_DIR, filename, filenameChunkNum, UPLOAD_DIR) res = concat_file_chunks(slot, UPLOAD_DIR, filename, filenameChunkNum, UPLOAD_DIR)
@ -54,7 +53,7 @@ class MMVC_Rest_Fileuploader:
def post_load_model( def post_load_model(
self, self,
# slot: int = Form(...), slot: int = Form(...),
pyTorchModelFilename: str = Form(...), pyTorchModelFilename: str = Form(...),
onnxModelFilename: str = Form(...), onnxModelFilename: str = Form(...),
configFilename: str = Form(...), configFilename: str = Form(...),
@ -63,15 +62,44 @@ class MMVC_Rest_Fileuploader:
indexFilename: str = Form(...), indexFilename: str = Form(...),
isHalf: bool = 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, # # Upload File Path
clusterTorchModelFilePath, featureFilePath, indexFilePath, # 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) isHalf)
json_compatible_item_data = jsonable_encoder(info) json_compatible_item_data = jsonable_encoder(info)
return JSONResponse(content=json_compatible_item_data) return JSONResponse(content=json_compatible_item_data)

View File

@ -108,6 +108,7 @@ class VoiceChanger():
def loadModel( def loadModel(
self, self,
slot: number,
config: str, config: str,
pyTorch_model_file: Optional[str] = None, pyTorch_model_file: Optional[str] = None,
onnx_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": 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) return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel)
elif self.modelType == "RVC": 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: else:
return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel) return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel)
except Exception as e: except Exception as e:

View File

@ -11,8 +11,8 @@ class VoiceChangerManager():
cls._instance.voiceChanger = VoiceChanger(params) cls._instance.voiceChanger = VoiceChanger(params)
return cls._instance return cls._instance
def loadModel(self, config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half: bool = True): def loadModel(self, slot, 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) info = self.voiceChanger.loadModel(slot, config, model, onnx_model, clusterTorchModel, feature_file, index_file, is_half)
if hasattr(info, "status") and info["status"] == "NG": if hasattr(info, "status") and info["status"] == "NG":
return info return info
else: else: