47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from flask import Flask
|
|
from app.settings import config
|
|
from app.utils import register_cors, make_response
|
|
from app.asr.routes import register_asr_routes
|
|
from app.transcode.routes import register_transcode_routes
|
|
from waitress import serve
|
|
|
|
from lib.caddy.run import run_caddy
|
|
|
|
def create_app():
|
|
"""【统一创建 Flask 服务】唯一创建 app 的地方"""
|
|
app = Flask(__name__)
|
|
|
|
# 加载全局配置
|
|
app.config.update(config)
|
|
|
|
# 注册全局工具
|
|
register_cors(app)
|
|
|
|
# 注册各个业务模块路由(模块只提供入口)
|
|
register_asr_routes(app)
|
|
register_transcode_routes(app)
|
|
|
|
# 根路由
|
|
@app.route('/')
|
|
def index():
|
|
return make_response(message="ASR & Speaker Diarization API 服务运行中")
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
api_port = config['API_PORT']
|
|
video_port = config['VIDEO_PORT']
|
|
|
|
app = create_app()
|
|
|
|
print("=" * 60)
|
|
print(f" API Server (模块化架构) 监听端口:{api_port}")
|
|
print(f" 视频文件服务监听端口:{video_port}")
|
|
print("=" * 60)
|
|
|
|
# 启动视频文件服务
|
|
run_caddy(port=video_port)
|
|
|
|
# 启动服务
|
|
serve(app, host='0.0.0.0', port=api_port, threads=4, connection_limit=100)
|