当style为洛丽塔时无sketch和谷歌风控问题FIX

This commit is contained in:
litianxiang
2026-03-12 18:36:21 +08:00
parent fc72d2c430
commit 61b7f3072f
2 changed files with 65 additions and 49 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
@@ -279,7 +280,7 @@ public class PythonService {
if (isDuplicate) { if (isDuplicate) {
elementVO.setHasUseMd5List(beforeAssemblyHasUseMd5List); elementVO.setHasUseMd5List(beforeAssemblyHasUseMd5List);
i --; i--;
switch (designPrintPictureType) { switch (designPrintPictureType) {
case PIN: case PIN:
@@ -406,13 +407,14 @@ public class PythonService {
// if (CollectionUtil.isEmpty(pinData)) { // if (CollectionUtil.isEmpty(pinData)) {
// return 0; // return 0;
// } // }
//// long topNum = sketchBoardElements.stream()
//// .filter(skecth -> skecth.getHasPin() == 1 /// / long topNum = sketchBoardElements.stream()
//// && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count(); /// / .filter(skecth -> skecth.getHasPin() == 1
//// long bottomNum = sketchBoardElements.stream() /// / && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
//// .filter(skecth -> skecth.getHasPin() == 1 /// / long bottomNum = sketchBoardElements.stream()
//// && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count(); /// / .filter(skecth -> skecth.getHasPin() == 1
//// int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue(); /// / && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
/// / int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue();
// int num = pinData.size(); // int num = pinData.size();
// return Math.min(num, 8); // return Math.min(num, 8);
// } // }
@@ -560,12 +562,12 @@ public class PythonService {
return 0; return 0;
} else { } else {
long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count(); long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count();
if (designNum - pinNum < 0){ if (designNum - pinNum < 0) {
return RandomsUtil.randomSysFile(0L, (long) (pinNum/2 + 1)); return RandomsUtil.randomSysFile(0L, (long) (pinNum / 2 + 1));
} else if (designNum - pinNum < designNum/2) { } else if (designNum - pinNum < designNum / 2) {
return RandomsUtil.randomSysFile(0L, designNum - pinNum + 1); return RandomsUtil.randomSysFile(0L, designNum - pinNum + 1);
} else { } else {
return RandomsUtil.randomSysFile(0L, (long) (designNum/2 + 1)); return RandomsUtil.randomSysFile(0L, (long) (designNum / 2 + 1));
} }
} }
} }
@@ -680,8 +682,10 @@ public class PythonService {
// 其他所有情况,都回退到使用系统推荐 // 其他所有情况,都回退到使用系统推荐
String categoryParam = elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase(); String categoryParam = elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale(),elementVO.getStyle()); List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale(), elementVO.getStyle());
if (recommentdUrlList.size() == 0) {
recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale(), null);
}
if (CollectionUtils.isEmpty(recommentdUrlList)) { if (CollectionUtils.isEmpty(recommentdUrlList)) {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
} }
@@ -1039,7 +1043,7 @@ public class PythonService {
if (!CollectionUtils.isEmpty(recommentdUrlList)) { if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0); String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
}else { } else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
} }
// JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex()); // JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex());
@@ -1062,7 +1066,7 @@ public class PythonService {
if (!CollectionUtils.isEmpty(recommentdUrlList)) { if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0); String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
}else { } else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
} }
@@ -1098,7 +1102,7 @@ public class PythonService {
if (!CollectionUtils.isEmpty(recommentdUrlList)) { if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0); String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
}else { } else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
} }
// JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex()); // JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex());
@@ -1122,7 +1126,7 @@ public class PythonService {
if (!CollectionUtils.isEmpty(recommentdUrlList)) { if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0); String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
}else { } else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
} }
// String tableName = getTableName(validateElementVO.getModelSex(), category); // String tableName = getTableName(validateElementVO.getModelSex(), category);
@@ -2190,7 +2194,7 @@ public class PythonService {
basic.setScale_earrings(0.16); basic.setScale_earrings(0.16);
if (Objects.nonNull(designLibraryModelPointVO)) { if (Objects.nonNull(designLibraryModelPointVO)) {
basic.setBody_point_test(getMap(designLibraryModelPointVO)); basic.setBody_point_test(getMap(designLibraryModelPointVO));
}else { } else {
basic.setBody_point_test(getMap(designLibraryModelPoint)); basic.setBody_point_test(getMap(designLibraryModelPoint));
} }
return basic; return basic;
@@ -2857,7 +2861,7 @@ public class PythonService {
/*PrintToPython printToPython = resolveDesignSinglePrint(designSingleItem.getPrintObject().getPrints(), /*PrintToPython printToPython = resolveDesignSinglePrint(designSingleItem.getPrintObject().getPrints(),
designSingleItem.getPartialDesign().getPartialDesignMinioPath());*/ designSingleItem.getPartialDesign().getPartialDesignMinioPath());*/
// resolveDesignElement(designSingleItem.getTrims(), printToPython); // resolveDesignElement(designSingleItem.getTrims(), printToPython);
log.info("组装参数【服装:{}的maskUrl: {}】",designSingleItem.getType(), designSingleItem.getMaskUrl()); log.info("组装参数【服装:{}的maskUrl: {}】", designSingleItem.getType(), designSingleItem.getMaskUrl());
String partialDesign = designSingleItem.getPartialDesign().getPartialDesignMinioPath(); String partialDesign = designSingleItem.getPartialDesign().getPartialDesignMinioPath();
String mergeImagePath = !StringUtil.isNullOrEmpty(partialDesign) String mergeImagePath = !StringUtil.isNullOrEmpty(partialDesign)
@@ -2884,7 +2888,7 @@ public class PythonService {
}); });
if (singleOverall.equals("overall")){ if (singleOverall.equals("overall")) {
String bodyPath; String bodyPath;
if (Objects.nonNull(designLibraryModelPoint)) { if (Objects.nonNull(designLibraryModelPoint)) {
bodyPath = designLibraryModelPoint.getTemplateUrl(); bodyPath = designLibraryModelPoint.getTemplateUrl();
@@ -2905,7 +2909,7 @@ public class PythonService {
// printToPython.setSingle(printSingle); // printToPython.setSingle(printSingle);
printToPython.setOverall(printOverall); printToPython.setOverall(printOverall);
printToPython.setPartial(StringUtil.isNullOrEmpty(partialDesign) ? null : partialDesign); printToPython.setPartial(StringUtil.isNullOrEmpty(partialDesign) ? null : partialDesign);
if (Objects.isNull(printObject) || printObject.isEmpty()){ if (Objects.isNull(printObject) || printObject.isEmpty()) {
return printToPython; return printToPython;
} }
@@ -2936,12 +2940,12 @@ public class PythonService {
Integer priority = p.getPriority(); Integer priority = p.getPriority();
setUriToMinioPath(p); setUriToMinioPath(p);
// todo 下标越界问题 // todo 下标越界问题
if (p.getIfSingle()){ if (p.getIfSingle()) {
locationS.set(priority - 1, p.getLocation()); locationS.set(priority - 1, p.getLocation());
scaleS.set(priority - 1, p.getScale()); scaleS.set(priority - 1, p.getScale());
angleS.set( priority - 1, p.getAngle()); angleS.set(priority - 1, p.getAngle());
pathsS.set(priority - 1, p.getMinIOPath()); pathsS.set(priority - 1, p.getMinIOPath());
}else { } else {
locationO.set(priority - 1, p.getLocation()); locationO.set(priority - 1, p.getLocation());
scaleO.set(priority - 1, p.getScale()); scaleO.set(priority - 1, p.getScale());
angleO.set(priority - 1, p.getAngle()); angleO.set(priority - 1, p.getAngle());
@@ -2971,9 +2975,9 @@ public class PythonService {
} }
// 对印花类型为Generate的图片路径进行特殊处理 // 对印花类型为Generate的图片路径进行特殊处理
private void setUriToMinioPath(DesignSinglePrint print){ private void setUriToMinioPath(DesignSinglePrint print) {
if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")){ if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")) {
if (!StringUtil.isNullOrEmpty(print.getPath())){ if (!StringUtil.isNullOrEmpty(print.getPath())) {
try { try {
URI uri = new URI(print.getPath()); URI uri = new URI(print.getPath());
String path = uri.getPath(); // 获取路径部分: /aida-users/87/print/9ac32f65-6043-424d-a146-92c9c6d204ee-4-87.png String path = uri.getPath(); // 获取路径部分: /aida-users/87/print/9ac32f65-6043-424d-a146-92c9c6d204ee-4-87.png
@@ -3442,7 +3446,10 @@ public class PythonService {
return imageUrlList; return imageUrlList;
}*/ }*/
/** 废弃状态 */
/**
* 废弃状态
*/
public String composeLayers(List<OutfitDetailPythonItem> layersDetail) { public String composeLayers(List<OutfitDetailPythonItem> layersDetail) {
HashMap<String, List<OutfitDetailPythonItem>> layers = new HashMap<>(); HashMap<String, List<OutfitDetailPythonItem>> layers = new HashMap<>();
HashMap<String, HashMap<String, List<OutfitDetailPythonItem>>> content = new HashMap<>(); HashMap<String, HashMap<String, List<OutfitDetailPythonItem>>> content = new HashMap<>();
@@ -3753,7 +3760,7 @@ public class PythonService {
throw new BusinessException("relightImage.interface.exception"); throw new BusinessException("relightImage.interface.exception");
} }
public String imageToSketch(String imagePath, String bucket, String objectName, String styleCode, String styleImageUrl){ public String imageToSketch(String imagePath, String bucket, String objectName, String styleCode, String styleImageUrl) {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
@@ -3800,7 +3807,7 @@ public class PythonService {
String sketchResult = jsonObject.get("data").toString(); String sketchResult = jsonObject.get("data").toString();
log.info("ImageToSketch 结果 {}", sketchResult); log.info("ImageToSketch 结果 {}", sketchResult);
return sketchResult; return sketchResult;
}else { } else {
log.info("ImageToSketch 失败。 Response code {}", responseCode); log.info("ImageToSketch 失败。 Response code {}", responseCode);
throw new BusinessException("ImageToSketch 失败。 Response code " + responseCode); throw new BusinessException("ImageToSketch 失败。 Response code " + responseCode);
} }
@@ -3853,7 +3860,7 @@ public class PythonService {
throw new BusinessException("bright.interface.exception"); throw new BusinessException("bright.interface.exception");
} }
public JSONObject attributeRecognition(List<String> pictureUrls,List<String> ids, List<String> category) { public JSONObject attributeRecognition(List<String> pictureUrls, List<String> ids, List<String> category) {
//限流校验 //限流校验
AccessLimitUtils.validate("attributeRecognition", 20); AccessLimitUtils.validate("attributeRecognition", 20);
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
@@ -3885,7 +3892,7 @@ public class PythonService {
} catch (IOException ioException) { } catch (IOException ioException) {
log.error("PythonService###attributeRecognition异常##{}", ExceptionUtil.getThrowableList(ioException)); log.error("PythonService###attributeRecognition异常##{}", ExceptionUtil.getThrowableList(ioException));
} }
log.info("识别python对应的属性标签值结果###{}",bodyStr.trim()); log.info("识别python对应的属性标签值结果###{}", bodyStr.trim());
//去除限流 //去除限流
AccessLimitUtils.validateOut("attributeRecognition"); AccessLimitUtils.validateOut("attributeRecognition");
if (Objects.isNull(response)) { if (Objects.isNull(response)) {
@@ -3969,7 +3976,7 @@ public class PythonService {
throw new BusinessException("design.interface.exception"); throw new BusinessException("design.interface.exception");
} }
public List<String> getSystemSketchByCategory(String category, Long brandId, Double brandScale,String style) { public List<String> getSystemSketchByCategory(String category, Long brandId, Double brandScale, String style) {
//******3.1.2版本临时使用java推荐方案去解决style未使用的问题********** //******3.1.2版本临时使用java推荐方案去解决style未使用的问题**********
// try { // try {
// //使用新库attribute_retrieval_style表命名修改为elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase()比如female_skirt,与传入的category保持一致 // //使用新库attribute_retrieval_style表命名修改为elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase()比如female_skirt,与传入的category保持一致
@@ -4114,6 +4121,7 @@ public class PythonService {
//生成失败 //生成失败
throw new BusinessException("segProduct.interface.exception"); throw new BusinessException("segProduct.interface.exception");
} }
/** /**
* 转发 seg_anything 请求到 python 服务 * 转发 seg_anything 请求到 python 服务
* 请求 body 由调用方组装(包含 user_id, image_path, type, points, labels, box 等) * 请求 body 由调用方组装(包含 user_id, image_path, type, points, labels, box 等)
@@ -4177,7 +4185,7 @@ public class PythonService {
throw new BusinessException("segAnything.missing.output"); throw new BusinessException("segAnything.missing.output");
} }
throw new BusinessException("segAnything.interface.exception"); throw new BusinessException("segAnything.interface.exception");
} catch (IOException |JSONException e) { } catch (IOException | JSONException e) {
log.error("PythonService##segAnything异常###{}", e.getMessage()); log.error("PythonService##segAnything异常###{}", e.getMessage());
throw new BusinessException("segAnything.interface.exception"); throw new BusinessException("segAnything.interface.exception");
} }
@@ -4185,6 +4193,7 @@ public class PythonService {
log.error("PythonService##segAnything异常response###{}", response); log.error("PythonService##segAnything异常response###{}", response);
throw new BusinessException("segAnything.interface.exception"); throw new BusinessException("segAnything.interface.exception");
} }
public Boolean poseTransformation(JSONObject content, String apiUri) { public Boolean poseTransformation(JSONObject content, String apiUri) {
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
@@ -4288,7 +4297,7 @@ public class PythonService {
String modifiedModel = jsonObject.get("data").toString(); String modifiedModel = jsonObject.get("data").toString();
log.info("modifyModelProportion 结果 {}", modifiedModel); log.info("modifyModelProportion 结果 {}", modifiedModel);
return modifiedModel; return modifiedModel;
}else { } else {
log.info("modifyModelProportion 失败。 Response code {}", responseCode); log.info("modifyModelProportion 失败。 Response code {}", responseCode);
throw new BusinessException("modifyModelProportion 失败。 Response code " + responseCode); throw new BusinessException("modifyModelProportion 失败。 Response code " + responseCode);
} }
@@ -4391,10 +4400,11 @@ public class PythonService {
log.info("imageSegmentation 结果 {}", jsonObject.get("data").toString()); log.info("imageSegmentation 结果 {}", jsonObject.get("data").toString());
List<ImageSegmentation.ImageDate> seg = JSONObject.parseObject( List<ImageSegmentation.ImageDate> seg = JSONObject.parseObject(
jsonObject.get("data").toString(), jsonObject.get("data").toString(),
new TypeReference<List<ImageSegmentation.ImageDate>>() {} new TypeReference<List<ImageSegmentation.ImageDate>>() {
}
); );
return seg; return seg;
}else { } else {
log.info("imageSegmentation 失败。 Response code {}", responseCode); log.info("imageSegmentation 失败。 Response code {}", responseCode);
throw new BusinessException("imageSegmentation 失败。 Response code " + responseCode); throw new BusinessException("imageSegmentation 失败。 Response code " + responseCode);
} }

View File

@@ -1260,8 +1260,14 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
modelAndPromptMap.put(ModelConstants.USE_MODEL, ModelConstants.LOCAL_MODEL); modelAndPromptMap.put(ModelConstants.USE_MODEL, ModelConstants.LOCAL_MODEL);
} }
} else if (ModelConstants.SKETCHBOARD.equals(generateDTO.getLevel1Type())) { } else if (ModelConstants.SKETCHBOARD.equals(generateDTO.getLevel1Type())) {
String prompt = generateDTO.getText() + "rules:front view sketch only,plain white background, single garment only, orthographic, centered on white background, borderless canvas, thin monochrome black line art.\n" + String[] split = generateDTO.getText().split(",");
" No clothes hanger, no fake clothes hanger, no human-related lines, no color fill, no words, no text, no black background, no boundary or frame."; String style = split[0].trim();
if ("Lolita".equals( style)){
style = "洛丽塔";
}
String userPrompt = split[1];
String prompt = userPrompt + "rules:front view sketch only,plain white background, single garment only, orthographic, centered on white background, borderless canvas, thin monochrome black line art.\n" +
" No clothes hanger, no fake clothes hanger, no human-related lines, no color fill, no words, no text, no black background, no boundary or frame.sketch style:"+ style;
modelAndPromptMap.put(ModelConstants.PROMPT, prompt); modelAndPromptMap.put(ModelConstants.PROMPT, prompt);
if (isUseImage) { if (isUseImage) {
if (ModelConstants.ADVANCED.equals(modelName)) { if (ModelConstants.ADVANCED.equals(modelName)) {