46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
import json
|
|
import logging
|
|
from fastapi import APIRouter
|
|
|
|
from app.schemas.attribute_retrieve import *
|
|
from app.service.attribute.config import const
|
|
from app.service.attribute.service_att_recognition import AttributeRecognition
|
|
from app.service.attribute.service_category_recognition import CategoryRecognition
|
|
|
|
router = APIRouter()
|
|
logger = logging.getLogger()
|
|
|
|
|
|
# 属性识别
|
|
@router.post("/attribute_recognition")
|
|
def attribute_recognition(request_item: list[AttributeRecognitionModel]):
|
|
try:
|
|
service = AttributeRecognition(const=const, request_data=request_item)
|
|
data = service.get_result()
|
|
code = 200
|
|
message = "OK!"
|
|
logger.info(f"attribute_recognition response @@@@@@:{json.dumps(data, indent=4)}")
|
|
except Exception as e:
|
|
code = 400
|
|
message = e
|
|
data = e
|
|
logger.warning(f"attribute_recognition Run Exception @@@@@@:{e}")
|
|
return {"code": code, "msg": message, "data": data}
|
|
|
|
|
|
# 类别识别
|
|
@router.post("/category_recognition")
|
|
def category_recognition(request_item: list[CategoryRecognitionModel]):
|
|
try:
|
|
service = CategoryRecognition(request_data=request_item)
|
|
data = service.get_result()
|
|
code = 200
|
|
message = "OK!"
|
|
logger.info(f"category_recognition response @@@@@@:{json.dumps(data, indent=4)}")
|
|
except Exception as e:
|
|
code = 400
|
|
message = e
|
|
data = e
|
|
logger.warning(f"category_recognition Run Exception @@@@@@:{e}")
|
|
return {"code": code, "msg": message, "data": data}
|