File size: 1,067 Bytes
f42ec01
 
a9ea03f
 
f42ec01
5760b44
 
 
 
 
a9ea03f
f42ec01
 
a5fed35
5760b44
f42ec01
 
b1106e6
 
f42ec01
 
5760b44
f42ec01
 
 
5760b44
 
a9ea03f
 
a5fed35
a9ea03f
 
 
 
 
 
 
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
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from src.baseline import BaselineCommaFixer
import logging

logger = logging.Logger(__name__)
logging.basicConfig(level=logging.INFO)

app = FastAPI()  # TODO router?
logger.info('Loading the baseline model...')
app.baseline_model = BaselineCommaFixer()


@app.post('/baseline/fix-commas/')
async def fix_commas_with_baseline(data: dict):
    json_field_name = 's'
    if json_field_name in data:
        logger.debug('Fixing commas.')
        return {json_field_name: app.baseline_model.fix_commas(data['s'])}
    else:
        msg = f"Text '{json_field_name}' missing"
        logger.debug(msg)
        raise HTTPException(status_code=400, detail=msg)


app.mount("/", StaticFiles(directory="static", html=True), name="static")


@app.get('/')
async def index() -> FileResponse:
    return FileResponse(path="static/index.html", media_type="text/html")


if __name__ == '__main__':
    uvicorn.run("app:app", port=8000)