-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (57 loc) · 1.63 KB
/
app.py
File metadata and controls
66 lines (57 loc) · 1.63 KB
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
60
61
62
63
64
65
66
import numpy as np
from pathlib import Path
from typing import Optional
from fastapi import FastAPI, File, UploadFile, Form
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from PIL import Image
import pytesseract
import cv2
import config
from load import ImageProcessing
from starlette.responses import Response
import boto3
from datetime import datetime
app = FastAPI()
origins = [
"http://localhost:8001",
"http://localhost:3000",
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
load = ImageProcessing()
client_s3 = boto3.client(
's3',
region_name=config.AWS_S3_CONFIG['AWS_REGION'],
aws_access_key_id=config.AWS_S3_CONFIG['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=config.AWS_S3_CONFIG['AWS_SECRET_ACCESS_KEY']
)
@app.get("/")
async def read_root():
return {"Health": "active"}
# OCR 인식 Request
@app.post("/ocr/")
async def upload_image(
imagez: UploadFile = File(...),
id: int = Form(...),
name: str = Form(...),
):
try:
image = Image.open(imagez.file)
img = np.array(image)
result = load.scanId(img, id, name)
if result == -1:
return JSONResponse(status_code=404)
else:
# res=client_s3.upload_file(imagez.file , config.AWS_S3_CONFIG['AWS_S3_BUCKET_NAME'], ExtraArgs={'ACL': 'public-read'} )
# print(res)
return {'status': True}
except Exception as e:
print(f"Unexpected {e=}, {type(e)=}")
return JSONResponse(status_code=500)