Spaces:
Sleeping
Sleeping
File size: 468 Bytes
c524d8c df37f6e c524d8c df37f6e c524d8c df37f6e c524d8c df37f6e c524d8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from contextlib import asynccontextmanager
from fastapi import FastAPI
from loguru import logger
@asynccontextmanager
async def lifespan(app: FastAPI):
# Load the ML model
from app.ner.services.ner import NER
ner: NER = NER()
ner.load_model()
app.state.ner = ner
logger.info("NER model loaded successfully.")
yield
# Clean up the ML models and release the resources
logger.info("Cleaning up NER model...")
del app.state.ner
|