2024-04-16 15:51:03 +08:00
|
|
|
|
import json
|
|
|
|
|
|
import logging
|
2024-06-25 16:58:17 +08:00
|
|
|
|
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from fastapi import APIRouter, HTTPException
|
2024-06-17 17:14:10 +08:00
|
|
|
|
|
|
|
|
|
|
from app.core.config import DEBUG
|
2024-04-16 15:51:03 +08:00
|
|
|
|
from app.schemas.attribute_retrieve import *
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from app.schemas.response_template import ResponseModel
|
2024-06-17 17:14:10 +08:00
|
|
|
|
from app.service.attribute.config import const, local_debug_const
|
2024-04-16 15:51:03 +08:00
|
|
|
|
from app.service.attribute.service_att_recognition import AttributeRecognition
|
|
|
|
|
|
from app.service.attribute.service_category_recognition import CategoryRecognition
|
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 属性识别
|
2024-06-13 14:31:14 +08:00
|
|
|
|
@router.post("/attribute_recognition", response_model=ResponseModel)
|
2024-04-16 15:51:03 +08:00
|
|
|
|
def attribute_recognition(request_item: list[AttributeRecognitionModel]):
|
2024-06-25 16:58:17 +08:00
|
|
|
|
"""
|
|
|
|
|
|
获取sketch的属性,collar sleeve_length 等等
|
|
|
|
|
|
创建一个具有以下参数的请求体:
|
|
|
|
|
|
- **category**: sketch的类别 ,Dress
|
|
|
|
|
|
- **colony**: 服装类别,男装或女装
|
|
|
|
|
|
- **sketch_img_url**: 被提取属性的S3或minio url地址
|
|
|
|
|
|
|
|
|
|
|
|
示例参数:
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"category": "Dress",
|
|
|
|
|
|
"colony": "Female",
|
|
|
|
|
|
"sketch_img_url": "aida-users/89/sketchboard/female/Dress/ae976103-d7ec-4eed-b5d1-3e5f04d8be26.jpg"
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
"""
|
2024-04-16 15:51:03 +08:00
|
|
|
|
try:
|
2024-06-13 14:31:14 +08:00
|
|
|
|
logger.info(f"attribute_recognition request item is : @@@@@@:{request_item}")
|
2024-06-17 17:14:10 +08:00
|
|
|
|
if DEBUG:
|
|
|
|
|
|
service = AttributeRecognition(const=local_debug_const, request_data=request_item)
|
|
|
|
|
|
else:
|
|
|
|
|
|
service = AttributeRecognition(const=const, request_data=request_item)
|
2024-04-16 15:51:03 +08:00
|
|
|
|
data = service.get_result()
|
|
|
|
|
|
logger.info(f"attribute_recognition response @@@@@@:{json.dumps(data, indent=4)}")
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"attribute_recognition Run Exception @@@@@@:{e}")
|
2024-06-13 14:31:14 +08:00
|
|
|
|
raise HTTPException(status_code=404, detail=str(e))
|
2024-06-17 17:14:10 +08:00
|
|
|
|
return ResponseModel(data={"list": data})
|
2024-04-16 15:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 类别识别
|
|
|
|
|
|
@router.post("/category_recognition")
|
|
|
|
|
|
def category_recognition(request_item: list[CategoryRecognitionModel]):
|
2024-06-25 16:58:17 +08:00
|
|
|
|
"""
|
|
|
|
|
|
获取sketch的类别,dress blouse 等等
|
|
|
|
|
|
创建一个具有以下参数的请求体:
|
|
|
|
|
|
- **colony**: 服装类别,male或Female
|
|
|
|
|
|
- **sketch_img_url**: 被提取sketch类别的S3或minio url地址
|
|
|
|
|
|
|
|
|
|
|
|
示例参数:
|
|
|
|
|
|
[
|
|
|
|
|
|
{
|
|
|
|
|
|
"colony": "Female",
|
|
|
|
|
|
"sketch_img_url": "aida-users/89/sketchboard/female/Dress/ae976103-d7ec-4eed-b5d1-3e5f04d8be26.jpg"
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
"""
|
2024-04-16 15:51:03 +08:00
|
|
|
|
try:
|
2024-06-13 14:31:14 +08:00
|
|
|
|
logger.info(f"category_recognition request item is : @@@@@@:{request_item}")
|
2024-04-16 15:51:03 +08:00
|
|
|
|
service = CategoryRecognition(request_data=request_item)
|
|
|
|
|
|
data = service.get_result()
|
|
|
|
|
|
logger.info(f"category_recognition response @@@@@@:{json.dumps(data, indent=4)}")
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"category_recognition Run Exception @@@@@@:{e}")
|
2024-06-13 14:31:14 +08:00
|
|
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
|
|
|
|
return ResponseModel(data=data)
|