Skip to content

Commit

Permalink
Merge pull request #50 from Dushyantbha012/main
Browse files Browse the repository at this point in the history
updated the fastAPI backend with latest specifications of lifespans
  • Loading branch information
Pranav0-0Aggarwal authored Oct 12, 2024
2 parents c0d8f40 + ce4002e commit 8dc7ac8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from time import sleep
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager

from app.database.faces import cleanup_face_embeddings, create_faces_table
from app.database.images import create_image_id_mapping_table, create_images_table
Expand All @@ -17,26 +18,21 @@
from app.routes.facetagging import router as tagging_router


app = FastAPI()


@app.on_event("startup")
async def startup_event():
@asynccontextmanager
async def lifespan(app: FastAPI):
create_YOLO_mappings()
create_faces_table()
create_image_id_mapping_table()
create_images_table()
create_albums_table()
cleanup_face_embeddings()
init_face_cluster()


@app.on_event("shutdown")
async def shutdown_event():
yield
face_cluster = get_face_cluster()
if face_cluster:
face_cluster.save_to_db()

app = FastAPI(lifespan=lifespan)

# Add CORS middleware
app.add_middleware(
Expand Down

0 comments on commit 8dc7ac8

Please sign in to comment.