main
HuangHai 2 months ago
parent 9704892500
commit 4c590175bc

@ -3,10 +3,16 @@ package com.dsideal.aiSupport.Util.JiMeng;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class JmImage2Video extends JmCommon {
private static final Logger log = LoggerFactory.getLogger(JmImage2Video.class);
private static final String req_key = "jimeng_vgfm_i2v_l20";
private static final String action = "CVSync2AsyncSubmitTask";
/**
* 使URL
@ -18,7 +24,7 @@ public class JmImage2Video extends JmCommon {
public static JSONObject submitImageToVideoTaskWithUrls(List<String> imageUrls, String prompt) throws Exception {
// 创建请求体
JSONObject req = new JSONObject();
req.put("req_key", "jimeng_vgfm_i2v_l20");
req.put("req_key", req_key);
// 添加图片URL数组
JSONArray urlArray = new JSONArray();
@ -26,29 +32,13 @@ public class JmImage2Video extends JmCommon {
req.put("image_urls", urlArray);
req.put("prompt", prompt);
// 使用JmCommon中的doRequest方法发送请求
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVSync2AsyncSubmitTask");
// 将响应结果转换为JSONObject并返回
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
return JSON.parseObject(responseBody);
}
/**
*
*
* @param taskId ID
* @return
* @throws Exception
*/
public static JSONObject queryTaskResult(String taskId) throws Exception {
return JmQueryTask.queryTaskResult(taskId);
}
public static void main(String[] args) throws Exception {
// 示例2使用图片URL
//17796623341273230793
List<String> imageUrls = new ArrayList<>();
imageUrls.add("https://dsideal.obs.myhuaweicloud.com/HuangHai/%E5%A4%87%E4%BB%BD/%E5%B0%8F%E4%B9%94%E5%A4%B4%E5%83%8F.jpg"); // 替换为实际图片URL
imageUrls.add("https://dsideal.obs.myhuaweicloud.com/HuangHai/%E5%A4%87%E4%BB%BD/%E5%B0%8F%E4%B9%94%E5%A4%B4%E5%83%8F.jpg");
String prompt = "眨眨眼";
JSONObject submitResult = submitImageToVideoTaskWithUrls(imageUrls, prompt);
System.out.println("提交结果: " + submitResult);

@ -7,6 +7,9 @@ import java.util.*;
public class JmQueryTask extends JmCommon {
private static final String req_key = "jimeng_vgfm_t2v_l20";
private static final String action = "CVSync2AsyncGetResult";
/**
*
*
@ -15,21 +18,14 @@ public class JmQueryTask extends JmCommon {
public static JSONObject queryTaskResult(String taskId) throws Exception {
// 创建请求体
JSONObject req = new JSONObject();
// 将参数名从 tsk_id 改为 task_id
req.put("task_id", taskId);
req.put("req_key", "jimeng_vgfm_t2v_l20");
// 使用JmCommon中的doRequest方法发送请求
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVSync2AsyncGetResult");
// 将响应结果转换为JSONObject并返回
req.put("req_key", req_key);
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
return JSON.parseObject(responseBody);
}
public static void main(String[] args) throws Exception {
// 使用实际获取到的task_id
//String taskId = "12748116377948882873";
String taskId="17796623341273230793";
String taskId = "17796623341273230793";
JSONObject result = JmQueryTask.queryTaskResult(taskId);
System.out.println("查询结果: " + result);
}

@ -2,10 +2,16 @@ package com.dsideal.aiSupport.Util.JiMeng;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class JmText2Video extends JmCommon {
private static final Logger log = LoggerFactory.getLogger(JmText2Video.class);
private static final String action = "CVSync2AsyncSubmitTask";
private static final String req_key = "jimeng_vgfm_t2v_l20";
/**
*
@ -15,9 +21,9 @@ public class JmText2Video extends JmCommon {
*/
public static JSONObject generateVideo(String prompt) throws Exception {
JSONObject req = new JSONObject();
req.put("req_key", "jimeng_vgfm_t2v_l20");
req.put("req_key", req_key);
req.put("prompt", prompt);
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVSync2AsyncSubmitTask");
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), action);
return JSON.parseObject(responseBody);
}

Loading…
Cancel
Save