Sketchboard与Printboard的generate功能 修改

This commit is contained in:
徐佩
2023-08-18 10:42:08 +08:00
parent c5e5b51852
commit b13feb8f1f
7 changed files with 46 additions and 29 deletions

View File

@@ -1433,7 +1433,7 @@ public class PythonService {
throw new BusinessException("system error!");
}
public String generateSketch(String url,String text) {
public String generateSketchOrPrint(String url, String text, int mode, String modelName) {
//限流校验
AccessLimitUtils.validate("generateSketch",5);
OkHttpClient client = new OkHttpClient().newBuilder()
@@ -1443,9 +1443,11 @@ public class PythonService {
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
Map<String, String> content = Maps.newHashMap();
Map<String, Object> content = Maps.newHashMap();
content.put("img_url", url);
content.put("input", text);
content.put("str", text);
content.put("mode",mode);
content.put("version",modelName);
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
Request request = new Request.Builder()
.url(accessPythonIp + ":2828/aida/diffusion")
@@ -1456,25 +1458,25 @@ public class PythonService {
Response response = null;
String bodyString = null;
try {
log.info("generateSketch请求入参content###{}", JSON.toJSONString(content));
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content));
response = client.newCall(request).execute();
bodyString = response.body().string();
} catch (IOException ioException) {
log.error("PythonService##generateSketch异常###{}", ExceptionUtil.getThrowableList(ioException));
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
}
//去除限流
AccessLimitUtils.validateOut("generateSketch");
AccessLimitUtils.validateOut("generateSketchOrPrint");
if (Objects.isNull(response)) {
log.error("PythonService##generateSketch异常###{}", "response or body is empty!");
throw new BusinessException("generate sketch exception!");
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
throw new BusinessException("generateSketchOrPrint exception!");
}
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
Boolean result = jsonObject.getBoolean("successful");
if (result) {
return bodyString;
}
log.info("generate sketch失败###{}", jsonObject);
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
//生成失败
throw new BusinessException("generate sketch exception!");
throw new BusinessException("generateSketchOrPrint exception!");
}
}