generate 添加Logo与Slogan

This commit is contained in:
2024-06-03 17:13:48 +08:00
parent 86e7119cfb
commit 49b086ad10
10 changed files with 261 additions and 102 deletions

View File

@@ -67,7 +67,11 @@ public class GenerateConsumer {
// redisUtil.removeFromSet(cancelSetKey, uniqueId); // redisUtil.removeFromSet(cancelSetKey, uniqueId);
} else { } else {
// GenerateCollectionVO generateCollectionVO = generateService.generateThroughImageText(generateThroughImageTextDTO); // GenerateCollectionVO generateCollectionVO = generateService.generateThroughImageText(generateThroughImageTextDTO);
generateService.generateThroughImageText(generateThroughImageTextDTO); try {
generateService.generateThroughImageText(generateThroughImageTextDTO);
}catch (Exception e){
log.error(e.getMessage());
}
// 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除 // 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除
redisUtil.removeFromZSet(consumptionOrderKey, uniqueId); redisUtil.removeFromZSet(consumptionOrderKey, uniqueId);
/*if (!Objects.isNull(generateCollectionVO)) { /*if (!Objects.isNull(generateCollectionVO)) {
@@ -154,63 +158,63 @@ public class GenerateConsumer {
} }
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer1(Message msg, Channel channel) { public void generateConsumer1(Message msg, Channel channel) {
// generate(msg, channel, "consumer 1"); generate(msg, channel, "consumer 1");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer2(Message msg, Channel channel) { public void generateConsumer2(Message msg, Channel channel) {
// generate(msg, channel, "consumer 2"); generate(msg, channel, "consumer 2");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer3(Message msg, Channel channel) { public void generateConsumer3(Message msg, Channel channel) {
// generate(msg, channel, "consumer 3"); generate(msg, channel, "consumer 3");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer4(Message msg, Channel channel) { public void generateConsumer4(Message msg, Channel channel) {
// generate(msg, channel, "consumer 4"); generate(msg, channel, "consumer 4");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer5(Message msg, Channel channel) { public void generateConsumer5(Message msg, Channel channel) {
// generate(msg, channel, "consumer 5"); generate(msg, channel, "consumer 5");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer6(Message msg, Channel channel) { public void generateConsumer6(Message msg, Channel channel) {
// generate(msg, channel, "consumer 6"); generate(msg, channel, "consumer 6");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer7(Message msg, Channel channel) { public void generateConsumer7(Message msg, Channel channel) {
// generate(msg, channel, "consumer 7"); generate(msg, channel, "consumer 7");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer8(Message msg, Channel channel) { public void generateConsumer8(Message msg, Channel channel) {
// generate(msg, channel, "consumer 8"); generate(msg, channel, "consumer 8");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_QUEUE)
// @RabbitHandler @RabbitHandler
// public void generateConsumer9(Message msg, Channel channel) { public void generateConsumer9(Message msg, Channel channel) {
// generate(msg, channel, "consumer 9"); generate(msg, channel, "consumer 9");
// } }
//
// @RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE) @RabbitListener(queues = MQConfig.GENERATE_RESULT_QUEUE)
// @RabbitHandler @RabbitHandler
// public void getGenerateResult(Message msg, Channel channel) { public void getGenerateResult(Message msg, Channel channel) {
// processGenerateResult(msg, channel); processGenerateResult(msg, channel);
// } }
} }

View File

@@ -17,4 +17,10 @@ public class CommonConstant {
public static final Integer NUMBER_10080 = 10080; public static final Integer NUMBER_10080 = 10080;
} }
public static final String GENERATE_PATH = "/api/generate_image";
public static final String GENERATE_SINGLE_LOGO = "/api/generate_single_logo";
public static final String GENERATE_SLOGAN = "/api/slogan";
} }

View File

@@ -1,5 +1,7 @@
package com.ai.da.common.enums; package com.ai.da.common.enums;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@@ -36,7 +38,18 @@ public enum CollectionLevel2TypeEnum {
* 男装下装 * 男装下装
*/ */
BOTTOMS("Bottoms"), BOTTOMS("Bottoms"),
; /**
* 印花-logo
*/
LOGO("Logo"),
/**
* 印花-slogan
*/
SLOGAN("Slogan"),
/**
* 印花-图案
*/
Pattern("Pattern");
private String realName; private String realName;
@@ -51,4 +64,8 @@ public enum CollectionLevel2TypeEnum {
public static CollectionLevel2TypeEnum of(String realName) { public static CollectionLevel2TypeEnum of(String realName) {
return Stream.of(CollectionLevel2TypeEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null); return Stream.of(CollectionLevel2TypeEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
} }
public static List<String> printType() {
return Arrays.asList(LOGO.getRealName(), SLOGAN.getRealName(), Pattern.getRealName());
}
} }

View File

@@ -27,11 +27,11 @@ public class GenerateController {
@Resource @Resource
private GenerateService generateService; private GenerateService generateService;
@ApiOperation("自动识别sketch的caption 暂时未上") /*@ApiOperation("自动识别sketch的caption 暂时未上")
@PostMapping("/caption") @PostMapping("/caption")
public Response<GenerateCaptionVO> generateCaption(@RequestParam Long sketchElementId) { public Response<GenerateCaptionVO> generateCaption(@RequestParam Long sketchElementId) {
return Response.success(generateService.generateCaption(sketchElementId)); return Response.success(generateService.generateCaption(sketchElementId));
} }*/
/*@ApiOperation("通过文字、图片生成图片") /*@ApiOperation("通过文字、图片生成图片")
@PostMapping("/sketchAndPrint") @PostMapping("/sketchAndPrint")

View File

@@ -33,10 +33,15 @@ public class Generate {
private String uniqueId; private String uniqueId;
/** /**
* Sketchboard Printboard * Sketchboard Printboard Moodboard
*/ */
private String level1Type; private String level1Type;
/**
* Slogan Logo Pattern
*/
private String level2Type;
/** /**
* 图片来源 collection | library * 图片来源 collection | library
*/ */
@@ -62,6 +67,11 @@ public class Generate {
*/ */
private String modelName; private String modelName;
/**
* Logo 种子 相同种子 相同prompt 输出一定相同
*/
private String seed;
/** /**
* 创建时间 * 创建时间
*/ */

View File

@@ -14,24 +14,25 @@ public class GenerateThroughImageTextDTO {
@ApiModelProperty("用户id") @ApiModelProperty("用户id")
Long userId; Long userId;
@ApiModelProperty("caption") @ApiModelProperty("caption | prompt")
String text; String text;
@ApiModelProperty("图片在t_collection_element表中的id") @ApiModelProperty("图片在t_collection_element表中的id")
Long collectionElementId; Long collectionElementId;
@NotBlank(message = "you have to choose the generate type") // todo 后续取消这个字段的传输,由后端自行判断相关参数是否有值
// @NotBlank(message = "you have to choose the generate type")
@ApiModelProperty("text image text-image") @ApiModelProperty("text image text-image")
String generateType; String generateType;
@ApiModelProperty("图片是update还是从library中选择") @ApiModelProperty("图片是update还是从library中选择 collection || library")
String designType; String designType;
@NotBlank(message = "level1Type cannot be empty!") @NotBlank(message = "level1Type cannot be empty!")
@ApiModelProperty("Moodboard Printboard Sketchboard MarketingSketch") @ApiModelProperty("Moodboard Printboard Sketchboard MarketingSketch")
String level1Type; String level1Type;
@ApiModelProperty("Outwear Dress Blouse Skirt Trousers") @ApiModelProperty("Outwear Dress Blouse Skirt Trousers || Logo Slogan Pattern")
String level2Type; String level2Type;
@ApiModelProperty("性别") @ApiModelProperty("性别")
@@ -50,4 +51,10 @@ public class GenerateThroughImageTextDTO {
@NotNull(message = "Please check if the required fields are empty.(isTestUser)") @NotNull(message = "Please check if the required fields are empty.(isTestUser)")
@ApiModelProperty("是否是测试用户") @ApiModelProperty("是否是测试用户")
Boolean isTestUser; Boolean isTestUser;
@ApiModelProperty("页面上用户设计的slogan所截的图片")
String sloganBase64;
@ApiModelProperty("种子 取值范围 0~99999")
String seed;
} }

View File

@@ -1,6 +1,5 @@
package com.ai.da.model.dto; package com.ai.da.model.dto;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -26,6 +25,10 @@ public class GenerateToPythonDTO {
// taskId的最后拼接用户id // taskId的最后拼接用户id
private String tasks_id; private String tasks_id;
private String seed;
private String svg;
public GenerateToPythonDTO(String tasks_id, String prompt, String image_url, String mode, String category, String gender) { public GenerateToPythonDTO(String tasks_id, String prompt, String image_url, String mode, String category, String gender) {
this.image_url = image_url; this.image_url = image_url;
this.category = category; this.category = category;

View File

@@ -66,7 +66,7 @@ public class PythonService {
private String accessPythonIp; private String accessPythonIp;
@Value("${access.python.port:''}") @Value("${access.python.port:''}")
private String accessPythonPort; private String accessPythonPort;
@Value("${access.python.sr}") @Value("${access.python.address}")
private String srPythonPort; private String srPythonPort;
@Value("${minio.bucketName.gradient}") @Value("${minio.bucketName.gradient}")
private String gradientBucketName; private String gradientBucketName;
@@ -2936,7 +2936,7 @@ public class PythonService {
throw new BusinessException("system error!"); throw new BusinessException("system error!");
} }
public Boolean generateSketchOrPrint(GenerateToPythonDTO generateToPythonDTO) { public Boolean generateSketchOrPrint(String params, String servicePath) {
//限流校验 //限流校验
// AccessLimitUtils.validate("generateSketchOrPrint", 5); // AccessLimitUtils.validate("generateSketchOrPrint", 5);
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
@@ -2946,13 +2946,14 @@ public class PythonService {
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒) .writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build(); .build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue)); // RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
RequestBody body = RequestBody.create(mediaType, params);
Request request = new Request.Builder() Request request = new Request.Builder()
// .url("http://18.167.251.121:9992") // .url("http://18.167.251.121:9992")
// .url("http://127.0.0.1:5000/api/diffusion") // .url("http://127.0.0.1:5000/api/diffusion")
// .url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion") // .url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion")
// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_image") // .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_image")
.url(srPythonPort + "/api/generate_image") .url(srPythonPort + servicePath)
.method("POST", body) .method("POST", body)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") // .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
@@ -2960,7 +2961,8 @@ public class PythonService {
Response response = null; Response response = null;
String bodyString; String bodyString;
try { try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue)); // log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
log.info("generateSketchOrPrint请求入参content###{}", params);
response = client.newCall(request).execute(); response = client.newCall(request).execute();
} catch (IOException ioException) { } catch (IOException ioException) {
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));

View File

@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
import com.ai.da.common.config.exception.BusinessException; import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.constant.CommonConstant; import com.ai.da.common.constant.CommonConstant;
import com.ai.da.common.context.UserContext; import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel2TypeEnum;
import com.ai.da.common.enums.GenerateModeEnum; import com.ai.da.common.enums.GenerateModeEnum;
import com.ai.da.common.enums.ModelNameEnum; import com.ai.da.common.enums.ModelNameEnum;
import com.ai.da.common.utils.*; import com.ai.da.common.utils.*;
@@ -21,7 +22,7 @@ import com.ai.da.service.GenerateService;
import com.ai.da.service.LibraryService; import com.ai.da.service.LibraryService;
import com.ai.da.service.RabbitMQService; import com.ai.da.service.RabbitMQService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -32,13 +33,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static com.ai.da.common.enums.CollectionLevel1TypeEnum.*; import static com.ai.da.common.enums.CollectionLevel1TypeEnum.*;
@@ -85,6 +84,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
@Value("${redis.key.generateResult}") @Value("${redis.key.generateResult}")
private String generateResultKey; private String generateResultKey;
@Value("${minio.bucketName.slogan}")
private String sloganBucket;
@Override @Override
public GenerateCaptionVO generateCaption(Long sketchElementId) { public GenerateCaptionVO generateCaption(Long sketchElementId) {
CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId); CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId);
@@ -110,6 +112,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generate.setAccountId(accountId); generate.setAccountId(accountId);
generate.setUniqueId(generateThroughImageTextDTO.getUniqueId()); generate.setUniqueId(generateThroughImageTextDTO.getUniqueId());
generate.setLevel1Type(generateThroughImageTextDTO.getLevel1Type()); generate.setLevel1Type(generateThroughImageTextDTO.getLevel1Type());
generate.setLevel2Type(generateThroughImageTextDTO.getLevel2Type());
generate.setSeed(StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getSeed()) ? "" : generateThroughImageTextDTO.getSeed());
// 当level1type是sketchboard时存数据库需要加上当前性别 // 当level1type是sketchboard时存数据库需要加上当前性别
generate.setGenerateType(generate.getLevel1Type().equals(SKETCH_BOARD.getRealName()) ? generate.setGenerateType(generate.getLevel1Type().equals(SKETCH_BOARD.getRealName()) ?
generateType + " (" + generateThroughImageTextDTO.getGender() + ")" : generateType + " (" + generateThroughImageTextDTO.getGender() + ")" :
@@ -119,12 +123,15 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generate.setElementSource(StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getDesignType()) ? null : generateThroughImageTextDTO.getDesignType()); generate.setElementSource(StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getDesignType()) ? null : generateThroughImageTextDTO.getDesignType());
String text = generateThroughImageTextDTO.getText(); String text = generateThroughImageTextDTO.getText();
generate.setText(text);
Long elementId = generateThroughImageTextDTO.getCollectionElementId(); Long elementId = generateThroughImageTextDTO.getCollectionElementId();
validateGeneraType(generate, text, elementId, generateType); // validateGeneraType(generate, text, elementId);
if (!StringUtil.isNullOrEmpty(text)) { if (!StringUtil.isNullOrEmpty(text)) {
text = modifyPrompt(text, generate, generateThroughImageTextDTO.getLevel1Type()); text = modifyPrompt(text, generate, generateThroughImageTextDTO.getLevel1Type());
} }
// todo 这一步现在还是有必要的吗?
// 2.1 sketch或print在t_collection_element表/t_library表中的信息是否需要更新 如 level2Type // 2.1 sketch或print在t_collection_element表/t_library表中的信息是否需要更新 如 level2Type
CollectionElement collectionElement = collectionElementService.editLevel2Type(elementId, generateThroughImageTextDTO.getLevel2Type(), generateThroughImageTextDTO.getDesignType()); CollectionElement collectionElement = collectionElementService.editLevel2Type(elementId, generateThroughImageTextDTO.getLevel2Type(), generateThroughImageTextDTO.getDesignType());
@@ -134,15 +141,38 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
GenerateModeEnum.TEXT_IMAGE.getType(); GenerateModeEnum.TEXT_IMAGE.getType();
String category = generateThroughImageTextDTO.getLevel1Type().equals(SKETCH_BOARD.getRealName()) ? "sketch" : String category = generateThroughImageTextDTO.getLevel1Type().equals(SKETCH_BOARD.getRealName()) ? "sketch" :
generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName()) ? "print" : "moodboard"; generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName()) ? "print" : "moodboard";
// AsyncCallerUtil asyncCallerUtil = new AsyncCallerUtil(); String path = CommonConstant.GENERATE_PATH;
// List<String> generatedSketchUrl = asyncCallerUtil.generate(new GenerateToPythonDTO(accountId, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(), String jsonString = "";
// category, text, mode, "1", generateThroughImageTextDTO.getGender(), generateThroughImageTextDTO.getUniqueId())); HashMap<String, String> params = new HashMap<>();
Boolean requestResult = pythonService.generateSketchOrPrint(new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(), // 3.1 确定不同类型的印花分别调哪个接口
mode, category, generateThroughImageTextDTO.getGender())); if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())){
// log.info("generate 响应 " + generatedSketchUrl); switch(generateThroughImageTextDTO.getLevel2Type()){
// if (CollectionUtils.isEmpty(generatedSketchUrl)) { case "Logo":
// return null; path = CommonConstant.GENERATE_SINGLE_LOGO;
// } params.put("tasks_id",generateThroughImageTextDTO.getUniqueId());
params.put("prompt", text);
params.put("seed", generateThroughImageTextDTO.getSeed());
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
break;
case "Slogan":
path = CommonConstant.GENERATE_SLOGAN;
params.put("tasks_id",generateThroughImageTextDTO.getUniqueId());
params.put("prompt", text);
params.put("svg", collectionElement.getUrl());
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
break;
case "Pattern":
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
mode, category, generateThroughImageTextDTO.getGender());
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
}
}else {
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
mode, category, generateThroughImageTextDTO.getGender());
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
}
Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, path);
// 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中 // 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中
save(generate); save(generate);
@@ -229,8 +259,24 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME); redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
} }
private void validateGeneraType(Generate generate, String text, Long elementId, String generateType) { private void validateGeneraType(Generate generate, String text, Long elementId) {
switch (generateType) { String generateType = "";
if (StringUtil.isNullOrEmpty(text.trim()) && Objects.isNull(elementId)) {
throw new BusinessException("please.input.the.caption.or.choose.an.image");
} else if (!StringUtil.isNullOrEmpty(text.trim()) && !Objects.isNull(elementId)) {
generateType = "text-image";
generate.setText(text);
generate.setElementId(elementId);
} else if (!StringUtil.isNullOrEmpty(text.trim())) {
generateType = "text";
generate.setText(text);
} else if (!Objects.isNull(elementId)) {
generateType = "image";
generate.setElementId(elementId);
}
generate.setGenerateType(generateType);
/*switch (generateType) {
case "text": case "text":
if (StringUtil.isNullOrEmpty(text)) { if (StringUtil.isNullOrEmpty(text)) {
throw new BusinessException("please.input.the.caption"); throw new BusinessException("please.input.the.caption");
@@ -250,7 +296,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generate.setText(text); generate.setText(text);
generate.setElementId(elementId); generate.setElementId(elementId);
default: default:
} }*/
} }
private String modifyPrompt(String userInput, Generate generate, String level1Type) { private String modifyPrompt(String userInput, Generate generate, String level1Type) {
@@ -263,13 +309,15 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
break; break;
case "Printboard": case "Printboard":
if (userInput.contains("Painting Style")) { if (userInput.contains("Painting Style")) {
userInput = "Picasso,increased color saturation,increased glossiness," + translated; text = "Picasso,increased color saturation,increased glossiness," + translated + ", fabric print, high quality";
} else if (userInput.contains("Illustration Style")) { } else if (userInput.contains("Illustration Style")) {
userInput = "Flat coating,romantic,soft,pencil strokes,accentuating and widening the depth of pencil strokes,paper patterns,block colors,crayons,reducing image contrast,and hand drawn painting marks," + translated; text = "Flat coating,romantic,soft,pencil strokes,accentuating and widening the depth of pencil strokes,paper patterns,block colors,crayons,reducing image contrast,and hand drawn painting marks," + translated + ", fabric print, high quality";
} else if (userInput.contains("Real Style")) { } else if (userInput.contains("Real Style")) {
userInput = "Still life photography,hyper realism,3d,deepened projection,increased permutation value,increased concavity and convexity value," + translated; text = "Still life photography,hyper realism,3d,deepened projection,increased permutation value,increased concavity and convexity value," + translated + ", fabric print, high quality";
}else {
text = translated;
} }
text = userInput + ", fabric print, high quality"; // text = userInput + ", fabric print, high quality";
// generate.setText(text); // generate.setText(text);
break; break;
case "Sketchboard": case "Sketchboard":
@@ -408,10 +456,10 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
if (Objects.isNull(generateThroughImageTextDTO.getUserId())) { if (Objects.isNull(generateThroughImageTextDTO.getUserId())) {
throw new BusinessException("userId cannot be empty"); throw new BusinessException("userId cannot be empty");
} }
String generateType = generateThroughImageTextDTO.getGenerateType(); /*String generateType = generateThroughImageTextDTO.getGenerateType();
if (!GenerateModeEnum.getGenerateModeList().contains(generateType)) { if (!GenerateModeEnum.getGenerateModeList().contains(generateType)) {
throw new BusinessException("unknown.generate.type"); throw new BusinessException("unknown.generate.type");
} }*/
// 判断试用用户是否还有剩余试用机会 // 判断试用用户是否还有剩余试用机会
int trialsCount = 0; int trialsCount = 0;
@@ -422,15 +470,75 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} }
} }
String text = generateThroughImageTextDTO.getText(); int times = 4;
Long elementId = generateThroughImageTextDTO.getCollectionElementId(); // 当level1Type为Print_board时level2Type为pattern时需要确定generateType
validateGeneraType(new Generate(), text, elementId, generateType); if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())){
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getLevel2Type())){
throw new BusinessException("level2Type.cannot.be.empty");
}else if (!CollectionLevel2TypeEnum.printType().contains(generateThroughImageTextDTO.getLevel2Type())){
throw new BusinessException("unknown.parameter.level2Type");
}
// Pattern 参数校验
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.Pattern.getRealName())){
String text = generateThroughImageTextDTO.getText();
Long elementId = generateThroughImageTextDTO.getCollectionElementId();
Generate generate = new Generate();
validateGeneraType(generate, text, elementId);
// 校验后获取
generateThroughImageTextDTO.setGenerateType(generate.getGenerateType());
}
// Slogan 参数校验
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.SLOGAN.getRealName())){
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getSloganBase64())){
log.error("Printboard-Slogan模式下slogan image为空");
throw new BusinessException("Slogan can not be empty!");
}
// 将图片上传到图片服务器
String path = minioUtil.base64Upload(generateThroughImageTextDTO.getSloganBase64(), sloganBucket);
String name = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
// 保存到db,collection-element
CollectionElement collectionElement = new CollectionElement();
collectionElement.setAccountId(generateThroughImageTextDTO.getUserId());
collectionElement.setCollectionId(0L);
collectionElement.setLevel1Type(PRINT_BOARD.getRealName());
collectionElement.setLevel2Type(CollectionLevel2TypeEnum.SLOGAN.getRealName());
collectionElement.setName(name);
collectionElement.setUrl(path);
collectionElement.setHasPin((byte) 0);
collectionElement.setMd5(MD5Utils.encryptFile(minioUtil.getPresignedUrl(path, 24 * 60), Boolean.FALSE));
collectionElement.setCreateDate(DateUtil.getByTimeZone(generateThroughImageTextDTO.getTimeZone()));
collectionElementService.save(collectionElement);
// 将上传后的地址放在指定字段
generateThroughImageTextDTO.setCollectionElementId(collectionElement.getId());
generateThroughImageTextDTO.setSloganBase64(null);
generateThroughImageTextDTO.setDesignType("collection");
}
// Logo参数校验
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.LOGO.getRealName())){
// logo模式下一次只生成一张
times = 1;
// 校验是否输入内容
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getText().trim())){
throw new BusinessException("please.input.the.prompt");
}
// 校验seed的取值范围
int seed = Integer.parseInt(generateThroughImageTextDTO.getSeed());
if (seed < 0 || seed > 99999){
throw new BusinessException("the.value.range.of.seed");
}
}
}
// 2、生成唯一id 使用uuid,由于uuid重复的几率很小故取消对uuid重复性的校验 // 2、生成唯一id 使用uuid,由于uuid重复的几率很小故取消对uuid重复性的校验
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
ArrayList<String> taskIdList = new ArrayList<>(); ArrayList<String> taskIdList = new ArrayList<>();
for (int i = 1; i <= 4; i++) { for (int i = 1; i <= times; i++) {
String temp = uuid; String temp = uuid;
temp += "-" + i + "-" + generateThroughImageTextDTO.getUserId(); temp += "-" + i + "-" + generateThroughImageTextDTO.getUserId();
taskIdList.add(temp); taskIdList.add(temp);
@@ -588,7 +696,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String key = generateResultKey + ":" + uniqueId; String key = generateResultKey + ":" + uniqueId;
GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class); GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class);
// 判断当前task的状态是不是Fail // 判断当前task的状态是不是Fail
if (!generateResultVO.getStatus().equals("Fail")){ if (!generateResultVO.getStatus().equals("Fail")) {
// 2、不是直接发送取消请求到python端 // 2、不是直接发送取消请求到python端
pythonService.cancelGenerateTask(uniqueId); pythonService.cancelGenerateTask(uniqueId);
// 3、更改result中当前taskId的状态 // 3、更改result中当前taskId的状态

View File

@@ -54,9 +54,10 @@ save.collection.failed=Save collection failed.
save.designItemDetail.failed=Save designItemDetail failed. save.designItemDetail.failed=Save designItemDetail failed.
save.classification.failed=Save classification failed. save.classification.failed=Save classification failed.
update.classification.failed=Update classification failed. update.classification.failed=Update classification failed.
please.input.the.caption=Please input the caption. please.input.the.prompt=Please input the prompt.
please.choose.an.image=Please choose an image. please.choose.an.image=Please choose an image.
please.input.the.caption.and.choose.an.image=Please input the caption and choose an image. please.input.the.caption.and.choose.an.image=Please input the caption and choose an image.
please.input.the.caption.or.choose.an.image=Please input the caption or choose an image.
duplicate.likes.are.not.allowed=Duplicate likes are not allowed. duplicate.likes.are.not.allowed=Duplicate likes are not allowed.
layer.information.not.found=Layer information not found. layer.information.not.found=Layer information not found.
singleOverall.cannot.be.empty=singleOverall cannot be empty. singleOverall.cannot.be.empty=singleOverall cannot be empty.
@@ -132,6 +133,7 @@ image.synthesis.failed=image synthesis failed.
priority.cannot.be.repeated=priority cannot be repeated. priority.cannot.be.repeated=priority cannot be repeated.
model.not.found=model not found. model.not.found=model not found.
libraryIdList.cannot.be.empty=libraryIdList cannot be empty. libraryIdList.cannot.be.empty=libraryIdList cannot be empty.
the.value.range.of.seed=The value range of seed is 0-99999
# 可能会报异常 # 可能会报异常
# Informative: # Informative: