1、design single 添加 design elements
2、design single -- print添加level2Type 3、替换部分flask接口 为 fastAPI接口
This commit is contained in:
@@ -67,7 +67,7 @@ public class PythonService {
|
||||
@Value("${access.python.port:''}")
|
||||
private String accessPythonPort;
|
||||
@Value("${access.python.address}")
|
||||
private String srPythonPort;
|
||||
private String fastApiPythonAddress;
|
||||
@Value("${minio.bucketName.gradient}")
|
||||
private String gradientBucketName;
|
||||
|
||||
@@ -270,13 +270,13 @@ public class PythonService {
|
||||
private void updateSketchNumbers(CurrentDesignPictureTypeEnum designPictureType, int[] sketchNumbers) {
|
||||
switch (designPictureType) {
|
||||
case PIN:
|
||||
sketchNumbers[0] ++;
|
||||
sketchNumbers[0]++;
|
||||
break;
|
||||
case NO_PIN:
|
||||
sketchNumbers[2] --;
|
||||
sketchNumbers[2]--;
|
||||
break;
|
||||
case SYS_FILE:
|
||||
sketchNumbers[1] --;
|
||||
sketchNumbers[1]--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -316,7 +316,7 @@ public class PythonService {
|
||||
Long l = RandomsUtil.randomSysFile(0l, 2l);
|
||||
if (l == 0l) {
|
||||
return CurrentDesignPictureTypeEnum.NO_PIN;
|
||||
}else {
|
||||
} else {
|
||||
return CurrentDesignPictureTypeEnum.SYS_FILE;
|
||||
}
|
||||
}
|
||||
@@ -793,6 +793,7 @@ public class PythonService {
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_recognition")
|
||||
// .url(fastApiPythonAddress + "/api/attribute_recognition")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
@@ -835,6 +836,7 @@ public class PythonService {
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_recognition")
|
||||
// .url(fastApiPythonAddress + "/api/attribute_recognition")
|
||||
.method("POST", body)
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
@@ -2358,7 +2360,8 @@ public class PythonService {
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design")
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/design")
|
||||
.url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
@@ -2464,7 +2467,8 @@ public class PythonService {
|
||||
System.out.println(JSON.toJSONString(content));
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_retrieve")
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_retrieve")
|
||||
.url(fastApiPythonAddress + "/api/attribute_retrieve")
|
||||
// .url(accessPythonIp+":9991/aifda/api/v1.0/attribute_retrieval")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
@@ -2611,22 +2615,22 @@ public class PythonService {
|
||||
|
||||
designSingleItemList.forEach(designSingleItem -> {
|
||||
Long businessId;
|
||||
if (!designSingleIncludeLayersDTO.getIsPreview() && designSingleItem.getChanged()){
|
||||
if (!designSingleIncludeLayersDTO.getIsPreview() && designSingleItem.getChanged()) {
|
||||
String s = String.valueOf(designSingleItem.getId());
|
||||
businessId = Long.parseLong(s.substring(0,s.length() - 3));
|
||||
}else {
|
||||
businessId = Long.parseLong(s.substring(0, s.length() - 3));
|
||||
} else {
|
||||
businessId = designSingleItem.getId();
|
||||
}
|
||||
|
||||
// 判断是否是渐变色
|
||||
String minioPath = null;
|
||||
String gradientString = null;
|
||||
if (!Objects.isNull(designSingleItem.getGradient())){
|
||||
if (!Objects.isNull(designSingleItem.getGradient())) {
|
||||
String colorImg = designSingleItem.getGradient().getColorImg();
|
||||
if (StringUtil.isNullOrEmpty(colorImg)){
|
||||
if (StringUtil.isNullOrEmpty(colorImg)) {
|
||||
throw new BusinessException("The base64 data of the image is empty");
|
||||
}
|
||||
minioPath = minioUtil.base64UploadToPath(colorImg, gradientBucketName,null);
|
||||
minioPath = minioUtil.base64UploadToPath(colorImg, gradientBucketName, null);
|
||||
designSingleItem.getGradient().setColorImg(null);
|
||||
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());
|
||||
|
||||
@@ -2637,7 +2641,8 @@ public class PythonService {
|
||||
designSingleItem.getType(),
|
||||
designSingleItem.getPath(),
|
||||
designSingleItem.getColor(),
|
||||
resolveDesignSinglePrint(designSingleItem.getPrintObject(), designSingleItem.getPath()),
|
||||
resolveDesignSinglePrint(designSingleItem.getPrintObject(), null),
|
||||
resolveDesignElement(designSingleItem.getTrims()),
|
||||
// businessId designItemDetailId (python端确认没有作用,但是数据库需要存,作用:未知)
|
||||
// designSingleItem.getId(),
|
||||
businessId,
|
||||
@@ -2669,21 +2674,24 @@ public class PythonService {
|
||||
}
|
||||
DesignPythonItemPrint print = CopyUtil.copyObject(printObject, DesignPythonItemPrint.class);
|
||||
|
||||
List<List<Double>> location = new ArrayList<>(printObject.getPrints().size());
|
||||
List<Double> scale = new ArrayList<>(printObject.getPrints().size());
|
||||
List<Double> angle = new ArrayList<>(printObject.getPrints().size());
|
||||
ArrayList<String> paths = new ArrayList<>(printObject.getPrints().size());
|
||||
int size = printObject.getPrints().size();
|
||||
// 占位符填充数组
|
||||
List<List<Double>> location = new ArrayList<>(Collections.nCopies(size, null));
|
||||
List<Double> scale = new ArrayList<>(Collections.nCopies(size, null));
|
||||
List<Double> angle = new ArrayList<>(Collections.nCopies(size, null));
|
||||
ArrayList<String> paths = new ArrayList<>(Collections.nCopies(size, null));
|
||||
|
||||
// 设置印花的位置、大小、旋转角度
|
||||
// 优先级越大,越靠近顶层,在传输给python的数组中,越靠前
|
||||
List<DesignSinglePrint> prints = printObject.getPrints();
|
||||
prints.forEach(p -> {
|
||||
p.getLocation().set(0, p.getLocation().get(0));
|
||||
p.getLocation().set(1, p.getLocation().get(1));
|
||||
Integer priority = p.getPriority();
|
||||
location.add(priority - 1, p.getLocation());
|
||||
scale.add(priority - 1, p.getScale());
|
||||
angle.add(priority - 1, p.getAngle());
|
||||
paths.add(priority - 1, p.getMinIOPath());
|
||||
location.set(size - priority, p.getLocation());
|
||||
scale.set(size - priority, p.getScale());
|
||||
angle.set(size - priority, p.getAngle());
|
||||
paths.set(size - priority, p.getMinIOPath());
|
||||
// log.info("本次print打点locations###{}###fileVO{}", p.getLocation(), JSON.toJSONString(fileVO));
|
||||
});
|
||||
print.setLocation(location);
|
||||
@@ -2694,6 +2702,41 @@ public class PythonService {
|
||||
return print;
|
||||
}
|
||||
|
||||
private DesignPythonItemElement resolveDesignElement(DesignSinglePrintDTO trims) {
|
||||
// 没有design element 时的参数设置
|
||||
if (Objects.isNull(trims.getIfSingle()) && CollectionUtil.isEmpty(trims.getPrints())) {
|
||||
return null;
|
||||
}
|
||||
DesignPythonItemElement print = new DesignPythonItemElement();
|
||||
|
||||
int size = trims.getPrints().size();
|
||||
// 占位符填充数组
|
||||
List<List<Double>> location = new ArrayList<>(Collections.nCopies(size, null));
|
||||
List<Double> scale = new ArrayList<>(Collections.nCopies(size, null));
|
||||
List<Double> angle = new ArrayList<>(Collections.nCopies(size, null));
|
||||
ArrayList<String> paths = new ArrayList<>(Collections.nCopies(size, null));
|
||||
|
||||
// 设置印花的位置、大小、旋转角度
|
||||
// 优先级越大,越靠近顶层,在传输给python的数组中,越靠前
|
||||
List<DesignSinglePrint> prints = trims.getPrints();
|
||||
prints.forEach(p -> {
|
||||
p.getLocation().set(0, p.getLocation().get(0));
|
||||
p.getLocation().set(1, p.getLocation().get(1));
|
||||
Integer priority = p.getPriority();
|
||||
location.set(size - priority, p.getLocation());
|
||||
scale.set(size - priority, p.getScale());
|
||||
angle.set(size - priority, p.getAngle());
|
||||
paths.set(size - priority, p.getMinIOPath());
|
||||
// log.info("本次print打点locations###{}###fileVO{}", p.getLocation(), JSON.toJSONString(fileVO));
|
||||
});
|
||||
print.setLocation(location);
|
||||
print.setElement_scale_list(scale);
|
||||
print.setElement_angle_list(angle);
|
||||
print.setElement_path_list(paths);
|
||||
|
||||
return print;
|
||||
}
|
||||
|
||||
private DesignPythonBasic coverToSingleBasic(DesignPythonItem designPythonItem, String singleOverall,
|
||||
String switchCategory, List<String> priority,
|
||||
DesignLibraryModelPointVO designLibraryModelPoint) {
|
||||
@@ -2856,6 +2899,7 @@ public class PythonService {
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design")
|
||||
// .url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
@@ -2953,7 +2997,7 @@ public class PythonService {
|
||||
// .url("http://127.0.0.1:5000/api/diffusion")
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion")
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_image")
|
||||
.url(srPythonPort + servicePath)
|
||||
.url(fastApiPythonAddress + servicePath)
|
||||
.method("POST", body)
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
@@ -2997,7 +3041,7 @@ public class PythonService {
|
||||
log.info("Generate##responseObject###{}", jsonObject);
|
||||
// return setGenerateImageList(jsonObject.getJSONObject("data"));
|
||||
return Boolean.TRUE;
|
||||
}else {
|
||||
} else {
|
||||
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
|
||||
log.info("Generate Exception! Code : " + jsonObject.get("code"));
|
||||
return Boolean.FALSE;
|
||||
@@ -3016,6 +3060,7 @@ public class PythonService {
|
||||
RequestBody body = RequestBody.create(mediaType, content);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + portAndRoute)
|
||||
// .url(fastApiPythonAddress + portAndRoute)
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
@@ -3036,13 +3081,13 @@ public class PythonService {
|
||||
List<String> imageUrlList = JSONObject.parseArray(jsonObject.get("list").toString(), String.class);
|
||||
if (imageUrlList.isEmpty()) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", "diffusion response list is null");
|
||||
// todo 如果这里返回为空,是判断出错还是返回给前端空
|
||||
// 如果这里返回为空,是判断出错还是返回给前端空
|
||||
throw new BusinessException("The data returned on the python side is empty");
|
||||
}
|
||||
|
||||
return imageUrlList;
|
||||
}
|
||||
|
||||
/** 废弃状态 */
|
||||
public String composeLayers(List<OutfitDetailPythonItem> layersDetail) {
|
||||
HashMap<String, List<OutfitDetailPythonItem>> layers = new HashMap<>();
|
||||
HashMap<String, HashMap<String, List<OutfitDetailPythonItem>>> content = new HashMap<>();
|
||||
@@ -3135,7 +3180,8 @@ public class PythonService {
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId;
|
||||
// String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId;
|
||||
String url = fastApiPythonAddress + "/api/generate_cancel/" + taskId;
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
@@ -3177,7 +3223,7 @@ public class PythonService {
|
||||
String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty);
|
||||
RequestBody body = RequestBody.create(mediaType, jsonString);
|
||||
Request request = new Request.Builder()
|
||||
.url(srPythonPort + "/api/super_resolution")
|
||||
.url(fastApiPythonAddress + "/api/super_resolution")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
@@ -3217,6 +3263,7 @@ public class PythonService {
|
||||
RequestBody body = RequestBody.create(mediaType, jsonString);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/translateToEN")
|
||||
// .url(fastApiPythonAddress + "/api/translateToEN")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
|
||||
@@ -28,15 +28,20 @@ public class DesignPythonItem {
|
||||
*/
|
||||
private String color;
|
||||
|
||||
// private String gradient;
|
||||
private String gradient;
|
||||
|
||||
// private String gradientString;
|
||||
private String gradientString;
|
||||
|
||||
/**
|
||||
* 对应的print图片的绝对路径
|
||||
*/
|
||||
private DesignPythonItemPrint print;
|
||||
|
||||
/**
|
||||
* trims 衣服上的装饰
|
||||
*/
|
||||
private DesignPythonItemElement element;
|
||||
|
||||
/**
|
||||
* 对应的icon的绝对路径
|
||||
*/
|
||||
@@ -113,20 +118,21 @@ public class DesignPythonItem {
|
||||
this.image_id = image_id;
|
||||
}
|
||||
|
||||
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, Long businessId,
|
||||
Long image_id, List<Long> offset, Float[] resize_scale, Integer priority) {
|
||||
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, DesignPythonItemElement element, Long businessId,
|
||||
Long image_id, List<Long> offset, Float[] resize_scale, Integer priority, String gradient, String gradientString) {
|
||||
this.type = type;
|
||||
this.path = path;
|
||||
this.color = color;
|
||||
this.print = print;
|
||||
this.element = element;
|
||||
// this.icon = icon;
|
||||
this.businessId = businessId;
|
||||
this.image_id = image_id;
|
||||
this.offset = offset;
|
||||
this.resize_scale = resize_scale;
|
||||
this.priority = priority;
|
||||
// this.gradient = gradient;
|
||||
// this.gradientString = gradientString;
|
||||
this.gradient = gradient;
|
||||
this.gradientString = gradientString;
|
||||
}
|
||||
|
||||
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, String icon, Long businessId, Long image_id) {
|
||||
|
||||
Reference in New Issue
Block a user