diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsEmoVideoSynthesis.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsEmoVideoSynthesis.java index 85715ecf..a4069f53 100644 --- a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsEmoVideoSynthesis.java +++ b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsEmoVideoSynthesis.java @@ -230,7 +230,7 @@ public class DsEmoVideoSynthesis { if ("SUCCEEDED".equals(status)) { // 任务成功,获取视频URL - videoUrl = result.getJSONObject("output").getString("url"); + videoUrl = result.getJSONObject("output").getJSONObject("results").getString("video_url"); log.info("生成的视频URL: {}", videoUrl); break; } else if ("FAILED".equals(status)) { diff --git a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsFaceDetect.java b/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsFaceDetect.java deleted file mode 100644 index 541d4aad..00000000 --- a/dsAiSupport/src/main/java/com/dsideal/aiSupport/Util/DashScope/DsFaceDetect.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.dsideal.aiSupport.Util.DashScope; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.dsideal.aiSupport.Plugin.YamlProp; -import com.jfinal.kit.Prop; -import lombok.SneakyThrows; -import okhttp3.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.concurrent.TimeUnit; - -import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix; - -/** - * 阿里云达摩院人脸检测API工具类 - */ -public class DsFaceDetect { - private static final Logger log = LoggerFactory.getLogger(DsFaceDetect.class); - private static final String API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/face-detect"; - private static final String API_KEY; - - public static Prop PropKit; // 配置文件工具 - - static { - //加载配置文件 - String configFile = "application_{?}.yaml".replace("{?}", getEnvPrefix()); - PropKit = new YamlProp(configFile); - API_KEY = PropKit.get("aliyun.API_KEY"); - } - - /** - * 调用人脸检测API - * - * @param imageUrl 图片URL - * @param ratio 比例,例如"1:1" - * @return 检测结果JSON对象 - * @throws Exception 异常信息 - */ - @SneakyThrows - public static JSONObject detectFace(String imageUrl, String ratio) { - // 创建OkHttpClient,设置超时时间 - OkHttpClient client = new OkHttpClient().newBuilder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) - .writeTimeout(30, TimeUnit.SECONDS) - .build(); - - // 构建请求体 - JSONObject requestBody = new JSONObject(); - requestBody.put("model", "emo-detect-v1"); - - // 设置输入参数 - JSONObject input = new JSONObject(); - input.put("image_url", imageUrl); - requestBody.put("input", input); - - // 设置其他参数 - JSONObject parameters = new JSONObject(); - parameters.put("ratio", ratio); - requestBody.put("parameters", parameters); - - // 创建请求 - MediaType mediaType = MediaType.parse("application/json"); - RequestBody body = RequestBody.create(mediaType, requestBody.toJSONString()); - Request request = new Request.Builder() - .url(API_URL) - .method("POST", body) - .addHeader("Content-Type", "application/json") - .addHeader("Authorization", "Bearer " + API_KEY) - .build(); - - // 发送请求并获取响应 - log.info("发送人脸检测请求: {}", requestBody.toJSONString()); - Response response = client.newCall(request).execute(); - - // 检查响应状态 - if (!response.isSuccessful()) { - String errorMsg = "人脸检测API请求失败,状态码: " + response.code(); - log.error(errorMsg); - throw new Exception(errorMsg); - } - - // 解析响应 - String responseBody = response.body().string(); - log.info("人脸检测响应: {}", responseBody); - - return JSON.parseObject(responseBody); - } - - /** - * 使用示例 - */ - @SneakyThrows - public static void main(String[] args) { - //EMO-detect模型,用于确认输入的人物肖像图片是否符合EMO视频生成模型的输入规范。本文档介绍了该模型提供的图像检测能力的API调用方法。 - // 图片URL - String imageUrl = "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/BlogImages/202505131058596.png"; - // 比例 - String ratio = "1:1"; - - // 调用人脸检测API - JSONObject result = detectFace(imageUrl, ratio); - - // 处理结果 - System.out.println("检测结果: " + result.toJSONString()); - } -} \ No newline at end of file