1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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
- import uvicorn
- 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
-
- # 提示词
- text = item.text
- # 大模型检测后如果有违章
- # response["data"]["illegal"] = 1
-
- return response
- if __name__ == "__main__":
- uvicorn.run('server:app', host="0.0.0.0", port=18000)
|