diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 5ef07e16..4538c4d4 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -39,6 +39,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; import jakarta.annotation.Resource; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -279,7 +280,7 @@ public class PythonService { if (isDuplicate) { elementVO.setHasUseMd5List(beforeAssemblyHasUseMd5List); - i --; + i--; switch (designPrintPictureType) { case PIN: @@ -406,13 +407,14 @@ public class PythonService { // if (CollectionUtil.isEmpty(pinData)) { // return 0; // } -//// long topNum = sketchBoardElements.stream() -//// .filter(skecth -> skecth.getHasPin() == 1 -//// && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count(); -//// long bottomNum = sketchBoardElements.stream() -//// .filter(skecth -> skecth.getHasPin() == 1 -//// && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count(); -//// int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue(); + + /// / long topNum = sketchBoardElements.stream() + /// / .filter(skecth -> skecth.getHasPin() == 1 + /// / && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count(); + /// / long bottomNum = sketchBoardElements.stream() + /// / .filter(skecth -> skecth.getHasPin() == 1 + /// / && 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(); // return Math.min(num, 8); // } @@ -560,12 +562,12 @@ public class PythonService { return 0; } else { long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count(); - if (designNum - pinNum < 0){ - return RandomsUtil.randomSysFile(0L, (long) (pinNum/2 + 1)); - } else if (designNum - pinNum < designNum/2) { + if (designNum - pinNum < 0) { + return RandomsUtil.randomSysFile(0L, (long) (pinNum / 2 + 1)); + } else if (designNum - pinNum < designNum / 2) { return RandomsUtil.randomSysFile(0L, designNum - pinNum + 1); } 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(); - List recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale(),elementVO.getStyle()); - + List 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)) { throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); } @@ -1039,7 +1043,7 @@ public class PythonService { if (!CollectionUtils.isEmpty(recommentdUrlList)) { String recommendSystemSketch = recommentdUrlList.get(0); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); - }else { + } else { throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); } // JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex()); @@ -1062,7 +1066,7 @@ public class PythonService { if (!CollectionUtils.isEmpty(recommentdUrlList)) { String recommendSystemSketch = recommentdUrlList.get(0); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); - }else { + } else { throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); } @@ -1098,7 +1102,7 @@ public class PythonService { if (!CollectionUtils.isEmpty(recommentdUrlList)) { String recommendSystemSketch = recommentdUrlList.get(0); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); - }else { + } else { throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); } // JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex()); @@ -1122,7 +1126,7 @@ public class PythonService { if (!CollectionUtils.isEmpty(recommentdUrlList)) { String recommendSystemSketch = recommentdUrlList.get(0); return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO); - }else { + } else { throw new BusinessException("failed.to.obtain.system.sketch.recommendation"); } // String tableName = getTableName(validateElementVO.getModelSex(), category); @@ -2190,7 +2194,7 @@ public class PythonService { basic.setScale_earrings(0.16); if (Objects.nonNull(designLibraryModelPointVO)) { basic.setBody_point_test(getMap(designLibraryModelPointVO)); - }else { + } else { basic.setBody_point_test(getMap(designLibraryModelPoint)); } return basic; @@ -2857,7 +2861,7 @@ public class PythonService { /*PrintToPython printToPython = resolveDesignSinglePrint(designSingleItem.getPrintObject().getPrints(), designSingleItem.getPartialDesign().getPartialDesignMinioPath());*/ // resolveDesignElement(designSingleItem.getTrims(), printToPython); - log.info("组装参数【服装:{}的maskUrl: {}】",designSingleItem.getType(), designSingleItem.getMaskUrl()); + log.info("组装参数【服装:{}的maskUrl: {}】", designSingleItem.getType(), designSingleItem.getMaskUrl()); String partialDesign = designSingleItem.getPartialDesign().getPartialDesignMinioPath(); String mergeImagePath = !StringUtil.isNullOrEmpty(partialDesign) @@ -2884,7 +2888,7 @@ public class PythonService { }); - if (singleOverall.equals("overall")){ + if (singleOverall.equals("overall")) { String bodyPath; if (Objects.nonNull(designLibraryModelPoint)) { bodyPath = designLibraryModelPoint.getTemplateUrl(); @@ -2905,7 +2909,7 @@ public class PythonService { // printToPython.setSingle(printSingle); printToPython.setOverall(printOverall); printToPython.setPartial(StringUtil.isNullOrEmpty(partialDesign) ? null : partialDesign); - if (Objects.isNull(printObject) || printObject.isEmpty()){ + if (Objects.isNull(printObject) || printObject.isEmpty()) { return printToPython; } @@ -2936,12 +2940,12 @@ public class PythonService { Integer priority = p.getPriority(); setUriToMinioPath(p); // todo 下标越界问题 - if (p.getIfSingle()){ + if (p.getIfSingle()) { locationS.set(priority - 1, p.getLocation()); scaleS.set(priority - 1, p.getScale()); - angleS.set( priority - 1, p.getAngle()); + angleS.set(priority - 1, p.getAngle()); pathsS.set(priority - 1, p.getMinIOPath()); - }else { + } else { locationO.set(priority - 1, p.getLocation()); scaleO.set(priority - 1, p.getScale()); angleO.set(priority - 1, p.getAngle()); @@ -2971,9 +2975,9 @@ public class PythonService { } // 对印花类型为Generate的图片路径进行特殊处理 - private void setUriToMinioPath(DesignSinglePrint print){ - if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")){ - if (!StringUtil.isNullOrEmpty(print.getPath())){ + private void setUriToMinioPath(DesignSinglePrint print) { + if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Generate")) { + if (!StringUtil.isNullOrEmpty(print.getPath())) { try { URI uri = new URI(print.getPath()); 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; }*/ - /** 废弃状态 */ + + /** + * 废弃状态 + */ public String composeLayers(List layersDetail) { HashMap> layers = new HashMap<>(); HashMap>> content = new HashMap<>(); @@ -3753,7 +3760,7 @@ public class PythonService { 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() .connectTimeout(30, TimeUnit.SECONDS) .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) @@ -3800,7 +3807,7 @@ public class PythonService { String sketchResult = jsonObject.get("data").toString(); log.info("ImageToSketch 结果 : {}", sketchResult); return sketchResult; - }else { + } else { log.info("ImageToSketch 失败。 Response code {}", responseCode); throw new BusinessException("ImageToSketch 失败。 Response code " + responseCode); } @@ -3853,7 +3860,7 @@ public class PythonService { throw new BusinessException("bright.interface.exception"); } - public JSONObject attributeRecognition(List pictureUrls,List ids, List category) { + public JSONObject attributeRecognition(List pictureUrls, List ids, List category) { //限流校验 AccessLimitUtils.validate("attributeRecognition", 20); OkHttpClient client = new OkHttpClient().newBuilder() @@ -3885,7 +3892,7 @@ public class PythonService { } catch (IOException ioException) { log.error("PythonService###attributeRecognition异常##{}", ExceptionUtil.getThrowableList(ioException)); } - log.info("识别python对应的属性标签值结果###{}",bodyStr.trim()); + log.info("识别python对应的属性标签值结果###{}", bodyStr.trim()); //去除限流 AccessLimitUtils.validateOut("attributeRecognition"); if (Objects.isNull(response)) { @@ -3969,7 +3976,7 @@ public class PythonService { throw new BusinessException("design.interface.exception"); } - public List getSystemSketchByCategory(String category, Long brandId, Double brandScale,String style) { + public List getSystemSketchByCategory(String category, Long brandId, Double brandScale, String style) { //******3.1.2版本临时使用java推荐方案去解决style未使用的问题********** // try { // //使用新库attribute_retrieval_style,表命名修改为elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase()比如female_skirt,与传入的category保持一致 @@ -4114,6 +4121,7 @@ public class PythonService { //生成失败 throw new BusinessException("segProduct.interface.exception"); } + /** * 转发 seg_anything 请求到 python 服务 * 请求 body 由调用方组装(包含 user_id, image_path, type, points, labels, box 等) @@ -4156,18 +4164,18 @@ public class PythonService { if (responseObject != null) { JSONObject dataObj = responseObject.getJSONObject("data"); if (dataObj != null) { - String output = dataObj.getString("output"); - if (!StringUtil.isNullOrEmpty(output)) { - try { - String presigned = minioUtil.getPreSignedUrl(output, 24 * 60); - return presigned; - } catch (Exception e) { - log.error("Failed to generate presigned url for {}: {}", output, e.getMessage()); - throw new BusinessException("segAnything.presign.failed"); - } + String output = dataObj.getString("output"); + if (!StringUtil.isNullOrEmpty(output)) { + try { + String presigned = minioUtil.getPreSignedUrl(output, 24 * 60); + return presigned; + } catch (Exception e) { + log.error("Failed to generate presigned url for {}: {}", output, e.getMessage()); + throw new BusinessException("segAnything.presign.failed"); } } } + } } catch (Exception ex) { log.error("PythonService##segAnything post-process error###{}", ex.getMessage()); @@ -4177,7 +4185,7 @@ public class PythonService { throw new BusinessException("segAnything.missing.output"); } throw new BusinessException("segAnything.interface.exception"); - } catch (IOException |JSONException e) { + } catch (IOException | JSONException e) { log.error("PythonService##segAnything异常###{}", e.getMessage()); throw new BusinessException("segAnything.interface.exception"); } @@ -4185,6 +4193,7 @@ public class PythonService { log.error("PythonService##segAnything异常response###{}", response); throw new BusinessException("segAnything.interface.exception"); } + public Boolean poseTransformation(JSONObject content, String apiUri) { OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(30, TimeUnit.SECONDS) @@ -4288,7 +4297,7 @@ public class PythonService { String modifiedModel = jsonObject.get("data").toString(); log.info("modifyModelProportion 结果 : {}", modifiedModel); return modifiedModel; - }else { + } else { log.info("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()); List seg = JSONObject.parseObject( jsonObject.get("data").toString(), - new TypeReference>() {} + new TypeReference>() { + } ); return seg; - }else { + } else { log.info("imageSegmentation 失败。 Response code {}", responseCode); throw new BusinessException("imageSegmentation 失败。 Response code " + responseCode); } diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 337ef4b6..fa080170 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -1260,8 +1260,14 @@ public class GenerateServiceImpl extends ServiceImpl i modelAndPromptMap.put(ModelConstants.USE_MODEL, ModelConstants.LOCAL_MODEL); } } 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" + - " 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[] split = generateDTO.getText().split(","); + 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); if (isUseImage) { if (ModelConstants.ADVANCED.equals(modelName)) {