BUGFIX:1、积分消耗值不准确 2、flux获取结果报错
This commit is contained in:
@@ -38,9 +38,12 @@ public enum CreditsEventsEnum {
|
|||||||
MOOD_BOARD("MoodBoard","5"),
|
MOOD_BOARD("MoodBoard","5"),
|
||||||
SKETCH_BOARD("SketchBoard","5"),
|
SKETCH_BOARD("SketchBoard","5"),
|
||||||
TO_PRODUCT_IMAGE("ToProductImage","5"),
|
TO_PRODUCT_IMAGE("ToProductImage","5"),
|
||||||
|
TO_PRODUCT_IMAGE_FLUX("ToProductImageFlux","10"),
|
||||||
RELIGHT("Relight","5"),
|
RELIGHT("Relight","5"),
|
||||||
|
RELIGHT_FLUX("RelightFlux","10"),
|
||||||
QUESTIONNAIRE("Questionnaire","100"),
|
QUESTIONNAIRE("Questionnaire","100"),
|
||||||
IMAGE_TO_SKETCH("ImageToSketch","5"),
|
IMAGE_TO_SKETCH("ImageToSketch","5"),
|
||||||
|
IMAGE_TO_SKETCH_FLUX("ImageToSketchFlux","10"),
|
||||||
POSE_TRANSFORMATION("PoseTransformation","10"),
|
POSE_TRANSFORMATION("PoseTransformation","10"),
|
||||||
OTHER("Other","5"),
|
OTHER("Other","5"),
|
||||||
|
|
||||||
@@ -53,7 +56,6 @@ public enum CreditsEventsEnum {
|
|||||||
LOCAL_IMG2IMG("Local_img2img","1.25"),
|
LOCAL_IMG2IMG("Local_img2img","1.25"),
|
||||||
LOCAL_TEXT2IMG_HIGH("Local_text2img_high","5"),
|
LOCAL_TEXT2IMG_HIGH("Local_text2img_high","5"),
|
||||||
LOCAL_IMG2IMG_HIGH("Local_img2img_high","5"),
|
LOCAL_IMG2IMG_HIGH("Local_img2img_high","5"),
|
||||||
LOCAL_SLOGAN("Local_Slogan","10"),
|
|
||||||
LOCAL_ANIMATION("Local_Animation","15"),
|
LOCAL_ANIMATION("Local_Animation","15"),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class RedisUtil {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, String> redisTemplate;
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
|
|
||||||
|
public final static String FLUX_POLLING_URL = "Flux:";
|
||||||
|
|
||||||
public Boolean hasKey(String key){
|
public Boolean hasKey(String key){
|
||||||
return redisTemplate.hasKey(key);
|
return redisTemplate.hasKey(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class SendRequestUtil {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.warn("请求失败,状态码为 : {}, body: {}", status, body);
|
log.warn("请求失败,状态码为 : {}", status);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,9 @@ public class PoseTransformationVO implements AllCollectionVO{
|
|||||||
this.isLiked = isLiked;
|
this.isLiked = isLiked;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PoseTransformationVO(String taskId, String status) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -992,7 +992,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
|
|
||||||
// 检查积分是否够本次扣除
|
// 检查积分是否够本次扣除
|
||||||
// CreditsEventsEnum event = CreditsEventsEnum.IMAGE_TO_SKETCH;
|
// CreditsEventsEnum event = CreditsEventsEnum.IMAGE_TO_SKETCH;
|
||||||
CreditsEventsEnum event = CreditsEventsEnum.FLUX_IMG2IMG;
|
CreditsEventsEnum event = CreditsEventsEnum.IMAGE_TO_SKETCH_FLUX;
|
||||||
Boolean b = creditsService.checkCredits(accountId, event, 1);
|
Boolean b = creditsService.checkCredits(accountId, event, 1);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
throw new BusinessException("remaining.credits.insufficient", ResultEnum.PROMPT.getCode());
|
throw new BusinessException("remaining.credits.insufficient", ResultEnum.PROMPT.getCode());
|
||||||
@@ -1232,7 +1232,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue());
|
poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue());
|
||||||
return poseTransformationVO;
|
return poseTransformationVO;
|
||||||
}else {
|
}else {
|
||||||
return new PoseTransformationVO();
|
return new PoseTransformationVO(taskId, "Executing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2099,13 +2099,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
String fluxRequestUrl = "https://api.bfl.ai/v1/flux-kontext-pro";
|
String fluxRequestUrl = "https://api.bfl.ai/v1/flux-kontext-pro";
|
||||||
if (StringUtil.isNullOrEmpty(prompt)){
|
if (StringUtil.isNullOrEmpty(prompt)){
|
||||||
switch (func){
|
switch (func){
|
||||||
case RELIGHT:
|
case RELIGHT_FLUX:
|
||||||
prompt = "a model standing on the beautiful beach, ultra high quality, 8k";
|
prompt = "a model standing on the beautiful beach, ultra high quality, 8k";
|
||||||
break;
|
break;
|
||||||
case IMAGE_TO_SKETCH:
|
case IMAGE_TO_SKETCH_FLUX:
|
||||||
prompt = "generate the sketch of the image, simple line, ultra high quality";
|
prompt = "generate the sketch of the image, simple line, ultra high quality";
|
||||||
break;
|
break;
|
||||||
case TO_PRODUCT_IMAGE:
|
case TO_PRODUCT_IMAGE_FLUX:
|
||||||
prompt = "change the image to real style, ultra high quality, 8k";
|
prompt = "change the image to real style, ultra high quality, 8k";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2130,16 +2130,29 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
String resp = sendRequestUtil.sendFluxPost(fluxRequestUrl, requestBody.toString());
|
String resp = sendRequestUtil.sendFluxPost(fluxRequestUrl, requestBody.toString());
|
||||||
JSONObject respObj = JSONUtil.parseObj(resp);
|
JSONObject respObj = JSONUtil.parseObj(resp);
|
||||||
log.info("flux 发起生成请求返回结果: {}", respObj);
|
log.info("flux 发起生成请求返回结果: {}", respObj);
|
||||||
if (StringUtil.isNullOrEmpty(respObj.getStr("id"))){
|
String taskId = respObj.getStr("id");
|
||||||
|
if (StringUtil.isNullOrEmpty(taskId)){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return respObj.getStr("id");
|
|
||||||
|
String pollingUrl = respObj.getStr("polling_url");
|
||||||
|
String key = RedisUtil.FLUX_POLLING_URL + taskId;
|
||||||
|
redisUtil.addToString(key, pollingUrl, CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||||
|
|
||||||
|
return taskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFluxResult(String taskId, String objectName){
|
public String getFluxResult(String taskId, String objectName){
|
||||||
String fluxResultRequestUrl = "https://api.bfl.ai/v1/get_result";
|
String pollingUrl = redisUtil.getFromString(RedisUtil.FLUX_POLLING_URL + taskId);
|
||||||
|
String fluxResultRequestUrl;
|
||||||
HashMap<String, Object> params = new HashMap<>();
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
|
if (StringUtil.isNullOrEmpty(pollingUrl)){
|
||||||
|
fluxResultRequestUrl = "https://api.bfl.ai/v1/get_result";
|
||||||
params.put("id", taskId);
|
params.put("id", taskId);
|
||||||
|
} else {
|
||||||
|
fluxResultRequestUrl = pollingUrl;
|
||||||
|
}
|
||||||
|
|
||||||
String resp = sendRequestUtil.sendGet(fluxResultRequestUrl, params);
|
String resp = sendRequestUtil.sendGet(fluxResultRequestUrl, params);
|
||||||
log.info("获取flux生成的结果为:{}", resp);
|
log.info("获取flux生成的结果为:{}", resp);
|
||||||
JSONObject respObj = JSONUtil.parseObj(resp);
|
JSONObject respObj = JSONUtil.parseObj(resp);
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
// 判断用户当前积分是否够本次生成消耗
|
// 判断用户当前积分是否够本次生成消耗
|
||||||
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
||||||
&& toProductImageDTO.getModelName().equals("flux");
|
&& toProductImageDTO.getModelName().equals("flux");
|
||||||
CreditsEventsEnum creditsEventsEnum = fluxTask ? CreditsEventsEnum.FLUX_IMG2IMG : CreditsEventsEnum.TO_PRODUCT_IMAGE;
|
CreditsEventsEnum creditsEventsEnum = fluxTask ? CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX : CreditsEventsEnum.TO_PRODUCT_IMAGE;
|
||||||
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, toProductImageDTO.getToProductImageVOList().size());
|
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, toProductImageDTO.getToProductImageVOList().size());
|
||||||
if (!preDeduction) {
|
if (!preDeduction) {
|
||||||
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||||
@@ -458,7 +458,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
}
|
}
|
||||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||||
if (fluxTask){
|
if (fluxTask){
|
||||||
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE, sb.toString(), tDesignPythonOutfit.getDesignUrl());
|
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl());
|
||||||
toProductImageResult.setModelName("flux");
|
toProductImageResult.setModelName("flux");
|
||||||
toProductImageResult.setResultType("ToProductImage");
|
toProductImageResult.setResultType("ToProductImage");
|
||||||
} else {
|
} else {
|
||||||
@@ -719,7 +719,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Objects.isNull(magicToolResultVO)) {
|
} else if (Objects.isNull(magicToolResultVO)) {
|
||||||
magicToolResultVO = new MagicToolResultVO();
|
magicToolResultVO = new MagicToolResultVO(taskId, "Executing");
|
||||||
}
|
}
|
||||||
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
|
||||||
results.add(magicToolResultVO);
|
results.add(magicToolResultVO);
|
||||||
@@ -973,7 +973,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
// 判断用户当前积分是否够本次生成消耗
|
// 判断用户当前积分是否够本次生成消耗
|
||||||
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
||||||
&& toProductImageDTO.getModelName().equals("flux");
|
&& toProductImageDTO.getModelName().equals("flux");
|
||||||
CreditsEventsEnum creditsEventsEnum = fluxTask ? CreditsEventsEnum.FLUX_IMG2IMG : CreditsEventsEnum.RELIGHT;
|
CreditsEventsEnum creditsEventsEnum = fluxTask ? CreditsEventsEnum.RELIGHT_FLUX : CreditsEventsEnum.RELIGHT;
|
||||||
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, toProductImageDTO.getToProductImageVOList().size());
|
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, toProductImageDTO.getToProductImageVOList().size());
|
||||||
if (!preDeduction) {
|
if (!preDeduction) {
|
||||||
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
|
||||||
@@ -1032,7 +1032,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
|
|
||||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||||
if (fluxTask){
|
if (fluxTask){
|
||||||
taskId = generateService.flux(CreditsEventsEnum.RELIGHT, s, toProductImageResult1.getUrl());
|
taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductImageResult1.getUrl());
|
||||||
toProductImageResult.setModelName("flux");
|
toProductImageResult.setModelName("flux");
|
||||||
toProductImageResult.setResultType("Relight");
|
toProductImageResult.setResultType("Relight");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user