Merge remote-tracking branch 'origin/develop' into dev_shb

# Conflicts:
#	src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
This commit is contained in:
shahaibo
2023-09-13 10:34:09 +08:00
101 changed files with 1597 additions and 346 deletions

View File

@@ -145,6 +145,28 @@ public class PythonService {
return null;
}
@Transactional
public List<String> upload(MultipartFile[] files, String operateType) {
List<String> paths = new ArrayList<>();
//用户信息
PythonToJavaApiOperationTypeEnum operationType = PythonToJavaApiOperationTypeEnum.uploadOf(operateType);
Assert.notNull(operationType, "unknown operateType " + operateType + "!");
String path = calculateFileUrl(operationType);
for (MultipartFile file : files) {
File generateFile = FileUtil.upload2(file, path);
Assert.notNull(generateFile,"An error occurred while processing the file, please try again later");
String linuxDomain = fileProperties.getLinuxDomain();
if (!StringUtils.isEmpty(linuxDomain)) {
//linux 系统
String oldPath = fileProperties.getSys().getPath();
paths.add(generateFile.getAbsolutePath().replace(oldPath, linuxDomain));
}
}
return paths;
}
private String calculateFileUrl(PythonToJavaApiOperationTypeEnum operationType) {
String rootPath = fileProperties.getSys().getPath();
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
@@ -1448,4 +1470,123 @@ public class PythonService {
//生成失败
throw new BusinessException("generate design exception!");
}
public String generateSketchCaption(String url) {
//限流校验
AccessLimitUtils.validate("generateSketchCaption",5);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, url);
Request request = new Request.Builder()
.url(accessPythonIp+":2828/aida/interrogator")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyStr = null;
try {
log.info("generateSketchCaption请求入参content###{}", url);
response = client.newCall(request).execute();
bodyStr = response.body().string();
} catch (IOException ioException) {
log.error("generateSketchCaption异常###{}", ExceptionUtil.getThrowableList(ioException));
}
//去除限流
AccessLimitUtils.validateOut("generateSketchCaption");
if (Objects.isNull(response)) {
log.error("generateSketchCaption异常###{}", "response or body is empty!");
throw new BusinessException("system error!");
}
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
Boolean result = jsonObject.getBoolean("successful");
if (result) {
return bodyStr;
}
log.info("attribute_retrieval失败###{}", bodyStr);
//生成失败
throw new BusinessException("system error!");
}
public String generateSketchOrPrint(String url, String text, int mode, String modelName) {
//限流校验
AccessLimitUtils.validate("generateSketchOrPrint",5);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
Map<String, Object> content = Maps.newHashMap();
content.put("img_url", url);
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")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyString = null;
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));
}
//去除限流
AccessLimitUtils.validateOut("generateSketchOrPrint");
if (Objects.isNull(response)) {
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("generateSketchOrPrintPrint失败###{}", jsonObject);
//生成失败
throw new BusinessException("generateSketchOrPrint exception!");
}
public String sendPostToModel(Map<String,Object> content,String portAndRoute,String functionName){
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
Request request = new Request.Builder()
.url(accessPythonIp + ":" + portAndRoute)
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyString = null;
try {
log.info(functionName + "请求入参content###{}", JSON.toJSONString(content));
response = client.newCall(request).execute();
bodyString = response.body().string();
} catch (IOException ioException) {
log.error("PythonService##"+ functionName +"异常###{}", ExceptionUtil.getThrowableList(ioException));
}
return bodyString;
}
}