Spaces:
Sleeping
Sleeping
File size: 1,022 Bytes
f42ec01 5760b44 f42ec01 a5fed35 5760b44 f42ec01 35c0239 5760b44 f42ec01 b1106e6 f42ec01 5760b44 f42ec01 5760b44 f42ec01 a5fed35 |
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 |
import uvicorn
from fastapi import FastAPI, HTTPException
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.get('/')
async def root():
return ("Welcome to the comma fixer. Send a POST request to /fix-commas or /baseline/fix-commas with a string "
"'s' in the JSON body to try "
"out the functionality.")
@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)
if __name__ == '__main__':
uvicorn.run("app:app", reload=True, port=8000)
|