server.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from pydantic import BaseModel, field_validator, model_validator, Field
  2. from typing import List, Optional, Generic, TypeVar
  3. from utils import base64_to_cv2
  4. from fastapi import FastAPI
  5. import uvicorn
  6. app = FastAPI()
  7. T = TypeVar("T")
  8. class APIRequest(BaseModel):
  9. imageData : str
  10. text : str
  11. class APIResponse(BaseModel, Generic[T]):
  12. success: bool
  13. data: Optional[List[T]]
  14. msg: Optional[List[str]]
  15. @app.post("/llm/detect")
  16. @app.post("/llm/detect/")
  17. async def detect(item: APIRequest):
  18. # illegal 为 0 代表没有违章
  19. # illegal 为 1 代表有违章
  20. response = {
  21. "sucess": "OK",
  22. "data": {"illegal" : 0},
  23. "msg": ""
  24. }
  25. image = base64_to_cv2(item.imageData)
  26. if not image.size:
  27. response["sucess"] = "FAILED"
  28. response["msg"] = "Decode Image Error"
  29. return response
  30. # 提示词
  31. text = item.text
  32. # 大模型检测后如果有违章
  33. # response["data"]["illegal"] = 1
  34. return response
  35. if __name__ == "__main__":
  36. uvicorn.run('server:app', host="0.0.0.0", port=18000)