update server_fastapi.py. 模型文件不存在时跳过加载模型

This commit is contained in:
Sora
2023-12-06 21:48:52 +08:00
parent c2fcc02984
commit a4f3388029

View File

@@ -87,6 +87,16 @@ class Models:
:param device: 模型推理使用设备 :param device: 模型推理使用设备
:param language: 模型推理默认语言 :param language: 模型推理默认语言
""" """
# 若文件不存在则不进行加载
if not os.path.isfile(model_path):
if model_path != "":
logger.warning(f"模型文件{model_path} 不存在,不进行初始化")
return self.num
if not os.path.isfile(config_path):
if config_path != "":
logger.warning(f"配置文件{config_path} 不存在,不进行初始化")
return self.num
# 若路径中的模型已存在,则不添加模型,若不存在,则进行初始化。 # 若路径中的模型已存在,则不添加模型,若不存在,则进行初始化。
model_path = os.path.realpath(model_path) model_path = os.path.realpath(model_path)
if model_path not in self.path2ids.keys(): if model_path not in self.path2ids.keys():