Skip to content

Commit

Permalink
Merge pull request #210 from jiangyuxiaoxiao/master
Browse files Browse the repository at this point in the history
update server_fastapi.py: 缺少web文件时添加提示信息。configyml添加更多帮助注释
  • Loading branch information
jiangyuxiaoxiao authored Dec 1, 2023
2 parents d4a2bc2 + 95f44ed commit b4d7bc5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ server:
port: 5000
# 模型默认使用设备:但是当前并没有实现这个配置。
device: "cuda"
# 需要加载的所有模型的配置
# 需要加载的所有模型的配置,可以填多个模型,也可以不填模型,等网页成功后手动加载模型
# 不加载模型的配置格式:删除默认给的两个模型配置,给models赋值 [ ],也就是空列表。参考模型2的speakers 即 models: [ ]
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
# 也可以不填模型,等网页加载成功后手动填写models。
models:
- # 模型的路径
model: ""
Expand Down
24 changes: 16 additions & 8 deletions server_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,24 @@ def get_models(self):
app = FastAPI()
app.logger = logger
# 挂载静态文件
logger.info("开始挂载网页页面")
StaticDir: str = "./Web"
dirs = [fir.name for fir in os.scandir(StaticDir) if fir.is_dir()]
files = [fir.name for fir in os.scandir(StaticDir) if fir.is_dir()]
for dirName in dirs:
app.mount(
f"/{dirName}",
StaticFiles(directory=f"./{StaticDir}/{dirName}"),
name=dirName,
if not os.path.isdir(StaticDir):
logger.warning(
"缺少网页资源,无法开启网页页面,如有需要请在 https://github.com/jiangyuxiaoxiao/Bert-VITS2-UI 或者Bert-VITS对应版本的release页面下载"
)
else:
dirs = [fir.name for fir in os.scandir(StaticDir) if fir.is_dir()]
files = [fir.name for fir in os.scandir(StaticDir) if fir.is_dir()]
for dirName in dirs:
app.mount(
f"/{dirName}",
StaticFiles(directory=f"./{StaticDir}/{dirName}"),
name=dirName,
)
loaded_models = Models()
# 加载模型
logger.info("开始加载模型")
models_info = config.server_config.models
for model_info in models_info:
loaded_models.init_model(
Expand Down Expand Up @@ -605,7 +612,8 @@ def get_audio(request: Request, path: str = Query(..., description="本地音频

logger.warning("本地服务,请勿将服务端口暴露于外网")
logger.info(f"api文档地址 http://127.0.0.1:{config.server_config.port}/docs")
webbrowser.open(f"http://127.0.0.1:{config.server_config.port}")
if os.path.isdir(StaticDir):
webbrowser.open(f"http://127.0.0.1:{config.server_config.port}")
uvicorn.run(
app, port=config.server_config.port, host="0.0.0.0", log_level="warning"
)

0 comments on commit b4d7bc5

Please sign in to comment.