model dir parameterized

This commit is contained in:
wataru 2023-05-29 03:29:29 +09:00
parent 21f098e8ec
commit f1683cb4a8
2 changed files with 14 additions and 5 deletions

View File

@ -209,7 +209,7 @@ if __name__ == "MMVCServerSIO":
printMessage("failed to download weight for rvc", level=2)
voiceChangerManager = VoiceChangerManager.get_instance(voiceChangerParams)
app_fastapi = MMVC_Rest.get_instance(voiceChangerManager)
app_fastapi = MMVC_Rest.get_instance(voiceChangerManager, voiceChangerParams)
app_socketio = MMVC_SocketIOApp.get_instance(app_fastapi, voiceChangerManager)

View File

@ -13,6 +13,7 @@ from restapi.MMVC_Rest_Hello import MMVC_Rest_Hello
from restapi.MMVC_Rest_VoiceChanger import MMVC_Rest_VoiceChanger
from restapi.MMVC_Rest_Fileuploader import MMVC_Rest_Fileuploader
from const import UPLOAD_DIR, getFrontendPath, TMP_DIR
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
class ValidationErrorLoggingRoute(APIRoute):
@ -35,7 +36,11 @@ class MMVC_Rest:
_instance = None
@classmethod
def get_instance(cls, voiceChangerManager: VoiceChangerManager):
def get_instance(
cls,
voiceChangerManager: VoiceChangerManager,
voiceChangerParams: VoiceChangerParams,
):
if cls._instance is None:
app_fastapi = FastAPI()
app_fastapi.router.route_class = ValidationErrorLoggingRoute
@ -75,14 +80,18 @@ class MMVC_Rest:
p1 = os.path.dirname(sys._MEIPASS)
p2 = os.path.dirname(p1)
p3 = os.path.dirname(p2)
model_dir = os.path.join(p3, "models")
model_dir = os.path.join(p3, voiceChangerParams.model_dir)
print("mac model_dir:", model_dir)
app_fastapi.mount(
"/models", StaticFiles(directory=model_dir), name="static"
f"/{voiceChangerParams.model_dir}",
StaticFiles(directory=model_dir),
name="static",
)
else:
app_fastapi.mount(
"/models", StaticFiles(directory="models"), name="static"
f"/{voiceChangerParams.model_dir}",
StaticFiles(directory=voiceChangerParams.model_dir),
name="static",
)
restHello = MMVC_Rest_Hello()