Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -4,14 +4,19 @@ from contextlib import asynccontextmanager
|
|
4 |
import logging
|
5 |
from api.endpoints import location
|
6 |
|
|
|
7 |
|
8 |
@asynccontextmanager
|
9 |
async def lifespan(app: FastAPI):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
yield
|
14 |
|
15 |
-
app = FastAPI(lifespan=lifespan)
|
16 |
app.include_router(location.router, prefix="/location/api/v1")
|
17 |
|
|
|
4 |
import logging
|
5 |
from api.endpoints import location
|
6 |
|
7 |
+
app = FastAPI(lifespan=lifespan)
|
8 |
|
9 |
@asynccontextmanager
|
10 |
async def lifespan(app: FastAPI):
|
11 |
+
# initialize_nlp()
|
12 |
+
print("Initializing NER model and tokenizer")
|
13 |
+
logging.info("Initializing NER model and tokenizer")
|
14 |
+
|
15 |
+
app.tokenizer = AutoTokenizer.from_pretrained("ml6team/bert-base-uncased-city-country-ner")
|
16 |
+
app.model = AutoModelForTokenClassification.from_pretrained("ml6team/bert-base-uncased-city-country-ner")
|
17 |
+
app.nlp = pipeline('ner', model=app.model, tokenizer=app.tokenizer, aggregation_strategy="simple")
|
18 |
+
|
19 |
yield
|
20 |
|
|
|
21 |
app.include_router(location.router, prefix="/location/api/v1")
|
22 |
|