BUGFIX:FLUX童装prompt修改;获取video结果允许传入list

This commit is contained in:
2025-07-03 14:20:33 +08:00
parent f541bee0e7
commit 373a360e76
4 changed files with 49 additions and 38 deletions

View File

@@ -53,7 +53,7 @@ public interface GenerateService extends IService<Generate> {
void processPoseTransformResult(String taskId, String gifUrl, String videoUrl, String imageUrl);
PoseTransformationVO getPoseTransformationResult(String taskId);
List<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList);
List<PoseTransformationVO> getPoseTransformationResultList(Long projectId, boolean like);
@@ -83,7 +83,7 @@ public interface GenerateService extends IService<Generate> {
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);

View File

@@ -1012,7 +1012,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList){
ArrayList<PoseTransformationVO> 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<PoseTransformationVO> getPoseTransformationResultList(Long projectId, boolean like){
@@ -2131,7 +2136,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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");

View File

@@ -458,7 +458,10 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
ToProductImageResult toProductImageResult = new ToProductImageResult();
if (fluxTask){
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl());
if (childFlag){
sb.append(", Children's face");
}
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl(), childFlag);
toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("ToProductImage");
} else {
@@ -475,7 +478,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setCreateTime(LocalDateTime.now());
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setIsLike(1);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setProjectId(projectId);
if (userLikeGroupId != null) {
@@ -497,7 +500,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductImageResult toProductImageResult = new ToProductImageResult();
if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl());
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag);
toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("ToProductImage");
} else {
@@ -514,7 +517,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setCreateTime(LocalDateTime.now());
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setIsLike(1);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setProjectId(projectId);
if (userLikeGroupId != null) {
@@ -1045,7 +1048,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductImageResult toProductImageResult = new ToProductImageResult();
if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, s, toProductImageResult1.getUrl());
taskId = generateService.flux(creditsEventsEnum, s, toProductImageResult1.getUrl(), false);
toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("Relight");
} else {
@@ -1057,7 +1060,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setCreateTime(LocalDateTime.now());
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setIsLike(1);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setProjectId(projectId);
if (null != userLikeGroupId) {
@@ -1074,7 +1077,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
ToProductImageResult toProductImageResult = new ToProductImageResult();
if (fluxTask){
taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductElement.getUrl());
taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductElement.getUrl(), false);
toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("Relight");
} else {
@@ -1086,7 +1089,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setCreateTime(LocalDateTime.now());
toProductImageResult.setToProductImageRecordId(toProductImageRecord.getId());
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setIsLike(1);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setProjectId(projectId);
if (null != userLikeGroupId) {