TASK:aida;

This commit is contained in:
shahaibo
2024-06-27 15:33:26 +08:00
parent 58a78a5366
commit 9b438c78a3
19 changed files with 312 additions and 60 deletions

View File

@@ -602,7 +602,7 @@ public class PythonService {
} else if (systemScale.compareTo(BigDecimal.ONE) != 0) {
BigDecimal collectNoPinSize = BigDecimal.valueOf(collectionNoPinSize);
poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue();
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum, elementVO.getStyle());
collectionElements.addAll(list);
int randomNum = RandomsUtil.randomSysFile(collectionElements.size());
if (randomNum < collectionNoPinSize) {
@@ -612,7 +612,7 @@ public class PythonService {
}
}
}
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum, elementVO.getStyle());
int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
}
@@ -622,7 +622,7 @@ public class PythonService {
}
private DesignPythonItem processAttributeRecognitionBySameCategory(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory) {
List<CollectionElement> list = getSystemSketchPoolBySameCategory(attributeRecognition, styleCategory, elementVO.getModelSex());
List<CollectionElement> list = getSystemSketchPoolBySameCategory(attributeRecognition, styleCategory, elementVO.getModelSex(), elementVO.getStyle());
int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
}
@@ -630,7 +630,7 @@ public class PythonService {
@Resource
private AttributeRetrievalMapper attributeRetrievalMapper;
private List<CollectionElement> getSystemSketchPool(JSONObject attributeRecognition, String styleCategory, String modelSex, int poolNum) {
private List<CollectionElement> getSystemSketchPool(JSONObject attributeRecognition, String styleCategory, String modelSex, int poolNum, String style) {
/**
* female trousers->female_pants
* female blouse->female_top
@@ -644,19 +644,19 @@ public class PythonService {
AttributeRetrieval attributeRetrievalAttrDict = toAttrDict(attrDictJSON);
String tableName;
tableName = getTableName(modelSex, styleCategory);
List<AttributeRetrieval> attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum);
List<AttributeRetrieval> attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum, style);
if (CollectionUtil.isEmpty(attributeRetrievalList) || attributeRetrievalList.size() < poolNum) {
attributeRetrievalAttrDict.setDesign(null);
attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum);
attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum, style);
}
if (CollectionUtil.isEmpty(attributeRetrievalList) || attributeRetrievalList.size() < poolNum) {
attributeRetrievalAttrDict.setSilhouette(null);
attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum);
attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPool(attributeRetrievalAttrDict, tableName, poolNum, style);
}
return toColoectionElementList(attributeRetrievalList, styleCategory, modelSex);
}
private List<CollectionElement> getSystemSketchPoolBySameCategory(JSONObject attributeRecognition, String styleCategory, String modelSex) {
private List<CollectionElement> getSystemSketchPoolBySameCategory(JSONObject attributeRecognition, String styleCategory, String modelSex, String style) {
/**
* female trousers->female_pants
* female blouse->female_top
@@ -712,7 +712,7 @@ public class PythonService {
}
}
List<AttributeRetrieval> attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPoolBySameCategory(attributeRetrievalAttrDict, tableName);
List<AttributeRetrieval> attributeRetrievalList = attributeRetrievalMapper.getSystemSketchPoolBySameCategory(attributeRetrievalAttrDict, tableName, style);
if (CollectionUtil.isEmpty(attributeRetrievalList)) {
System.out.println(attributeRetrievalAttrDict);
System.out.println(tableName);
@@ -935,7 +935,7 @@ public class PythonService {
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName = getTableName(validateElementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName, validateElementVO.getStyle());
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, validateElementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, validateElementVO);
}
@@ -975,7 +975,7 @@ public class PythonService {
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName = getTableName(validateElementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName, validateElementVO.getStyle());
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, validateElementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, validateElementVO);
}
@@ -2801,23 +2801,23 @@ public class PythonService {
private List<DesignPythonItem> coverToModelsDotPythonItem(ModelsDotDTO modelsDotDTO) {
List<DesignPythonItem> response = Lists.newArrayList();
if (modelsDotDTO.getTemplateUrl().contains("female")) {
DesignPythonItem dress = new DesignPythonItem();
dress.setType(SysFileLevel2TypeEnum.DRESS.getRealName());
dress.setColor("none");
dress.setIcon("none");
// DesignPythonItem dress = new DesignPythonItem();
// dress.setType(SysFileLevel2TypeEnum.DRESS.getRealName());
// dress.setColor("none");
// dress.setIcon("none");
DesignPythonItemPrint designPythonItemPrint = new DesignPythonItemPrint();
designPythonItemPrint.setIfSingle(false);
designPythonItemPrint.setPrint_path_list(new ArrayList<>());
dress.setPrint(designPythonItemPrint);
dress.setPath("aida-sys-image/images/female/blouse/blouse_p5_817.jpg");
response.add(dress);
// dress.setPrint(designPythonItemPrint);
// dress.setPath("aida-sys-image/images/female/blouse/blouse_p5_817.jpg");
// response.add(dress);
DesignPythonItem skirt = new DesignPythonItem();
skirt.setType(SysFileLevel2TypeEnum.TROUSERS.getRealName());
skirt.setType(SysFileLevel2TypeEnum.DRESS.getRealName());
skirt.setColor("none");
skirt.setIcon("none");
skirt.setPrint(designPythonItemPrint);
skirt.setPath("aida-sys-image/images/female/trousers/trousers_974.jpg");
skirt.setPath("aida-sys-image/images/female/dress/0628002038.jpeg");
response.add(skirt);
} else {
DesignPythonItem top = new DesignPythonItem();
@@ -2839,7 +2839,7 @@ public class PythonService {
designPythonItemPrint1.setIfSingle(false);
designPythonItemPrint1.setPrint_path_list(new ArrayList<>());
bottom.setPrint(designPythonItemPrint1);
bottom.setPath("aida-sys-image/images/male/bottoms/mens_test_10007.png");
bottom.setPath("aida-sys-image/images/male/bottoms/mens_test_12.png");
response.add(bottom);
}
@@ -3348,4 +3348,46 @@ public class PythonService {
//生成失败
throw new BusinessException("toProductImage.interface.exception");
}
public Boolean relight(String url, String taskId, String prompt) {
// todo 限流校验
// AccessLimitUtils.validate("design",5);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
Map<String, String> map = new HashMap<>();
map.put("tasks_id", taskId);
map.put("image_url", url);
map.put("prompt", prompt);
log.info("relightImage请求python 参数:####{}", map);
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder()
// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_product_image")
// .url(accessPythonIp + ":9996/api/generate_product_image")
.url(accessPythonIp + ":9994/api/generate_relight_image")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response;
String responseBody;
try {
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##relightImage异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("relightImage.interface.exception");
}
if (response.isSuccessful()) {
return Boolean.TRUE;
}
log.error("PythonService##relightImage异常response###{}", response);
//生成失败
throw new BusinessException("relightImage.interface.exception");
}
}