本地flux改为flux2
This commit is contained in:
@@ -28,6 +28,11 @@ public class MQPublisher {
|
|||||||
amqpTemplate.convertAndSend(rabbitMQProperties.getQueues().getSr(), mm);
|
amqpTemplate.convertAndSend(rabbitMQProperties.getQueues().getSr(), mm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendGenerateResultMessage(String mm) {
|
||||||
|
log.info("send generate result message: {}", mm);
|
||||||
|
amqpTemplate.convertAndSend(rabbitMQProperties.getQueues().getGenerateResult(), mm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param mailParams 含有的字段
|
* @param mailParams 含有的字段
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ 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_PATH = "/api/generate_image_flux2_klein";
|
||||||
|
|
||||||
public static final String GENERATE_SINGLE_LOGO = "/api/generate_single_logo";
|
public static final String GENERATE_SINGLE_LOGO = "/api/generate_single_logo";
|
||||||
|
|
||||||
|
|||||||
55
src/main/java/com/ai/da/model/dto/ImageProcessRequest.java
Normal file
55
src/main/java/com/ai/da/model/dto/ImageProcessRequest.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package com.ai.da.model.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片处理请求体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class ImageProcessRequest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSS桶名(bucket_name)
|
||||||
|
*/
|
||||||
|
private String bucket_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSS对象名(object_name)
|
||||||
|
*/
|
||||||
|
private String object_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入图片路径列表(input_image_paths)
|
||||||
|
*/
|
||||||
|
private List<String> input_image_paths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图像宽度(width)
|
||||||
|
*/
|
||||||
|
private Integer width;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图像高度(height)
|
||||||
|
*/
|
||||||
|
private Integer height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本提示(prompt)
|
||||||
|
*/
|
||||||
|
private String prompt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推理步数(steps)
|
||||||
|
*/
|
||||||
|
private Integer steps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引导系数(guidance)
|
||||||
|
*/
|
||||||
|
private Double guidance;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,8 +2,10 @@ package com.ai.da.python;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||||
|
import com.ai.da.common.RabbitMQ.RabbitMQProperties;
|
||||||
import com.ai.da.common.config.FileProperties;
|
import com.ai.da.common.config.FileProperties;
|
||||||
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.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.enums.*;
|
import com.ai.da.common.enums.*;
|
||||||
import com.ai.da.common.utils.*;
|
import com.ai.da.common.utils.*;
|
||||||
@@ -20,6 +22,7 @@ import com.ai.da.model.vo.*;
|
|||||||
import com.ai.da.python.vo.*;
|
import com.ai.da.python.vo.*;
|
||||||
import com.ai.da.service.DesignHistoryService;
|
import com.ai.da.service.DesignHistoryService;
|
||||||
import com.ai.da.service.PythonTAllInfoService;
|
import com.ai.da.service.PythonTAllInfoService;
|
||||||
|
import com.ai.da.service.RabbitMQService;
|
||||||
import com.ai.da.service.SysFileService;
|
import com.ai.da.service.SysFileService;
|
||||||
import com.alibaba.fastjson.*;
|
import com.alibaba.fastjson.*;
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
@@ -84,6 +87,12 @@ public class PythonService {
|
|||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RabbitMQService rabbitMQService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RabbitMQProperties rabbitMQProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成打印的图片 二合一 (废弃于2024/01/02)
|
* 生成打印的图片 二合一 (废弃于2024/01/02)
|
||||||
*
|
*
|
||||||
@@ -3334,7 +3343,7 @@ public class PythonService {
|
|||||||
throw new BusinessException("system error!");
|
throw new BusinessException("system error!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean generateSketchOrPrint(String params, String port, String servicePath) {
|
public Boolean generateSketchOrPrint(String params, String port, String servicePath,String taskId) {
|
||||||
//限流校验
|
//限流校验
|
||||||
// AccessLimitUtils.validate("generateSketchOrPrint", 5);
|
// AccessLimitUtils.validate("generateSketchOrPrint", 5);
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
@@ -3396,6 +3405,22 @@ public class PythonService {
|
|||||||
if (result && jsonObject.get("code").equals(200)) {
|
if (result && jsonObject.get("code").equals(200)) {
|
||||||
log.info("Generate##responseObject###{}", jsonObject);
|
log.info("Generate##responseObject###{}", jsonObject);
|
||||||
// return setGenerateImageList(jsonObject.getJSONObject("data"));
|
// return setGenerateImageList(jsonObject.getJSONObject("data"));
|
||||||
|
if (servicePath== CommonConstant.GENERATE_PATH){
|
||||||
|
//放入结果到mq
|
||||||
|
JSONObject data = jsonObject.getJSONObject("data");
|
||||||
|
String outputPath = data.getString("output_path");
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, String> mqMessage = new HashMap<>();
|
||||||
|
mqMessage.put("tasks_id", taskId);
|
||||||
|
mqMessage.put("status", "SUCCESS");
|
||||||
|
mqMessage.put("message", "success");
|
||||||
|
mqMessage.put("image_url", outputPath);
|
||||||
|
mqMessage.put("category", "");
|
||||||
|
|
||||||
|
String mqMessageBody = JSON.toJSONString(mqMessage);
|
||||||
|
rabbitMQService.publishMessageToGenerateResult(mqMessageBody);
|
||||||
|
}
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
} else {
|
} else {
|
||||||
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
|
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ public interface RabbitMQService {
|
|||||||
|
|
||||||
void publishMessageToGenerate(String message);
|
void publishMessageToGenerate(String message);
|
||||||
|
|
||||||
|
void publishMessageToGenerateResult(String message);
|
||||||
|
|
||||||
void publishMessageToSR(String message);
|
void publishMessageToSR(String message);
|
||||||
|
|
||||||
Integer getMessageCount(String queueUrl);
|
Integer getMessageCount(String queueUrl);
|
||||||
|
|||||||
@@ -243,12 +243,17 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
|
// 构建object_name: {userId}/{category}/{uuid}.png
|
||||||
mode, category, generateThroughImageTextDTO.getGender(), version);
|
String objectName = generateThroughImageTextDTO.getUserId() + "/" + category + "/" + UUID.randomUUID() + ".png";
|
||||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
|
||||||
|
ImageProcessRequest imageProcessRequest = ImageProcessRequest.builder()
|
||||||
|
.object_name(objectName)
|
||||||
|
.bucket_name(userBucket)
|
||||||
|
.prompt(text).build();
|
||||||
|
jsonString = JSON.toJSONString(imageProcessRequest, SerializerFeature.WriteMapNullValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path);
|
Boolean requestResult = pythonService.generateSketchOrPrint(jsonString, port, path,generateThroughImageTextDTO.getUniqueId());
|
||||||
|
|
||||||
// 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中
|
// 4、将请求信息落库,将本次generate的请求信息添加到t_generate表中
|
||||||
save(generate);
|
save(generate);
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ public class RabbitMQServiceImpl implements RabbitMQService {
|
|||||||
mqPublisher.sendGenerateMessage(message);
|
mqPublisher.sendGenerateMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publishMessageToGenerateResult(String message) {
|
||||||
|
mqPublisher.sendGenerateResultMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publishMessageToSR(String message) {
|
public void publishMessageToSR(String message) {
|
||||||
mqPublisher.sendSRMessage(message);
|
mqPublisher.sendSRMessage(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user