2024-03-21 11:12:01 +08:00
|
|
|
|
import json
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from fastapi import APIRouter, BackgroundTasks, HTTPException
|
2024-03-20 11:44:15 +08:00
|
|
|
|
|
2024-06-13 14:31:14 +08:00
|
|
|
|
from app.schemas.response_template import ResponseModel
|
2024-03-20 11:44:15 +08:00
|
|
|
|
from app.schemas.super_resolution import SuperResolutionModel
|
2024-03-21 11:12:01 +08:00
|
|
|
|
from app.service.super_resolution.service import SuperResolution, infer_cancel
|
2024-03-20 11:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
2024-03-21 11:12:01 +08:00
|
|
|
|
logger = logging.getLogger()
|
2024-03-20 11:44:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-03-21 11:27:37 +08:00
|
|
|
|
@router.post("/super_resolution")
|
2024-03-21 11:12:01 +08:00
|
|
|
|
def super_resolution(request_item: SuperResolutionModel, background_tasks: BackgroundTasks):
|
2024-06-25 16:58:17 +08:00
|
|
|
|
"""
|
|
|
|
|
|
创建一个具有以下参数的请求体:
|
|
|
|
|
|
- **sr_image_url**: 超分图片的minio或s3 url地址
|
|
|
|
|
|
- **sr_xn**: 超分的倍数,只接受2或4
|
|
|
|
|
|
- **sr_tasks_id**: 任务id 用于取消超分任务和获取超分结果
|
|
|
|
|
|
|
|
|
|
|
|
示例参数:
|
|
|
|
|
|
{
|
|
|
|
|
|
"sr_image_url": "aida-sys-image/images/female/blouse/0628000098.jpg",
|
|
|
|
|
|
"sr_xn": 2,
|
|
|
|
|
|
"sr_tasks_id": "12341556-89"
|
|
|
|
|
|
}
|
|
|
|
|
|
"""
|
2024-03-21 11:12:01 +08:00
|
|
|
|
try:
|
2024-07-04 14:14:57 +08:00
|
|
|
|
logger.info(f"super_resolution request item is : @@@@@@:{json.dumps(request_item.dict())}")
|
2024-03-21 11:12:01 +08:00
|
|
|
|
service = SuperResolution(request_item)
|
|
|
|
|
|
background_tasks.add_task(service.sr_result)
|
|
|
|
|
|
except Exception as e:
|
2024-06-13 14:31:14 +08:00
|
|
|
|
logger.warning(f"super_resolution Run Exception @@@@@@:{e}")
|
|
|
|
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
|
|
|
|
return ResponseModel()
|
2024-03-21 11:12:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-03-21 11:27:37 +08:00
|
|
|
|
@router.get("/sr_cancel/{tasks_id}>")
|
2024-06-14 14:52:48 +08:00
|
|
|
|
def super_resolution(tasks_id: str):
|
2024-06-13 14:31:14 +08:00
|
|
|
|
try:
|
|
|
|
|
|
logger.info(f"sr_cancel request item is : @@@@@@:{tasks_id}")
|
|
|
|
|
|
data = infer_cancel(tasks_id)
|
2024-07-04 14:14:57 +08:00
|
|
|
|
logger.info(f"sr_cancel response @@@@@@:{data}")
|
2024-06-13 14:31:14 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(f"sr_cancel Run Exception @@@@@@:{e}")
|
|
|
|
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
|
|
|
|
return ResponseModel(data=data['data'])
|