Files
AiDA_Python/app/api/api_sketch_to_garment.py
zcr c73bfa7e2a
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped
3D 打板部署
2026-04-28 17:03:04 +08:00

105 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import json
import logging
from fastapi import APIRouter, HTTPException
from app.schemas.response_template import ResponseModel
from app.schemas.sketch_to_garment_schemas import SketchToGarmentModel
from app.service.sketch2garment.server import submit_sketch_to_garment_task
logger = logging.getLogger()
router = APIRouter()
@router.post("/sketch_to_garment")
def sketch_to_garment_api(request_item: SketchToGarmentModel):
"""
### 接口说明:
将图片转换为3D模型异步处理。接口接收请求后立即返回任务ID后台通过 Celery 处理,处理完成后结果会通过 RabbitMQ 发送。
### 参数说明:
- **input_image_path**: 输入图片路径
- **bucket_name**: bucket name
- **user_id**: 用户id
- **callback_url**: 回调url
- **task_id**: 任务id
- **model**: 转换模式 文本和图片 ,默认只有图片
### 请求体示例:
**单张图片模式:**
```json
{
"input_image_path": "test/53d38bd5-f77b-4034-ada2-45f1e2ebe00c.png",
"bucket_name": "test",
"user_id": "string-456",
"callback_url": "http://18.167.251.121:10015/api/image/webhook/img-to-3d",
"task_id": "string12",
"model": "picture"
}
```
### 输出示例:
```json
{
"code": 200,
"msg": "OK!",
"data": {
"state": "success",
"task_id": "string12",
"message": "任务已成功提交,正在后台处理..."
}
}
```
### 错误输出
参考文档: https://platform.tripo3d.ai/docs/error-handling
```json
{
"code": 500,
"message": "You dont have enough credit to create this task",
"data": {
"status": "fail",
"task_id": "123",
"message": "You dont have enough credit to create this task",
"error": str(e)
}
}
```
回调请求参数例子:
```json
{
"task_id": "string12",
"status": "success",
"result": {
"pattern": "test/string-456/pattern_making/now_string-456_pattern.png",
"texture": "test/string-456/pattern_making/now_string-456_texture.png",
"glb": "test/string-456/pattern_making/now_string-456_sim.glb",
"texture_fabric": "test/string-456/pattern_making/now_string-456_texture_fabric.png"
}
}
```
"""
try:
logger.info(f"sketch_to_garment request item is : @@@@@@:{json.dumps(request_item.model_dump(), indent=4)}")
result = submit_sketch_to_garment_task(
task_id=request_item.task_id,
callback_url=request_item.callback_url,
bucket_name=request_item.bucket_name,
input_image_path=request_item.input_image_path,
user_id=request_item.user_id,
model=request_item.model
)
result = {
"state": "success",
"task_id": request_item.task_id,
"message": "任务已成功提交,正在后台处理...",
}
state_code = 200
return ResponseModel(data=result, code=state_code)
except Exception as e:
logger.warning(f"super_resolution Run Exception @@@@@@:{e}")
raise HTTPException(status_code=404, detail=str(e))