Files
2025-07-29 18:15:35 +08:00

31 lines
875 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"}