-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
59 lines (45 loc) · 1.32 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
54
55
56
57
58
59
import cv2
import numpy as np
import uvicorn
from starlette.responses import JSONResponse
from utils.clova import clova_ocr
from utils.image_preprocess import PreProcessor
from fastapi import FastAPI, HTTPException, File, UploadFile
from pydantic import BaseModel
import logging
import warnings
from utils.nutrition_runner import nutrition_run
from utils.pororo_ocr import PororoOcr
warnings.filterwarnings('ignore')
class ImageRequest(BaseModel):
image_key: str
app = FastAPI()
ocr = PororoOcr()
preprocessor = PreProcessor()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@app.get("/")
def health_check():
return {"ping":"pong"}
@app.exception_handler(Exception)
def handle_unexpected_error(request, exc: Exception):
return JSONResponse(
status_code=500,
content={"detail": f"An unexpected error occurred: {exc}"},
)
@app.post("/parse_nutrients", status_code=201)
async def read_item(file: UploadFile = File(...)):
contents = await file.read()
result = clova_ocr(file, contents)
if not result:
raise HTTPException(status_code=422, detail='Text Recognition Fail')
else:
return result
if __name__ == '__main__':
uvicorn.run(
app='main:app',
host='0.0.0.0',
port=8000,
workers=1,
access_log=False,
)