Merge remote-tracking branch 'origin/dev/dev' into dev/dev

# Conflicts:
#	src/main/resources/application-dev.properties
This commit is contained in:
shahaibo
2024-06-17 17:38:04 +08:00
6 changed files with 42 additions and 18 deletions

View File

@@ -72,7 +72,7 @@ public class GenerateConsumer {
try { try {
generateService.generateThroughImageText(generateThroughImageTextDTO); generateService.generateThroughImageText(generateThroughImageTextDTO);
}catch (Exception e){ }catch (Exception e){
log.error(e.getMessage()); log.error("error message : {}", e.getMessage());
} }
// 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除 // 将消息从redis排队队列中删除,需保证被消费的消息存储到db之后再从redis删除
redisUtil.removeFromZSet(consumptionOrderKey, uniqueId); redisUtil.removeFromZSet(consumptionOrderKey, uniqueId);

View File

@@ -13,13 +13,16 @@ public class MQConfig {
// ================================================================== // ==================================================================
// public static final String GENERATE_QUEUE = "generate-queue-local"; // public static final String GENERATE_QUEUE = "generate-queue-local";
public static final String GENERATE_QUEUE = "generate-queue-dev"; public static final String GENERATE_QUEUE = "generate-queue-dev";
// public static final String GENERATE_QUEUE = "generate-queue-prod";
//
// public static final String SR_QUEUE = "SR-queue-local"; // public static final String SR_QUEUE = "SR-queue-local";
public static final String SR_QUEUE = "SR-queue-dev"; public static final String SR_QUEUE = "SR-queue-dev";
// public static final String SR_QUEUE = "SR-queue-prod";
//
// public static final String SR_RESULT_QUEUE = "SuperResolution-local"; // public static final String SR_RESULT_QUEUE = "SuperResolution-local";
public static final String SR_RESULT_QUEUE = "SuperResolution-dev"; public static final String SR_RESULT_QUEUE = "SuperResolution-dev";
// public static final String SR_RESULT_QUEUE = "SuperResolution-prod";
//
// public static final String GENERATE_RESULT_QUEUE = "GenerateImage-local"; // public static final String GENERATE_RESULT_QUEUE = "GenerateImage-local";
public static final String GENERATE_RESULT_QUEUE = "GenerateImage-dev"; public static final String GENERATE_RESULT_QUEUE = "GenerateImage-dev";

View File

@@ -23,4 +23,10 @@ public class CommonConstant {
public static final String GENERATE_SLOGAN = "/api/slogan"; public static final String GENERATE_SLOGAN = "/api/slogan";
public static final String PYTHON_PORT_9996 = "9996";
public static final String PYTHON_PORT_9997 = "9997";
} }

View File

@@ -67,6 +67,8 @@ public class PythonService {
private String fastApiPythonAddress; private String fastApiPythonAddress;
@Value("${minio.bucketName.gradient}") @Value("${minio.bucketName.gradient}")
private String gradientBucketName; private String gradientBucketName;
@Value("${access.python.generate_sr_port}")
private String srServicePort;
@Resource @Resource
private PythonTAllInfoService pythonTAllInfoService; private PythonTAllInfoService pythonTAllInfoService;
@@ -2357,8 +2359,8 @@ public class PythonService {
log.info("design请求python 参数:####{}", param); log.info("design请求python 参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param); RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder() Request request = new Request.Builder()
// .url(accessPythonIp + ":" + accessPythonPort + "/api/design") .url(accessPythonIp + ":" + accessPythonPort + "/api/design")
.url(fastApiPythonAddress + "/api/design") // .url(fastApiPythonAddress + "/api/design")
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate") // .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.method("POST", body) .method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
@@ -2464,8 +2466,8 @@ public class PythonService {
System.out.println(JSON.toJSONString(content)); System.out.println(JSON.toJSONString(content));
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
Request request = new Request.Builder() Request request = new Request.Builder()
// .url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_retrieve") .url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_retrieve")
.url(fastApiPythonAddress + "/api/attribute_retrieve") // .url(fastApiPythonAddress + "/api/attribute_retrieve")
// .url(accessPythonIp+":9991/aifda/api/v1.0/attribute_retrieval") // .url(accessPythonIp+":9991/aifda/api/v1.0/attribute_retrieval")
.method("POST", body) .method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
@@ -2977,7 +2979,7 @@ public class PythonService {
throw new BusinessException("system error!"); throw new BusinessException("system error!");
} }
public Boolean generateSketchOrPrint(String params, String servicePath) { public Boolean generateSketchOrPrint(String params, String port, String servicePath) {
//限流校验 //限流校验
// AccessLimitUtils.validate("generateSketchOrPrint", 5); // AccessLimitUtils.validate("generateSketchOrPrint", 5);
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
@@ -2989,12 +2991,14 @@ public class PythonService {
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); RequestBody body = RequestBody.create(mediaType, params);
log.info("generate 请求地址: {}", accessPythonIp + ":" + port + servicePath);
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(fastApiPythonAddress + servicePath) .url(accessPythonIp + ":" + port + 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")
@@ -3220,7 +3224,7 @@ public class PythonService {
String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty); String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty);
RequestBody body = RequestBody.create(mediaType, jsonString); RequestBody body = RequestBody.create(mediaType, jsonString);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(fastApiPythonAddress + "/api/super_resolution") .url(accessPythonIp + ":" + srServicePort + "/api/super_resolution")
.method("POST", body) .method("POST", body)
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
.build(); .build();
@@ -3258,8 +3262,10 @@ public class PythonService {
String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty); String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty);
RequestBody body = RequestBody.create(mediaType, jsonString); RequestBody body = RequestBody.create(mediaType, jsonString);
String path = accessPythonIp + ":" + accessPythonPort + "/api/translateToEN";
log.info("translateToEN 请求地址: {}", path);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(accessPythonIp + ":" + accessPythonPort + "/api/translateToEN") .url(path)
// .url(fastApiPythonAddress + "/api/translateToEN") // .url(fastApiPythonAddress + "/api/translateToEN")
.method("POST", body) .method("POST", body)
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")

View File

@@ -152,8 +152,8 @@ public class ChatRobotServiceImpl implements ChatRobotService {
RequestBody body = RequestBody.create(mediaType, param); RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder() Request request = new Request.Builder()
// .url("http://127.0.0.1:5000/api/chat_stream_test") // .url("http://127.0.0.1:5000/api/chat_stream_test")
// .url(accessPythonIp + ":" + accessPythonPort + "/api/chat_stream_test") .url(accessPythonIp + ":" + accessPythonPort + "/api/chat_stream_test")
.url(fastApiPythonAddress + "/api/chat_robot") // .url(fastApiPythonAddress + "/api/chat_robot")
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate") // .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.method("POST", body) .method("POST", body)
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")

View File

@@ -88,6 +88,10 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
@Value("${redis.key.toProductImageResultKey}") @Value("${redis.key.toProductImageResultKey}")
private String toProductImageResultKey; private String toProductImageResultKey;
@Value("${access.python.generate_sr_port}")
private String generateServicePort;
@Override @Override
public GenerateCaptionVO generateCaption(Long sketchElementId) { public GenerateCaptionVO generateCaption(Long sketchElementId) {
CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId); CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId);
@@ -143,6 +147,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
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";
String path = CommonConstant.GENERATE_PATH; String path = CommonConstant.GENERATE_PATH;
String port = generateServicePort;
String jsonString = ""; String jsonString = "";
HashMap<String, String> params = new HashMap<>(); HashMap<String, String> params = new HashMap<>();
// 3.1 确定不同类型的印花分别调哪个接口 // 3.1 确定不同类型的印花分别调哪个接口
@@ -157,9 +162,11 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
break; break;
case "Slogan": case "Slogan":
path = CommonConstant.GENERATE_SLOGAN; path = CommonConstant.GENERATE_SLOGAN;
port = CommonConstant.PYTHON_PORT_9997;
params.put("num_point","16");
params.put("tasks_id",generateThroughImageTextDTO.getUniqueId()); params.put("tasks_id",generateThroughImageTextDTO.getUniqueId());
params.put("prompt", text); params.put("prompt", text);
params.put("svg", collectionElement.getUrl()); params.put("image_url", collectionElement.getUrl());
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue); jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
break; break;
case "Pattern": case "Pattern":
@@ -173,7 +180,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue); jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
} }
Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, path); Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path);
// 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中 // 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中
save(generate); save(generate);
@@ -525,8 +532,10 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
throw new BusinessException("Slogan can not be empty!"); throw new BusinessException("Slogan can not be empty!");
} }
times = 1;
// 将图片上传到图片服务器 // 将图片上传到图片服务器
String path = minioUtil.base64UploadToPath(generateThroughImageTextDTO.getSloganBase64(), sloganBucket, null); String path = minioUtil.base64UploadToPath(generateThroughImageTextDTO.getSloganBase64(), sloganBucket, null);
// String path = "test/7c9114f93d08a702e00da928e66f321.png";
String name = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")); String name = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
// 保存到db,collection-element // 保存到db,collection-element
CollectionElement collectionElement = new CollectionElement(); CollectionElement collectionElement = new CollectionElement();