BUGFIX: toProductImage、relight;

This commit is contained in:
shahaibo
2025-02-13 11:06:19 +08:00
parent 34ee8fa11d
commit 7fdf832f44
4 changed files with 129 additions and 3 deletions

View File

@@ -36,13 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import static cn.hutool.poi.excel.sax.AttributeName.s;
/**
* 服务实现类
*
@@ -343,6 +340,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -365,6 +363,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -378,6 +378,66 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void toProduct(String taskId) {
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(toProductImageResults)) {
ToProductImageResult toProductImageResultOne = toProductImageResults.get(0);
ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResultOne.getToProductImageRecordId());
String prompt = toProductImageRecord.getPrompt();
StringBuilder sb = new StringBuilder("The best quality, masterpiece, real image.");
if (!StringUtil.isNullOrEmpty(prompt)) {
prompt = pythonService.promptTranslate(prompt);
}
String elementType = toProductImageResultOne.getElementType();
if (elementType.equals("DesignOutfit")) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultOne.getElementId());
Long designItemId = tDesignPythonOutfit.getDesignItemId();
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemId);
designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body");
List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
String collect = designItemDetails.stream().map(DesignItemDetail::getType).collect(Collectors.joining(","));
Long designId = tDesignPythonOutfit.getDesignId();
Design design = designMapper.selectById(designId);
String productType = "overall";
if (design.getSingleOverall().equals("single")) {
productType = "single";
sb.append(collect);
}else {
if (collect.contains("Tops")) {
sb.append("a handsome man,");
}else {
sb.append("a beautiful women,");
}
sb.append("wearing ").append(collect);
}
if (StringUtils.isEmpty(prompt)) {
sb.append(",high quality clothing details,8K realistic,HDR");
}else {
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
}
// 走模型
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, sb.toString(), toProductImageResultOne.getImageStrength(), "single");
}else {
if (StringUtils.isEmpty(prompt)) {
sb.append(",high quality clothing details,8K realistic,HDR");
}else {
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
}
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultOne.getElementId());
// 走模型
pythonService.toProductImage(toProductElement.getUrl(), taskId, sb.toString(), toProductImageResultOne.getImageStrength(), "single");
}
}
}
@Resource
private ToProductElementMapper toProductElementMapper;
@@ -535,6 +595,48 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return Boolean.TRUE;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void relight(String taskId) {
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(toProductImageResults)) {
ToProductImageResult toProductImageResultOne = toProductImageResults.get(0);
ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResultOne.getToProductImageRecordId());
String prompt = toProductImageRecord.getPrompt();
// 翻译
String s = "";
if (!StringUtil.isNullOrEmpty(prompt)) {
s = pythonService.promptTranslate(prompt);
}else {
s = "Snow moutain, snowy day, natural light";
}
String elementType = toProductImageResultOne.getElementType();
if (elementType.equals("ToProductImage")) {
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultOne.getElementId());
String relightType = "overall";
if (toProductImageResult1.getElementType().equals("DesignOutfit")) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult1.getElementId());
Long designId = tDesignPythonOutfit.getDesignId();
Design design = designMapper.selectById(designId);
if (design.getSingleOverall().equals("single")) {
relightType = "single";
}
}
// 走模型
pythonService.relight(toProductImageResult1.getUrl(), taskId, s, toProductImageResultOne.getDirection(), "single");
}else {
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultOne.getElementId());
// 走模型
pythonService.relight(toProductElement.getUrl(), taskId, s, toProductImageResultOne.getDirection(), "single");
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) {
@@ -594,6 +696,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -609,9 +712,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);