-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (43 loc) · 1.47 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel
from starlette.responses import FileResponse
from starlette.staticfiles import StaticFiles
from ner_tagger import ner_tagger
from crime_tagger import crime_tagger
class Query(BaseModel):
sent: str
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
app.mount("/static", StaticFiles(directory="build/static"))
@app.get("/api")
async def root():
return {"msg": "Usage: post '/api/ner' with json 'sent'"}
@app.post("/api/ner") # 한국어 문장 -> NER 태그하여 반환
async def api_ner(query:Query):
res = ner_tagger(query.sent)
print(res)
return JSONResponse(content=jsonable_encoder(res))
@app.post("/api/crime") # 한국어 문장 -> crime keywords 태그하여 반환
async def api_crime(query:Query):
res = crime_tagger(query.sent)
print(res)
return JSONResponse(content=jsonable_encoder(res))
@app.post("/api/both") # 위에꺼 두개 다 해서 반환
async def api_crime(query:Query):
res_ner = ner_tagger(query.sent)
res_crime = crime_tagger(query.sent)
print(res_ner, res_crime)
return JSONResponse(content=jsonable_encoder(res_ner+res_crime))
@app.get("/")
def index():
return FileResponse("build/index.html")