TASK: 新增pose transfer模特姿势选项
This commit is contained in:
72
src/main/java/com/ai/da/common/enums/PoseEnum.java
Normal file
72
src/main/java/com/ai/da/common/enums/PoseEnum.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.ai.da.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum PoseEnum {
|
||||
|
||||
POSE_1(1L, "aida-sys-image/pose/pose-1.mp4", "aida-sys-image/pose/pose-1.gif", "aida-sys-image/pose/pose-1-first_frame.jpeg", "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j"),
|
||||
POSE_2(2L, "aida-sys-image/pose/pose-2.mp4", "aida-sys-image/pose/pose-2.gif", "aida-sys-image/pose/pose-2-first_frame.jpeg", "AACT.8090e67b.TwJLxEv3EfCbDTI_rjSH-A.IOQZCYhf"),
|
||||
POSE_3(3L, "aida-sys-image/pose/pose-3.mp4", "aida-sys-image/pose/pose-3.gif", "aida-sys-image/pose/pose-3-first_frame.jpeg", "AACT.8090e67b.gd3OCkv4EfCxyZo8eQGF2Q.qMm-a1XI"),
|
||||
POSE_4(4L, "aida-sys-image/pose/pose-4.mp4", "aida-sys-image/pose/pose-4.gif", "aida-sys-image/pose/pose-4-first_frame.jpeg", "AACT.8090e67b.AUDnuEwDEfCEHBaRJeW4dg.rlx36xEY"),
|
||||
POSE_5(5L, "aida-sys-image/pose/pose-5.mp4", "aida-sys-image/pose/pose-5.gif", "aida-sys-image/pose/pose-5-first_frame.jpeg", "AACT.8090e67b.G8BvkEwEEfCxyZo8eQGF2Q.fo4ryrgR"),
|
||||
POSE_6(6L, "aida-sys-image/pose/pose-6.mp4", "aida-sys-image/pose/pose-6.gif", "aida-sys-image/pose/pose-6-first_frame.jpeg", "AACT.8090e67b.yBIPnEwEEfCxyZo8eQGF2Q.boSFwTG9");
|
||||
|
||||
|
||||
private final Long id;
|
||||
|
||||
private final String videoPath;
|
||||
|
||||
private final String gifPath;
|
||||
|
||||
private final String firstFramePath;
|
||||
|
||||
private final String templateId;
|
||||
|
||||
private static final List<Map<String, String>> PROPERTY_LIST;
|
||||
|
||||
static {
|
||||
PROPERTY_LIST = Arrays.stream(values())
|
||||
.map(PoseEnum::toMap)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static final Map<Long, PoseEnum> BY_ID = Arrays.stream(values())
|
||||
.collect(Collectors.toMap(PoseEnum::getId, Function.identity()));
|
||||
|
||||
private static final Map<String, PoseEnum> BY_VIDEO_PATH = Arrays.stream(values())
|
||||
.collect(Collectors.toMap(PoseEnum::getVideoPath, Function.identity()));
|
||||
|
||||
private static final List<String> VIDEO_PATH = Arrays.stream(values())
|
||||
.map(PoseEnum::getVideoPath).collect(Collectors.toList());
|
||||
|
||||
public static PoseEnum getById(Long id) {
|
||||
return BY_ID.get(id);
|
||||
}
|
||||
|
||||
public static PoseEnum getByVideoPath(String videoPath) {
|
||||
return BY_VIDEO_PATH.get(videoPath);
|
||||
}
|
||||
|
||||
private Map<String, String> toMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("id", String.valueOf(id));
|
||||
map.put("gif", gifPath);
|
||||
map.put("firstFrame", firstFramePath);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> getPropertyList() {
|
||||
return new ArrayList<>(PROPERTY_LIST); // 返回副本以保证不可变性
|
||||
}
|
||||
|
||||
public static List<String> getVideoList() {
|
||||
return new ArrayList<>(VIDEO_PATH); // 返回副本以保证不可变性
|
||||
}
|
||||
}
|
||||
@@ -498,8 +498,6 @@ public class RedisUtil {
|
||||
|
||||
public final static String STRIPE_EXCEPTION_LOG = "StripeException:";
|
||||
|
||||
public final static String ANIMATE_ANYONE_TEMPLATE_ID = "AnimateAnyoneTemplateId:";
|
||||
|
||||
public void batchDeleteKeysWithSamePrefix(String prefix){
|
||||
Set<String> keys = redisTemplate.keys(prefix + "*");
|
||||
assert keys != null;
|
||||
|
||||
@@ -1416,13 +1416,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getAllPose(){
|
||||
String posePath = "aida-sys-image/pose/pose-1.gif";
|
||||
String firstFramePath = "aida-sys-image/pose/pose-1-first_frame.jpeg";
|
||||
HashMap<String, String> resp = new HashMap<>();
|
||||
// todo 以后要返回poseId
|
||||
resp.put("gif", minioUtil.getPreSignedUrl(posePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
resp.put("firstFrame", minioUtil.getPreSignedUrl(firstFramePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
return Arrays.asList(resp);
|
||||
List<Map<String, String>> propertyList = PoseEnum.getPropertyList();
|
||||
propertyList.forEach(item -> {
|
||||
item.put("gif", minioUtil.getPreSignedUrl(item.get("gif"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
item.put("firstFrame", minioUtil.getPreSignedUrl(item.get("firstFrame"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
});
|
||||
return propertyList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1687,13 +1686,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
// 轮询配置
|
||||
private static final int MAX_RETRIES = 30; // 最大重试次数
|
||||
private static final int POLL_INTERVAL = 2000; // 轮询间隔(毫秒)
|
||||
private static final int POLL_INTERVAL = 20000; // 轮询间隔(毫秒)
|
||||
|
||||
public String getVideoTemplateId(String videoPath){
|
||||
String key = RedisUtil.ANIMATE_ANYONE_TEMPLATE_ID + videoPath;
|
||||
String templateId = redisUtil.getFromString(key);
|
||||
boolean contains = PoseEnum.getVideoList().contains(videoPath);
|
||||
|
||||
if (StringUtil.isNullOrEmpty(templateId)){
|
||||
String templateId;
|
||||
if (!contains){
|
||||
String videoUrl = minioUtil.getPreSignedUrl(videoPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
JSONObject requestBody = new JSONObject();
|
||||
requestBody.set("model", "animate-anyone-template-gen2");
|
||||
@@ -1703,8 +1702,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
requestBody.set("input", input);
|
||||
requestBody.set("parameters", parameters);
|
||||
|
||||
String resp = sendRequestUtil.sendPost(TEMPLATE_ID_GEN, requestBody.toString());
|
||||
|
||||
log.info("获取pose的模板id 请求数据:{}", requestBody);
|
||||
String resp = sendRequestUtil.sendAliYunPostAsync(TEMPLATE_ID_GEN, requestBody.toString());
|
||||
if (StringUtil.isNullOrEmpty(resp)){
|
||||
throw new BusinessException("请求获取video template id失败");
|
||||
}
|
||||
@@ -1719,7 +1718,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
throw new BusinessException("获取动作模板失败");
|
||||
}
|
||||
// templateId = "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j";
|
||||
redisUtil.addToString(key, templateId);
|
||||
} else {
|
||||
templateId = PoseEnum.getByVideoPath(videoPath).getTemplateId();
|
||||
}
|
||||
|
||||
return templateId;
|
||||
|
||||
Reference in New Issue
Block a user