From 373a360e76bbc0d253df530a4cf8a34558c1f353 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 3 Jul 2025 14:20:33 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:FLUX=E7=AB=A5=E8=A3=85prompt=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=9B=E8=8E=B7=E5=8F=96video=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E4=BC=A0=E5=85=A5list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/controller/GenerateController.java | 6 +- .../com/ai/da/service/GenerateService.java | 4 +- .../da/service/impl/GenerateServiceImpl.java | 58 +++++++++++-------- .../impl/UserLikeGroupServiceImpl.java | 19 +++--- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/ai/da/controller/GenerateController.java b/src/main/java/com/ai/da/controller/GenerateController.java index 9ead554e..e2d4e6f4 100644 --- a/src/main/java/com/ai/da/controller/GenerateController.java +++ b/src/main/java/com/ai/da/controller/GenerateController.java @@ -107,8 +107,8 @@ public class GenerateController { @ApiOperation(value = "获取姿势变换生成结果") @PostMapping("/poseTransformResult") - public Response getPoseTransformationResults(@Valid @RequestBody Map taskId) { - PoseTransformationVO generateResult = generateService.getPoseTransformationResult(taskId.get("taskId")); + public Response> getPoseTransformationResults(@Valid @RequestBody List taskIdList) { + List generateResult = generateService.getPoseTransformationResult(taskIdList); return Response.success(generateResult); } @@ -203,7 +203,7 @@ public class GenerateController { typeEnum = CreditsEventsEnum.IMAGE_TO_SKETCH; break; } - return Response.success(generateService.flux(typeEnum, prompt, path)); + return Response.success(generateService.flux(typeEnum, prompt, path, false)); } // @ApiOperation(value = "获取flux结果") diff --git a/src/main/java/com/ai/da/service/GenerateService.java b/src/main/java/com/ai/da/service/GenerateService.java index f95dd2a5..5ae76366 100644 --- a/src/main/java/com/ai/da/service/GenerateService.java +++ b/src/main/java/com/ai/da/service/GenerateService.java @@ -53,7 +53,7 @@ public interface GenerateService extends IService { void processPoseTransformResult(String taskId, String gifUrl, String videoUrl, String imageUrl); - PoseTransformationVO getPoseTransformationResult(String taskId); + List getPoseTransformationResult(List taskIdList); List getPoseTransformationResultList(Long projectId, boolean like); @@ -83,7 +83,7 @@ public interface GenerateService extends IService { String getImageDescription(String imagePath); - String flux(CreditsEventsEnum func, String prompt, String imagePath); + String flux(CreditsEventsEnum func, String prompt, String imagePath, boolean childStyle); String getFluxResult(String taskId, String objectName); diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index d701362f..afc66e9a 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -1012,7 +1012,7 @@ public class GenerateServiceImpl extends ServiceImpl i }else { imagePath = collagePictureUrl; } - taskId = flux(event, null, imagePath); + taskId = flux(event, null, imagePath, false); // 存数据库 saveExtractSketchRequest(imageToSketchDTO, collagePictureUrl, projectId, accountId, imageToSketchDTO.getStyle(), "flux", taskId); @@ -1158,6 +1158,7 @@ public class GenerateServiceImpl extends ServiceImpl i poseTransformation.setUniqueId(taskId); poseTransformation.setProductImage(productImage); poseTransformation.setPoseId(poseId); + poseTransformation.setIsLiked((byte)1); poseTransformation.setCreateTime(LocalDateTime.now()); poseTransformationMapper.insert(poseTransformation); @@ -1210,30 +1211,34 @@ public class GenerateServiceImpl extends ServiceImpl i if (flag) creditsService.updateChangedCredits(accountId, taskId); } - public PoseTransformationVO getPoseTransformationResult(String taskId){ - String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue()); - if (type.equals("wx")){ - return getAnimateResult(taskId); - } - String key = generateResultKey + ":" + taskId; - String resultJson = redisUtil.getFromString(key); - - if (!StringUtil.isNullOrEmpty(resultJson)){ - PoseTransformationVO poseTransformationVO = new Gson().fromJson(redisUtil.getFromString(key), PoseTransformationVO.class); - if (poseTransformationVO.getStatus().equals("Success")){ - // 处理各种URL - processUrl(poseTransformationVO.getGifUrl(), url -> - poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); - processUrl(poseTransformationVO.getVideoUrl(), url -> - poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); - processUrl(poseTransformationVO.getFirstFrameUrl(), url -> - poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + public List getPoseTransformationResult(List taskIdList){ + ArrayList poseTransformationVOS = new ArrayList<>(); + for (String taskId : taskIdList){ + String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue()); + if (type.equals("wx")){ + poseTransformationVOS.add(getAnimateResult(taskId)); + } + String key = generateResultKey + ":" + taskId; + String resultJson = redisUtil.getFromString(key); + + if (!StringUtil.isNullOrEmpty(resultJson)){ + PoseTransformationVO poseTransformationVO = new Gson().fromJson(redisUtil.getFromString(key), PoseTransformationVO.class); + if (poseTransformationVO.getStatus().equals("Success")){ + // 处理各种URL + processUrl(poseTransformationVO.getGifUrl(), url -> + poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getVideoUrl(), url -> + poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getFirstFrameUrl(), url -> + poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + } + poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); + poseTransformationVOS.add(poseTransformationVO); + }else { + poseTransformationVOS.add(new PoseTransformationVO(taskId, "Executing")); } - poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); - return poseTransformationVO; - }else { - return new PoseTransformationVO(taskId, "Executing"); } + return poseTransformationVOS; } public List getPoseTransformationResultList(Long projectId, boolean like){ @@ -2131,7 +2136,7 @@ public class GenerateServiceImpl extends ServiceImpl i * @param imagePath 图片minio路径 * @return 返回taskId,用于异步获取结果 */ - public String flux(CreditsEventsEnum func, String prompt, String imagePath){ + public String flux(CreditsEventsEnum func, String prompt, String imagePath, boolean childStyle){ String fluxRequestUrl = "https://api.bfl.ai/v1/flux-kontext-pro"; if (StringUtil.isNullOrEmpty(prompt)){ switch (func){ @@ -2143,6 +2148,7 @@ public class GenerateServiceImpl extends ServiceImpl i break; case TO_PRODUCT_IMAGE_FLUX: prompt = "change the image to real style, ultra high quality, 8k"; + if (childStyle) prompt = prompt + ", Children's face"; break; } } @@ -2150,9 +2156,10 @@ public class GenerateServiceImpl extends ServiceImpl i requestBody.set("prompt", prompt); requestBody.set("seed", 42); -// requestBody.set("aspect_ratio", "9:16"); + requestBody.set("aspect_ratio", "9:16"); requestBody.set("output_format", "png"); + log.info("flux 请求入参:{}", requestBody); if (!StringUtil.isNullOrEmpty(imagePath)){ try { String imageAsBase64 = null; @@ -2170,6 +2177,7 @@ public class GenerateServiceImpl extends ServiceImpl i } String resp = sendRequestUtil.sendFluxPost(fluxRequestUrl, requestBody.toString()); +// JSONObject respObj = JSONUtil.parseObj(null); JSONObject respObj = JSONUtil.parseObj(resp); log.info("flux 发起生成请求返回结果: {}", respObj); String taskId = respObj.getStr("id"); diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 8e2c27af..d1a1fc3c 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -458,7 +458,10 @@ public class UserLikeGroupServiceImpl extends ServiceImpl