Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -5,6 +5,7 @@ import logging
|
|
5 |
from api.endpoints import location
|
6 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
7 |
from transformers import pipeline
|
|
|
8 |
@asynccontextmanager
|
9 |
async def lifespan(app: FastAPI):
|
10 |
# initialize_nlp()
|
@@ -14,8 +15,10 @@ async def lifespan(app: FastAPI):
|
|
14 |
app.tokenizer = AutoTokenizer.from_pretrained("ml6team/bert-base-uncased-city-country-ner")
|
15 |
app.model = AutoModelForTokenClassification.from_pretrained("ml6team/bert-base-uncased-city-country-ner")
|
16 |
app.nlp = pipeline('ner', model=app.model, tokenizer=app.tokenizer, aggregation_strategy="simple")
|
17 |
-
|
18 |
yield
|
|
|
|
|
19 |
|
20 |
app = FastAPI(lifespan=lifespan)
|
21 |
|
|
|
5 |
from api.endpoints import location
|
6 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
7 |
from transformers import pipeline
|
8 |
+
from .models.fastapi_globals import g ,GlobalsMiddleware
|
9 |
@asynccontextmanager
|
10 |
async def lifespan(app: FastAPI):
|
11 |
# initialize_nlp()
|
|
|
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 |
+
g.set_default("ner_model", ner_model)
|
19 |
yield
|
20 |
+
del sentiment_model
|
21 |
+
g.cleanup()
|
22 |
|
23 |
app = FastAPI(lifespan=lifespan)
|
24 |
|