58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from pydantic import BaseModel
|
|
import uvicorn
|
|
|
|
from pipeline import PipePredictor
|
|
from utils import base64_to_cv2
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# class Item(BaseModel):
|
|
# img_base64: str = None #图片base64
|
|
|
|
class Item(BaseModel):
|
|
imgbase64: str = None
|
|
|
|
@app.get("/ocr/vehicle_certificate/state")
|
|
async def get_state():
|
|
return "OCR Vehicle Certificate is running!"
|
|
|
|
@app.post('/ocr/vehicle_certificate')
|
|
async def predict(request_data: Item):
|
|
img_base64 = request_data.imgbase64
|
|
img = base64_to_cv2(img_base64)
|
|
result = pipe_predictor(img)
|
|
return result
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# from register import Register
|
|
# register = Register()
|
|
# while(not register.checkAuthored()):
|
|
# register.register()
|
|
|
|
from authorization import Authorization
|
|
authorization = Authorization()
|
|
while(not authorization.check()):
|
|
authorization.activate()
|
|
|
|
pipe_predictor = PipePredictor()
|
|
print("OCR Vehicle Certificate Service start!")
|
|
uvicorn.run(app=app,
|
|
host="0.0.0.0",
|
|
port=8002,
|
|
# reload=True,
|
|
workers=1,
|
|
)
|