From d418df3c609b770f71aca4eeffb1701863f20bf8 Mon Sep 17 00:00:00 2001 From: xupei <1779019091@qq.com> Date: Tue, 19 Sep 2023 10:25:03 +0800 Subject: [PATCH] =?UTF-8?q?generate=20=E6=8E=A5=E5=8F=A3=E7=96=8F=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/python/PythonService.java | 44 ++++++++++++------- .../da/service/impl/GenerateServiceImpl.java | 9 +++- .../resources/application-test.properties | 1 + 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index cb8ac052..1f6313a5 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -1638,7 +1638,7 @@ public class PythonService { content.put("category", category); content.put("mode",mode); // content.put("str", text); - content.put("version",modelName); + content.put("version",2); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); Request request = new Request.Builder() // .url(accessPythonIp + ":2828/aida/diffusion") @@ -1650,24 +1650,34 @@ public class PythonService { .build(); Response response = null; String bodyString = null; - try { +// try { log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content)); - response = client.newCall(request).execute(); - bodyString = response.body().string(); - } catch (IOException ioException) { - log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); - } +// response = client.newCall(request).execute(); +// bodyString = response.body().string(); + bodyString = "{\n" + + " \"code\": 200,\n" + + " \"data\": {\n" + + " \"list\": [\n" + + " \"12/print_1695088687_0.png\"\n" + + " ]\n" + + " },\n" + + " \"msg\": \"OK!\"\n" + + "}"; +// } catch (IOException ioException) { +// log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); +// } //去除限流 AccessLimitUtils.validateOut("generateSketchOrPrint"); // 生成失败 - if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) { - log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!"); - throw new BusinessException("generate exception!"); - } - JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(bodyString)); - Boolean result = jsonObject.getBoolean("successful"); +// if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) { +// log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!"); +// throw new BusinessException("generate exception!"); +// } + JSONObject jsonObject = JSON.parseObject(bodyString); +// Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); + Boolean result = Boolean.TRUE; if (result) { - return setGenerateImageList(jsonObject.getJSONObject("date")); + return setGenerateImageList(jsonObject.getJSONObject("data")); } log.info("generateSketchOrPrintPrint失败###{}", jsonObject); //生成失败 @@ -1703,13 +1713,13 @@ public class PythonService { } private static List setGenerateImageList(JSONObject jsonObject){ - if (Objects.isNull(jsonObject.getJSONObject("list"))){ + List imageUrlList = JSONObject.parseArray(jsonObject.get("list").toString(),String.class); + if (imageUrlList.size() == 0){ log.error("PythonService##generateSketchOrPrint异常###{}","diffusion response list is null"); - // todo 如果这里返回为空,是判断出错还是返回给前端空 throw new BusinessException("Some errors occurred, please try again later"); } - return JSONArray.parseArray(JSONObject.toJSONString(jsonObject.get("list")), String.class); + return imageUrlList; } } 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 8dd79cf9..6f4e809b 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -7,6 +7,7 @@ import com.ai.da.common.enums.GenerateModeEnum; import com.ai.da.common.enums.ModelNameEnum; import com.ai.da.common.utils.DateUtil; import com.ai.da.common.utils.MD5Utils; +import com.ai.da.common.utils.MinioUtil; import com.ai.da.mapper.CollectionElementMapper; import com.ai.da.mapper.GenerateDetailMapper; import com.ai.da.mapper.GenerateMapper; @@ -21,6 +22,7 @@ import com.ai.da.service.LibraryService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import io.netty.util.internal.StringUtil; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -44,6 +46,11 @@ public class GenerateServiceImpl extends ServiceImpl im @Resource private CollectionElementService collectionElementService; + @Resource + private MinioUtil minioUtil; + @Value("${minio.bucketName4}") + private String bucketName4; + @Override public GenerateCaptionVO generateCaption(Long sketchElementId) { CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId); @@ -102,7 +109,7 @@ public class GenerateServiceImpl extends ServiceImpl im GenerateCollectionItemVO generateCollectionItemVO = new GenerateCollectionItemVO(); generateCollectionItemVO.setGenerateItemId(generateDetail.getId()); - generateCollectionItemVO.setGenerateItemUrl(item); + generateCollectionItemVO.setGenerateItemUrl(minioUtil.getPresignedUrl(bucketName4,item,480)); generatedCollectionItems.add(generateCollectionItemVO); }); diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index e076c02c..ffd37423 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -49,6 +49,7 @@ minio.secretKey=minioadmin minio.bucketName=aida-results minio.bucketName2=aida-clothing minio.bucketName3=aida-mannequins +minio.bucketName4=aida-users