Update api.py

接口api增加跨域功能,方便接入其他应用,避免触发同源策略
This commit is contained in:
刘悦 2024-02-29 20:28:02 +08:00 committed by GitHub
parent 0ab0e5390f
commit 93be26afbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

10
api.py
View File

@ -129,6 +129,9 @@ from text.cleaner import clean_text
from module.mel_processing import spectrogram_torch
from my_utils import load_audio
import config as global_config
from starlette.middleware.cors import CORSMiddleware #引入 CORS中间件模块
#设置允许访问的域名
origins = ["*"] #"*",即为所有。
g_config = global_config.Config()
@ -490,6 +493,13 @@ def handle(refer_wav_path, prompt_text, prompt_language, text, text_language):
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins, #设置允许的origins来源
allow_credentials=True,
allow_methods=["*"], # 设置允许跨域的http方法比如 get、post、put等。
allow_headers=["*"]) #允许跨域的headers可以用来鉴别来源等作用。
#clark新增-----2024-02-21
#可在启动后动态修改模型以此满足同一个api不同的朗读者请求
@app.post("/set_model")