-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,64 @@ | ||
import logging | ||
from jel.api.v1 import predictor | ||
from fastapi import FastAPI | ||
|
||
FORMAT = "%(message)s" | ||
logging.basicConfig( | ||
level="NOTSET", format=FORMAT, datefmt="[%X]" | ||
) | ||
from fastapi.middleware.cors import CORSMiddleware | ||
import uvicorn | ||
from fastapi import FastAPI, File, UploadFile | ||
from pydantic import BaseModel | ||
import uvicorn | ||
from fastapi import BackgroundTasks, FastAPI | ||
from fastapi import HTTPException | ||
|
||
|
||
def app() -> FastAPI: | ||
app = FastAPI() | ||
app.state.cache = {} | ||
app.include_router(predictor.router) | ||
app = FastAPI() | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
|
||
from jel.mention_predictor import EntityLinker | ||
|
||
class Sentence(BaseModel): | ||
sentence: str | ||
|
||
logger = logging.getLogger(__file__) | ||
logger.info("loading linker...") | ||
el = EntityLinker() | ||
logger.info("loading finished!") | ||
|
||
@app.post("/link") | ||
async def link(params: Sentence): | ||
if params.sentence is None: | ||
raise HTTPException(status_code=400, detail="Sentence is required.") | ||
|
||
try: | ||
result = el.link(sentence=params.sentence) | ||
except Exception: | ||
raise HTTPException(status_code=400, detail="fail to link") | ||
|
||
return {"result": result} | ||
|
||
@app.post("/question") | ||
async def question(params: Sentence): | ||
if params.sentence is None: | ||
raise HTTPException(status_code=400, detail="Sentence is required.") | ||
|
||
try: | ||
result = el.question(sentence=params.sentence) | ||
except Exception: | ||
raise HTTPException(status_code=400, detail="fail to link") | ||
|
||
return {"result": result} | ||
|
||
|
||
return app | ||
if __name__ == '__main__': | ||
uvicorn.run("app:app", host='0.0.0.0', port=8000, | ||
log_level="debug", debug=True) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters