diff --git a/server/MMVCServerSIO.py b/server/MMVCServerSIO.py index 090f7049..11c353cb 100755 --- a/server/MMVCServerSIO.py +++ b/server/MMVCServerSIO.py @@ -134,27 +134,27 @@ if __name__ == thisFilename or args.colab == True: MODEL_DIR = "MMVC_Trainer/logs" os.makedirs(MODEL_DIR, exist_ok=True) - @app_fastapi.post("/upload_file") - async def post_upload_file( - file: UploadFile = File(...), - filename: str = Form(...) - ): - return upload_file(UPLOAD_DIR, file, filename) + # @app_fastapi.post("/upload_file") + # async def post_upload_file( + # file: UploadFile = File(...), + # filename: str = Form(...) + # ): + # return upload_file(UPLOAD_DIR, file, filename) - @app_fastapi.post("/load_model") - async def post_load_model( - modelFilename: str = Form(...), - modelFilenameChunkNum: int = Form(...), - configFilename: str = Form(...) - ): + # @app_fastapi.post("/load_model") + # async def post_load_model( + # modelFilename: str = Form(...), + # modelFilenameChunkNum: int = Form(...), + # configFilename: str = Form(...) + # ): - modelFilePath = concat_file_chunks( - UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR) - print(f'File saved to: {modelFilePath}') - configFilePath = os.path.join(UPLOAD_DIR, configFilename) + # modelFilePath = concat_file_chunks( + # UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR) + # print(f'File saved to: {modelFilePath}') + # configFilePath = os.path.join(UPLOAD_DIR, configFilename) - voiceChangerManager.loadModel(configFilePath, modelFilePath) - return {"load": f"{modelFilePath}, {configFilePath}"} + # voiceChangerManager.loadModel(configFilePath, modelFilePath) + # return {"load": f"{modelFilePath}, {configFilePath}"} @app_fastapi.post("/load_model_for_train") async def post_load_model_for_train( @@ -184,49 +184,6 @@ if __name__ == thisFilename or args.colab == True: # Voice Changer # ########## - @app_fastapi.post("/test2") - async def post_test2(voice: VoiceModel): - try: - # print("POST REQUEST PROCESSING....") - gpu = voice.gpu - srcId = voice.srcId - dstId = voice.dstId - timestamp = voice.timestamp - prefixChunkSize = voice.prefixChunkSize - buffer = voice.buffer - wav = base64.b64decode(buffer) - - if wav == 0: - samplerate, data = read("dummy.wav") - unpackedData = data - else: - unpackedData = np.array(struct.unpack( - '<%sh' % (len(wav) // struct.calcsize(' Callable: original_route_handler = super().get_route_handler() @@ -51,6 +51,8 @@ class MMVC_Rest: app_fastapi.include_router(restHello.router) restVoiceChanger = MMVC_Rest_VoiceChanger(voiceChangerManager) app_fastapi.include_router(restVoiceChanger.router) + fileUploader = MMVC_Rest_Fileuploader(voiceChangerManager) + app_fastapi.include_router(fileUploader.router) cls._instance = app_fastapi return cls._instance diff --git a/server/restapi/MMVC_Rest_Fileuploader.py b/server/restapi/MMVC_Rest_Fileuploader.py new file mode 100644 index 00000000..3aefcc3a --- /dev/null +++ b/server/restapi/MMVC_Rest_Fileuploader.py @@ -0,0 +1,40 @@ +import os + +from fastapi import APIRouter +from fastapi.encoders import jsonable_encoder +from fastapi.responses import JSONResponse +from fastapi import HTTPException, FastAPI, UploadFile, File, Form + +from mods.FileUploader import upload_file, concat_file_chunks +from voice_changer.VoiceChangerManager import VoiceChangerManager + +UPLOAD_DIR = "upload_dir" +os.makedirs(UPLOAD_DIR, exist_ok=True) +MODEL_DIR = "MMVC_Trainer/logs" +os.makedirs(MODEL_DIR, exist_ok=True) + +class MMVC_Rest_Fileuploader: + def __init__(self, voiceChangerManager:VoiceChangerManager): + self.voiceChangerManager = voiceChangerManager + self.router = APIRouter() + self.router.add_api_route("/upload_file", self.post_upload_file, methods=["POST"]) + self.router.add_api_route("/load_model", self.post_load_model, methods=["POST"]) + + def post_upload_file(self, file: UploadFile = File(...), filename: str = Form(...)): + return upload_file(UPLOAD_DIR, file, filename) + + def post_load_model( + self, + modelFilename: str = Form(...), + modelFilenameChunkNum: int = Form(...), + configFilename: str = Form(...) + ): + modelFilePath = concat_file_chunks( + UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR) + configFilePath = os.path.join(UPLOAD_DIR, configFilename) + + self.voiceChangerManager.loadModel(configFilePath, modelFilePath) + return {"load": f"{modelFilePath}, {configFilePath}"} + + +