31 lines
875 B
Python
31 lines
875 B
Python
|
|
|||
|
from fastapi import FastAPI
|
|||
|
from .api import router as api_router
|
|||
|
|
|||
|
from .database import database, create_tables
|
|||
|
|
|||
|
app = FastAPI(
|
|||
|
title="人脸识别服务 V2 - PostgreSQL版",
|
|||
|
description="一个使用PostgreSQL和Milvus的高性能人脸识别服务。",
|
|||
|
version="2.1.0"
|
|||
|
)
|
|||
|
|
|||
|
@app.on_event("startup")
|
|||
|
async def on_startup():
|
|||
|
"""应用启动时,连接数据库并创建表"""
|
|||
|
await database.connect()
|
|||
|
create_tables() # SQLAlchemy的create_all是同步的,所以这样调用没问题
|
|||
|
|
|||
|
@app.on_event("shutdown")
|
|||
|
async def on_shutdown():
|
|||
|
"""应用关闭时,断开数据库连接"""
|
|||
|
await database.disconnect()
|
|||
|
|
|||
|
|
|||
|
# 挂载API路由
|
|||
|
app.include_router(api_router, prefix="/api", tags=["Face Recognition"])
|
|||
|
|
|||
|
@app.get("/", summary="服务健康检查")
|
|||
|
def read_root():
|
|||
|
return {"status": "ok", "message": "欢迎使用人脸识别服务 V2"}
|