|
@@ -0,0 +1,38 @@
|
|
|
+from pydantic import BaseModel, field_validator, model_validator, Field
|
|
|
+from typing import List, Optional, Generic, TypeVar
|
|
|
+from utils import base64_to_cv2
|
|
|
+from fastapi import FastAPI
|
|
|
+
|
|
|
+app = FastAPI()
|
|
|
+
|
|
|
+T = TypeVar("T")
|
|
|
+
|
|
|
+class APIRequest(BaseModel):
|
|
|
+ imageData : str
|
|
|
+ text : str
|
|
|
+
|
|
|
+class APIResponse(BaseModel, Generic[T]):
|
|
|
+ success: bool
|
|
|
+ data: Optional[List[T]]
|
|
|
+ msg: Optional[List[str]]
|
|
|
+
|
|
|
+@app.post("/llm/detect")
|
|
|
+@app.post("/llm/detect/")
|
|
|
+async def detect(item: APIRequest):
|
|
|
+ # illegal 为 0 代表没有违章
|
|
|
+ # illegal 为 1 代表有违章
|
|
|
+ response = {
|
|
|
+ "sucess": "OK",
|
|
|
+ "data": {"illegal" : 0},
|
|
|
+ "msg": ""
|
|
|
+ }
|
|
|
+ image = base64_to_cv2(item.imageData)
|
|
|
+ if not image.size:
|
|
|
+ response["sucess"] = "FAILED"
|
|
|
+ response["msg"] = "Decode Image Error"
|
|
|
+ return response
|
|
|
+
|
|
|
+ # 大模型检测后如果有违章
|
|
|
+ # response["data"]["illegal"] = 1
|
|
|
+
|
|
|
+ return response
|